3 * (Convenience wrapper around BSD sockets)
5 * Copyright (C) 2004, 2015 by Chris Jaekl
8 #ifndef __QD_SOCKET_H__
9 #define __QD_SOCKET_H__
12 #include <sys/socket.h>
13 #include <sys/types.h>
15 #define QD_SOCK_BUF_SIZE 32768
18 int sd; // socket (file) descriptor
19 int toWrite; // number of bytes in buf (starting from [0]) that are waiting to be written
20 char closeRequested; // boolean: has qdClose() been called on this socket?
21 char buf[QD_SOCK_BUF_SIZE];
24 void qdSockCheckClose(struct qdSocket *sock);
26 void qdSockClose(struct qdSocket *sock);
28 // Returns 0 on success, non-zero on failure
29 int qdSockConnect(struct qdSocket *sock, const char * host, int port);
31 void qdSockInit(struct qdSocket *sock);
33 // Returns # of bytes actually written by this flush operation
34 ssize_t qdSockFlush(struct qdSocket *to);
36 ssize_t qdSockWrite(struct qdSocket *to, char * buf, ssize_t n);
38 #endif /* __QD_SOCKET_H__ */