/* Socket I/O include stuff. */ #ifndef SOCKETIO_H #define SOCKETIO_H #include /*************************************************************************/ /* A define that can mean "no socket"--not used by socketio, but can be * used by callers if they want. */ #define NO_SOCK 0x80000000 /*************************************************************************/ typedef void (*socket_callback)(int sock, int status); typedef struct { int status; /* SOCKSTAT_* below */ socket_callback connect_callback; char *rbuf; int rbufsize, rbuflen; char *wbuf; int wbufsize, wbuflen; } Socket; #define SOCKSTAT_OPEN 0x0001 #define SOCKSTAT_CONNECTING 0x0002 /*************************************************************************/ /* Try to establish a connection to a remote host. Call the specified * callback routine when the connection either succeeds or fails. */ extern void sock_connect(int sock, struct sockaddr_in *sin, socket_callback callback); /* Close the given socket. This routine should be preferred over close() * because it frees any buffer memory associated with the socket. */ extern void sock_close(int sock); /* Read some data from the given socket. Return 0 and errno==EAGAIN if the * requested amount of data is not yet available. */ extern int sock_read(int sock, char *buf, int len); /* Write some data to the requested socket. Always succeeds, barring * out-of-memory conditions or other such failures. */ extern int sock_write(int sock, const char *buf, int len); /*************************************************************************/ #endif /* SOCKETIO_H */