home *** CD-ROM | disk | FTP | other *** search
/ ftp.parl.clemson.edu / 2015-02-07.ftp.parl.clemson.edu.tar / ftp.parl.clemson.edu / pub / pvfs2 / orangefs-2.8.3-20110323.tar.gz / orangefs-2.8.3-20110323.tar / orangefs / src / io / bmi / bmi_tcp / sockio.h < prev   
C/C++ Source or Header  |  2007-10-16  |  3KB  |  117 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 BMI_sockio_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.  
  22. #ifndef SOCKIO_H
  23. #define SOCKIO_H
  24.  
  25. #include <sys/types.h>
  26. #include <sys/socket.h>
  27. #include <netinet/in.h>
  28. #include <stdio.h>
  29.  
  30. #include "bmi-types.h"
  31.  
  32. int BMI_sockio_new_sock(void);
  33. int BMI_sockio_bind_sock(int,
  34.              int);
  35. int BMI_sockio_bind_sock_specific(int sockd,
  36.               const char *name,
  37.           int service);
  38. int BMI_sockio_connect_sock(int,
  39.                 const char *,
  40.                 int);
  41. int BMI_sockio_init_sock(struct sockaddr *,
  42.              const char *,
  43.              int);
  44. int BMI_sockio_nbrecv(int s,
  45.               void *buf,
  46.               int len);
  47. int BMI_sockio_nbsend(int s,
  48.               void *buf,
  49.               int len);
  50. int BMI_sockio_nbvector(int s,
  51.             struct iovec* vector,
  52.             int count,
  53.             int recv_flag);
  54. int BMI_sockio_get_sockopt(int s,
  55.                int optname);
  56. int BMI_sockio_set_tcpopt(int s,
  57.               int optname,
  58.               int val);
  59. int BMI_sockio_set_sockopt(int s,
  60.                int optname,
  61.                int size);
  62. int BMI_sockio_nbpeek(int s,
  63.               void* buf,
  64.               int len);
  65. #ifdef __USE_SENDFILE__
  66. int BMI_sockio_nbsendfile(int s,
  67.               int f,
  68.               int off,
  69.               int len);
  70. #endif
  71.  
  72. #define GET_RECVBUFSIZE(s) BMI_sockio_get_sockopt(s, SO_RCVBUF)
  73. #define GET_SENDBUFSIZE(s) BMI_sockio_get_sockopt(s, SO_SNDBUF)
  74.  
  75. /* some OS's (ie. Linux 1.3.xx) can't handle buffer sizes of certain
  76.  * sizes, and will hang up
  77.  */
  78. #ifdef BRAINDEADSOCKS
  79. /* setting socket buffer sizes can do bad things */
  80. #define SET_RECVBUFSIZE(s, size)
  81. #define SET_SENDBUFSIZE(s, size)
  82. #else
  83. #define SET_RECVBUFSIZE(s, size) BMI_sockio_set_sockopt(s, SO_RCVBUF, size)
  84. #define SET_SENDBUFSIZE(s, size) BMI_sockio_set_sockopt(s, SO_SNDBUF, size)
  85. #endif
  86.  
  87. #define GET_MINSENDSIZE(s) BMI_sockio_get_sockopt(s, SO_SNDLOWAT)
  88. #define GET_MINRECVSIZE(s) BMI_sockio_get_sockopt(s, SO_RCVLOWAT)
  89. #define SET_MINSENDSIZE(s, size) BMI_sockio_set_sockopt(s, SO_SNDLOWAT, size)
  90. #define SET_MINRECVSIZE(s, size) BMI_sockio_set_sockopt(s, SO_RCVLOWAT, size)
  91.  
  92. /* BLOCKING / NONBLOCKING MACROS */
  93.  
  94. #define SET_NONBLOCK(x_fd) fcntl((x_fd), F_SETFL, O_NONBLOCK | \
  95.    fcntl((x_fd), F_GETFL, 0))
  96.  
  97. #define SET_NONBLOCK_AND_SIGIO(x_fd) \
  98. do { \
  99.     fcntl((x_fd), F_SETOWN, getpid()); \
  100.     fcntl((x_fd), F_SETFL, FASYNC | O_NONBLOCK | fcntl((x_fd), F_GETFL, 0)); \
  101. } while (0)
  102.  
  103. #define CLR_NONBLOCK(x_fd) fcntl((x_fd), F_SETFL, fcntl((x_fd), F_GETFL, 0) & \
  104.    (~O_NONBLOCK))
  105.  
  106. #endif
  107.  
  108. /*
  109.  * Local variables:
  110.  *  c-indent-level: 4
  111.  *  c-basic-offset: 4
  112.  * End:
  113.  *
  114.  * vim: ts=8 sts=4 sw=4 expandtab
  115.  */
  116.  
  117.