1 #include "output_hook.h"
2 #include "output_item.h"
11 SIMPLEQ_HEAD(output_list
, output_item
);
14 struct output_list queue
;
17 output_hook
*new_output_hook() {
18 output_hook
*ret
= calloc(1, sizeof(output_hook
));
20 SIMPLEQ_INIT(&ret
->queue
);
24 void release_output_hook(output_hook
*hook
) {
28 void output_hook_queue(output_hook
*hook
, output_item
*item
) {
29 SIMPLEQ_INSERT_TAIL(&hook
->queue
, item
, queue_entries
);
32 static output_item
*get_next(output_hook
*hook
) {
33 output_item
*next
= SIMPLEQ_FIRST(&hook
->queue
);
34 while(next
&& !output_remaining(next
)) {
35 SIMPLEQ_REMOVE_HEAD(&hook
->queue
, queue_entries
);
36 output_on_complete(next
);
37 /* PERFORM RELEASE... user callback should be doing this */
39 next
= SIMPLEQ_FIRST(&hook
->queue
);
44 void output_hook_callback(EV_P_
struct ev_io
*w
, int revents
) {
45 output_hook
*hook
= w
->data
;
48 output_item
*next
= get_next(hook
);
49 fprintf(stderr
, "In output_hook\n");
51 /* ASSUME OUTPUT IS PIPE FOR NOW */
52 ssize_t ret
= output_send(next
, fd
, FDT_SOCKET
);
53 if(ret
< 0) break; /* Error... output_item should have triggered */
54 next
= get_next(hook
);
56 /* Completed normally */
61 if(ret
< 0 && errno
!= EAGAIN
) {
62 perror("Something went wrong while writing out to the fd");