$Revision: 1.6 $
Socket module - cd_socket.c - basic read/write socket routines defined
in terms of connection data structures
with timeouts and storing information about
broken connections.
Status: NOT REVUED, TESTED
Design and implementation by Marek Bukowy.
Included Files
Preprocessor definitions
#define SKBUFLEN 2047
pthread_mutex_t Lock
Wrapper around the close(2) system call,
Author:
marek
int SK_cd_close ( sk_conn_st* condat )
- int SK_cd_close
- returns the error codes of close(2).
- sk_conn_st* condat
- Pointer to the connection data structure.
Destroys the data allocated and anchored by the connection data structure.
void SK_cd_free ( sk_conn_st* condat )
- sk_conn_st* condat
- Pointer to the connection data structure.
Read from a socket, until a linefeed character is received or the buffer
fills up to the maximum size "count". If the connection data has non-zero
timeout value for reading, it is used here between calls to read
the next 1 character.
More:
if the connection structure has bad status for this connection
from previous calls, no read will be attempted.
Author:
marek
Side Effects:
broken connections get registered in the connection structure.
int SK_cd_gets ( sk_conn_st* condat, char* str, size_t count )
- int SK_cd_gets
- Returns the total_count of bytes read,
or inverted error codes (negative numbers):
(- SK_DISCONNECT) on broken connection,
(- SK_TIMEOUT) on timeout.
- sk_conn_st* condat
- connection data
- char* str
- The buffer to store the data received from
the socket.
- size_t count
- size of the buffer.
Construct a connection data given the socket or file descriptor.
Also performs the getpeername check and stores the IP in an allocated
string.
void SK_cd_make ( sk_conn_st* condat, int sock, unsigned timeout )
- sk_conn_st* condat
- pointer to where the data is to be stored.
- int sock
- The socket or file descriptor.
- unsigned timeout
- Read timeout (used in SK_cd_gets) in seconds.
Value of 0 disables the timeout.
Printf-like function to print to socket/file specified by connection
data structure. First writes the text to a temporary buffer, then
uses SK_cd_puts to print it. Maintains a 2K static buffer, and allocates
more memory if this is not enough.
Author:
marek
int SK_cd_printf ( sk_conn_st* condat, char* txt, ... )
- int SK_cd_printf
- Returns the SK_cd_puts error code/return value.
- sk_conn_st* condat
- Pointer to the connection data structure.
- char* txt
- Format text to be written
- ...
- more arguments (like printf)
This function writes a character string out to a socket, unless
the connection is broken.
char *str The buffer to be written to the socket.
More:
if the connection structure has bad status for this connection
from previous calls, no write will be attempted.
Side Effects:
broken connections get registered in the connection structure
int SK_cd_puts ( sk_conn_st* condat, const char* str )
- int SK_cd_puts
- Returns the total_count of bytes written,
or inverted error codes (negative numbers):
(- SK_DISCONNECT) on broken connection,
(- SK_INTERRUPT) on control-c received,
(- SK_TIMEOUT) on timeout.
- sk_conn_st* condat
- Pointer to the connection data structure.
- const char* str
- &nbs;
static char* asctime_r ( const struct tm* __tm, char* __buf )
static char* ctime_r ( const time_t* __time, char* __buf )
static int getlogin_r ( char* __name, int __len )
static int readdir_r ( DIR* __dp, struct dirent* __ent, struct dirent** __res )
static int sigwait ( const sigset_t* __setp, int* __signo )
static int ttyname_r ( int __fildes, char* __buf, size_t __size )