cctools
mq.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2020- The University of Notre Dame
3 This software is distributed under the GNU General Public License.
4 See the file COPYING for details.
5 */
6 
7 #ifndef MQ_H
8 #define MQ_H
9 
10 #include <stddef.h>
11 #include <time.h>
12 
13 #include "buffer.h"
14 
117 typedef enum {
118  MQ_MSG_NONE = 0,
119  MQ_MSG_BUFFER,
120  MQ_MSG_FD,
121 } mq_msg_t;
122 
123 
124 //---------Basic Functions----------------//
125 
135 struct mq *mq_connect(const char *addr, int port);
136 
147 struct mq *mq_serve(const char *addr, int port);
148 
153 void mq_close(struct mq *mq);
154 
163 struct mq *mq_accept(struct mq *server);
164 
178 int mq_wait(struct mq *mq, time_t stoptime);
179 
188 void mq_set_tag(struct mq *mq, void *tag);
189 
196 void *mq_get_tag(struct mq *mq);
197 
204 int mq_address_local(struct mq *mq, char *addr, int *port);
205 
212 int mq_address_remote(struct mq *mq, char *addr, int *port);
213 
224 int mq_geterror(struct mq *mq);
225 
226 //------------Polling API-----------------//
227 
235 struct mq_poll *mq_poll_create(void);
236 
244 void mq_poll_delete(struct mq_poll *p);
245 
254 int mq_poll_add(struct mq_poll *p, struct mq *mq);
255 
266 int mq_poll_rm(struct mq_poll *p, struct mq *mq);
267 
282 int mq_poll_wait(struct mq_poll *p, time_t stoptime);
283 
295 struct mq *mq_poll_readable(struct mq_poll *p);
296 
308 struct mq *mq_poll_acceptable(struct mq_poll *p);
309 
320 struct mq *mq_poll_error(struct mq_poll *p);
321 
322 
323 //------------Send/Recv-------------------//
324 
341 int mq_send_buffer(struct mq *mq, buffer_t *buf, size_t maxlen);
342 
358 int mq_send_fd(struct mq *mq, int fd, size_t maxlen);
359 
377 int mq_store_buffer(struct mq *mq, buffer_t *buf, size_t maxlen);
378 
393 int mq_store_fd(struct mq *mq, int fd, size_t maxlen);
394 
409 mq_msg_t mq_recv(struct mq *mq, size_t *length);
410 
411 #endif
struct mq * mq_poll_error(struct mq_poll *p)
Find a queue in the error state or closed socket.
int mq_poll_rm(struct mq_poll *p, struct mq *mq)
Remove a message queue from a polling group.
int mq_geterror(struct mq *mq)
Check for errors on the connection.
void mq_set_tag(struct mq *mq, void *tag)
Set the tag associated with the given queue.
struct mq_poll * mq_poll_create(void)
Create a new (empty) polling group.
int mq_store_fd(struct mq *mq, int fd, size_t maxlen)
Write the next message to the given file descriptor.
struct mq * mq_connect(const char *addr, int port)
Connect to a remote host.
int mq_address_local(struct mq *mq, char *addr, int *port)
Return the local address of the queue in text format.
int mq_send_buffer(struct mq *mq, buffer_t *buf, size_t maxlen)
Push a message onto the send queue.
void mq_poll_delete(struct mq_poll *p)
Delete a polling group.
void * mq_get_tag(struct mq *mq)
Get the tag associated with the given queue.
struct mq * mq_serve(const char *addr, int port)
Prepare to accept connections.
struct mq * mq_poll_readable(struct mq_poll *p)
Find a queue with messages waiting.
int mq_address_remote(struct mq *mq, char *addr, int *port)
Return the remote address of the queue in text format.
int mq_poll_add(struct mq_poll *p, struct mq *mq)
Add a message queue to a polling group.
String Buffer Operations.
int mq_wait(struct mq *mq, time_t stoptime)
Wait for a message or connection.
mq_msg_t mq_recv(struct mq *mq, size_t *length)
Pop a message from the receive queue.
Definition: buffer.h:26
void mq_close(struct mq *mq)
Close a connection.
int mq_store_buffer(struct mq *mq, buffer_t *buf, size_t maxlen)
Store the next message in the given buffer.
struct mq * mq_accept(struct mq *server)
Accept a connection.
struct mq * mq_poll_acceptable(struct mq_poll *p)
Find a server queue with connections waiting.
int mq_poll_wait(struct mq_poll *p, time_t stoptime)
Wait for messages or connections.
int mq_send_fd(struct mq *mq, int fd, size_t maxlen)
Stream a file descriptor across the wire.