fix serious typo
[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)(long unsigned current_chunk, long unsigned chunks_sent,
49 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)(int *max_fileno, fd_set *rfds, fd_set *wfds);
62 /**
63 * handle the file descriptors which are ready for I/O
64 *
65 * If the pre_select hook added one ore more file descriptors to the read or write
66 * set, this is the hook to check the result and do any I/O on those descriptors
67 * which are ready for reading/writing.
68 */
69 void (*post_select)(fd_set *rfds, fd_set *wfds);
70 /**
71 * terminate all connected clients
72 *
73 * This is called e.g. if the stop command was executed. It should make the clients
74 * aware of the end-of-file condition.
75 */
76 void (*shutdown_clients)(void);
77 /**
78 * array of function pointers for the sender subcommands
79 *
80 * Each sender may implement any subset of the sender commands by filling in
81 * the aprropriate function pointer in the array. A \p NULL pointer means this
82 * command is not implemented by this sender.
83 */
84 int (*client_cmds[NUM_SENDER_CMDS])(struct sender_command_data*);
85 };
86
87 /**
88 * check a file descriptor for writability
89 *
90 * \param fd the file desctiptor
91 *
92 * \return positive if fd is ready for writing, zero if it isn't, negative if
93 * an error occured.
94 */
95
96 static inline int write_ok(int fd)
97 {
98 struct timeval tv = {0, 0};
99 fd_set wfds;
100 int ret;
101 again:
102 FD_ZERO(&wfds);
103 FD_SET(fd, &wfds);
104 ret = select(fd + 1, NULL, &wfds, NULL, &tv);
105 if (ret < 0 && errno == EINTR)
106 goto again;
107 return ret;
108 }