fix error log message
[paraslash.git] / send.h
1 /** \file send.h sender-related defines and structures */
2 /** the sender subcommands */
3 enum {SENDER_ADD, SENDER_DELETE, SENDER_ALLOW, SENDER_DENY, SENDER_ON, SENDER_OFF};
4
5 /** the number of sender subcommands */
6 #define NUM_SENDER_CMDS (SENDER_OFF + 1)
7
8 /**
9  * describes one supported sender of para_server
10  *
11  * \sa http_send.c ortp_send.c
12  */
13 struct sender {
14 /** the name of the sender */
15         const char *name;
16 /**
17  * the init function of this sender
18  *
19  * It must fill in all function pointers of \a s as well as the \a client_cmds
20  * array, see below. It should also do all neccessary preparations to init
21  * this sending facility, for example it could open a tcp port.
22  */
23         void (*init)(struct sender *s);
24 /** \p SENDER_ON or \p SENDER_OFF */
25         int status;
26 /**
27  * return the help text of this sender
28  *
29  * The result must be dynamically allocated and is freed by the caller.
30  */
31         char* (*help)(void);
32 /**
33  * return current status info about this sender
34  *
35  * The result must be dynamically allocated and is freed by the caller.
36  */
37         char* (*info)(void);
38 /**
39  * the send-hook
40  *
41  * It gets called whenever para_server is playing and the current
42  * audio format handler indicates that another chunk of data should
43  * be sent now. The two parameters \a current_chunk and \a chunks_sent
44  * only differ if the stream was repositioned by the \a ff or \a jmp
45  * command. Of course, \a buf is a pointer to the chunk of data which
46  * should be sent, and \a len is the length of this buffer.
47 */
48         void (*send)(struct audio_format *af, long unsigned current_chunk,
49                 long unsigned chunks_sent, const char *buf, size_t len);
50 /** add file descriptors to fd_sets
51  *
52  * The pre_select function of each supported sender is called just before
53  * para_server enters its main select loop. Each sender may add its own
54  * file descriptors to the \a rfds or the \a wfds set.
55  *
56  * If a file descriptor was added, \a max_fileno must be increased by
57  * this function, if neccessary.
58  *
59  * \sa select(2)
60 */
61         void (*pre_select)(struct audio_format *af, int *max_fileno, fd_set *rfds,
62                 fd_set *wfds);
63 /**
64  * handle the file descriptors which are ready for I/O
65  *
66  * If the pre_select hook added one ore more file descriptors to the read or write
67  * set, this is the hook to check the result and do any I/O on those descriptors
68  * which are ready for reading/writing.
69  */
70         void (*post_select)(struct audio_format *af, fd_set *rfds, fd_set *wfds);
71 /**
72  * terminate all connected clients
73  *
74  * This is called e.g. if the stop command was executed. It should make the clients
75  * aware of the end-of-file condition.
76  */
77         void (*shutdown_clients)(void);
78 /**
79  * array of function pointers for the sender subcommands
80  *
81  * Each sender may implement any subset of the sender commands by filling in
82  * the aprropriate function pointer in the array. A \p NULL pointer means this
83  * command is not implemented by this sender.
84  */
85         int (*client_cmds[NUM_SENDER_CMDS])(struct sender_command_data*);
86 };
87
88 /**
89  * check a file descriptor for writability
90  *
91  * \param fd the file desctiptor
92  *
93  * \return positive if fd is ready for writing, zero if it isn't, negative if
94  * an error occured.
95  */
96
97 static inline int write_ok(int fd)
98 {
99         struct timeval tv = {0, 0};
100         fd_set wfds;
101         int ret;
102 again:
103         FD_ZERO(&wfds);
104         FD_SET(fd, &wfds);
105         ret = select(fd + 1, NULL, &wfds, NULL, &tv);
106         if (ret < 0 && errno == EINTR)
107                 goto again;
108         return ret;
109 }