home *** CD-ROM | disk | FTP | other *** search
/ ftp.parl.clemson.edu / 2015-02-07.ftp.parl.clemson.edu.tar / ftp.parl.clemson.edu / pub / coven / glpv-1.1.tgz / glpv-1.1.tar / glpv / sockio.h < prev   
C/C++ Source or Header  |  2002-10-29  |  3KB  |  93 lines

  1. /*
  2.  * (C) 2001 Clemson University and The University of Chicago
  3.  *
  4.  * See COPYING in top-level directory.
  5.  */
  6.  
  7.  
  8. /* 
  9.  * These are the exported functions from the sockio library.  They
  10.  * provide a simple intuitive interface to the TCP/IP sockets API.
  11.  */
  12.  
  13. /*
  14.  * Defines which may be set at compile time to determine functionality:
  15.  *
  16.  * __USE_SENDFILE__ turns on the use of sendfile() in the library and
  17.  * makes the nbsendfile function available to the application.
  18.  * Older glibc systems do not have this functionality so we leave it to
  19.  * be turned on manually.
  20.  *
  21.  * BRAINDEADSOCKS can be defined to prevent the macros that set socket
  22.  * buffer sizes from having an effect.  On some kernels (such as Linux
  23.  * 1.3) setting socket buffer sizes can cause problems.
  24.  *
  25.  * BSEND_NO_WRITEV determines whether the bsendv (blocking vector send)
  26.  * function will use the writev system call or not.
  27.  */
  28.  
  29. #ifndef SOCKIO_H
  30. #define SOCKIO_H
  31.  
  32. #include <sys/types.h>
  33. #include <sys/socket.h>
  34. #include <netinet/in.h>
  35.  
  36. int new_sock(void);
  37. int bind_sock(int, int);
  38. int connect_sock(int, char *, int);
  39. int init_sock(struct sockaddr *, char *, int);
  40. int brecv(int s, void *buf, int len);
  41. int nbrecv(int s, void *buf, int len);
  42. int bsend(int s, void *buf, int len);
  43. int bsendv(int s, const struct iovec *vec, int cnt);
  44. int nbsend(int s, void *buf, int len);
  45. int get_sockopt(int s, int optname);
  46. int set_tcpopt(int s, int optname, int val);
  47. int set_sockopt(int s, int optname, int size);
  48. int set_socktime(int s, int optname, int size);
  49. int sockio_dump_sockaddr(struct sockaddr_in *ptr, FILE *fp);
  50. int brecv_timeout(int s, void *buf, int len, int timeout);
  51. int connect_timeout(int s, struct sockaddr *saddrp, int len, int time_secs);
  52. int nbpeek(int s, int len);
  53. #ifdef __USE_SENDFILE__
  54. int nbsendfile(int s, int f, int off, int len);
  55. #endif
  56.  
  57. #define GET_RECVBUFSIZE(s) get_sockopt(s, SO_RCVBUF)
  58. #define GET_SENDBUFSIZE(s) get_sockopt(s, SO_SNDBUF)
  59.  
  60. /* some OS's (ie. Linux 1.3.xx) can't handle buffer sizes of certain
  61.  * sizes, and will hang up
  62.  */
  63. #ifdef BRAINDEADSOCKS
  64. /* setting socket buffer sizes can do bad things */
  65. #define SET_RECVBUFSIZE(s, size)
  66. #define SET_SENDBUFSIZE(s, size)
  67. #else
  68. #define SET_RECVBUFSIZE(s, size) set_sockopt(s, SO_RCVBUF, size)
  69. #define SET_SENDBUFSIZE(s, size) set_sockopt(s, SO_SNDBUF, size)
  70. #endif
  71.  
  72. #define GET_MINSENDSIZE(s) get_sockopt(s, SO_SNDLOWAT)
  73. #define GET_MINRECVSIZE(s) get_sockopt(s, SO_RCVLOWAT)
  74. #define SET_MINSENDSIZE(s, size) set_sockopt(s, SO_SNDLOWAT, size)
  75. #define SET_MINRECVSIZE(s, size) set_sockopt(s, SO_RCVLOWAT, size)
  76.  
  77. /* BLOCKING / NONBLOCKING MACROS */
  78.  
  79. #define SET_NONBLOCK(x_fd) fcntl((x_fd), F_SETFL, O_NONBLOCK | \
  80.    fcntl((x_fd), F_GETFL, 0))
  81.  
  82. #define SET_NONBLOCK_AND_SIGIO(x_fd) \
  83. do { \
  84.     fcntl((x_fd), F_SETOWN, getpid()); \
  85.     fcntl((x_fd), F_SETFL, FASYNC | O_NONBLOCK | fcntl((x_fd), F_GETFL, 0)); \
  86. } while (0)
  87.  
  88. #define CLR_NONBLOCK(x_fd) fcntl((x_fd), F_SETFL, fcntl((x_fd), F_GETFL, 0) & \
  89.    (~O_NONBLOCK))
  90.  
  91.  
  92. #endif
  93.