Simple tools for networking / objects in plain C Snapshot
ioutils.h
Go to the documentation of this file.
00001 #ifndef _IOUTILS_H_Y_Z_
00002 #define _IOUTILS_H_Y_Z_
00003 
00004 #include <nutils/addrutil.h>
00005 
00006 /**
00007  * @defgroup IOUTILS
00008  * @brief functions for setting of common socket options and doing stuff with sockets.
00009  *
00010  * @{
00011  */
00012 
00013 
00014 /** 
00015  * @brief disable SIG_PIPE signal, 
00016  * checks for static flag so as not to call system call again and again.
00017  */
00018 int disable_sigpipe();
00019 
00020 /**
00021  * @brief set mode to blocking / non blocking.
00022  */
00023 int fd_set_blocking(int fd,  int is_blocking);
00024 
00025 /**
00026  * @brief return bytes available for reading
00027  */
00028 int fd_get_bytes_available(int fd) ;
00029 
00030 /**
00031  * @brief return socket error.
00032  */
00033 int fd_get_error(int fd);
00034 
00035 typedef enum _Buffsize_op {
00036         Receive_buffer,
00037         Send_buffer,
00038 } Buffsize_op;
00039 
00040 /**
00041  * @brief set receive or send buffer size
00042  */
00043 int fd_set_buf_size( int fd, Buffsize_op op, int size);
00044 
00045 /**
00046  * @brief return the receive or send buffer size
00047  */
00048 int fd_get_buf_size( int fd, Buffsize_op op );
00049 
00050 /**
00051  * @brief set reuse address option
00052  */
00053 int fd_set_reuse_address(int fd, int reuse_on);
00054 
00055 /**
00056  * @brief get reuse address option
00057  */
00058 int fd_get_reuse_address(int fd);
00059 
00060 
00061 /**
00062  * @brief set naggle algorithm (tcp no delay option)
00063  */
00064 int fd_set_nagling(int fd, int on);
00065 
00066 /**
00067  * @brief set linger option
00068  */
00069 int fd_set_linger_option(int fd, int on, int linger_value);
00070 
00071 /**
00072  * @brief ungracefull connection termination - send RST to peer;
00073  */
00074 int fd_close_by_RST( int fd );
00075 
00076  
00077 /**
00078  * @brief make socket for accepting connections (listening endpoint), with SO_REUSE_ADDRESS and given backlog length.
00079  */
00080 int fd_make_tcp_listener(SOCKADDR *saddr, int backlog);
00081 
00082 
00083 
00084 /* 
00085  * @}
00086  */
00087 #endif
00088 
00089