home *** CD-ROM | disk | FTP | other *** search
/ ftp.ncftp.com / ftp.ncftp.com.zip / ftp.ncftp.com / libncftp / older_versions / libncftp-3.1.5-src.tar.gz / libncftp-3.1.5-src.tar / libncftp-3.1.5 / sio / sio.h < prev    next >
C/C++ Source or Header  |  2002-05-22  |  9KB  |  314 lines

  1. /* sio.h */
  2.  
  3. #ifndef _sio_h_
  4. #define _sio_h_ 1
  5.  
  6. #ifdef __cplusplus
  7. extern "C"
  8. {
  9. #endif    /* __cplusplus */
  10.  
  11. typedef struct SelectSet {
  12.     fd_set fds;
  13.     struct timeval timeout;
  14.     int maxfd;
  15.     int numfds;
  16. } SelectSet, *SelectSetPtr;
  17.  
  18. /* For SReadline */
  19. #ifndef _SReadlineInfo_
  20. #define _SReadlineInfo_ 1
  21. typedef struct SReadlineInfo {
  22.     char *buf;        /* Pointer to beginning of buffer. */
  23.     char *bufPtr;        /* Pointer to current position in buffer. */
  24.     char *bufLim;        /* Pointer to end of buffer. */
  25.     size_t bufSize;        /* Current size of buffer block. */
  26.     size_t bufSizeMax;    /* Maximum size available for buffer. */
  27.     int malloc;        /* If non-zero, malloc() was used for buf. */
  28.     int fd;            /* File descriptor to use for I/O. */
  29.     int timeoutLen;        /* Timeout to use, in seconds. */
  30.     int requireEOLN;    /* When buffer is full, continue reading and discarding until \n? */
  31. } SReadlineInfo;
  32. #endif
  33.  
  34. #ifndef forever
  35. #    define forever for ( ; ; )
  36. #endif
  37.  
  38. /* Private decl; only for use when compiling sio code. */
  39. #ifdef HAVE_SIGSETJMP
  40. #    define SSetjmp(a) sigsetjmp(a, 1)
  41. #    define SLongjmp(a,b) siglongjmp(a, b)
  42. #    define Sjmp_buf sigjmp_buf
  43. #else
  44. #    define SSetjmp(a) setjmp(a)
  45. #    define SLongjmp(a,b) longjmp(a, b)
  46. #    define Sjmp_buf jmp_buf
  47. #endif
  48.  
  49. /* Parameter to SBind */
  50. #define kReUseAddrYes 1
  51. #define kReUseAddrNo 0
  52.  
  53. /* Parameter to SRead/SWrite */
  54. #define kFullBufferNotRequired                00000
  55. #define kFullBufferRequired                00001
  56. #define kFullBufferRequiredExceptLast            00002
  57. #define    kNoFirstSelect                    00010
  58.  
  59. /* Parameter to AddrToAddrStr */
  60. #define kUseDNSYes 1
  61. #define kUseDNSNo 0
  62.  
  63. #define kTimeoutErr (-2)
  64. #define kBrokenPipeErr (-3)
  65.  
  66. #define kAddrStrToAddrMiscErr (-4)
  67. #define kAddrStrToAddrBadHost (-5)
  68.  
  69. #define kSNewFailed (-6)
  70. #define kSBindFailed (-7)
  71. #define kSListenFailed (-8)
  72.  
  73. #define kSrlBufSize 2048
  74.  
  75. #define kNoTimeLimit 0
  76.  
  77. /* Return value from GetOurHostName */
  78. #define kGethostnameFailed (-1)
  79. #define kDomainnameUnknown (-2)
  80. #define kFullyQualifiedHostNameTooLongForBuffer (-3)
  81. #define kHostnameHardCoded 1
  82. #define kGethostnameFullyQualified 2
  83. #define kGethostbynameFullyQualified 3
  84. #define kGethostbynameHostAliasFullyQualified 4
  85. #define kGethostbyaddrFullyQualified 5
  86. #define kGethostbyaddrHostAliasFullyQualified 6
  87. #define kDomainnameHardCoded 7
  88. #define kResInitDomainnameFound 8
  89. #define kEtcResolvConfDomainFound 9
  90. #define kEtcResolvConfSearchFound 10
  91.  
  92.  
  93. #if 1 /* %config2% -- set by configure script -- do not modify */
  94. #    ifndef NO_SIGNALS
  95. #        define NO_SIGNALS 1
  96. #    endif
  97. #else
  98.     /* #undef NO_SIGNALS */
  99. #endif
  100.  
  101. /* Don't change the following line -- it is modified by the Configure script. */
  102. #define SAccept SAcceptS
  103.  
  104. #ifndef SAccept
  105. #    if defined(NO_SIGNALS) || ((defined(WIN32) || defined(_WINDOWS)) && !defined(__CYGWIN__))
  106. #        define SAccept SAcceptS
  107. #    else
  108. #        define SAccept SAcceptA
  109. #    endif
  110. #endif
  111.  
  112. #if !defined(ETIMEDOUT) && defined(WSAETIMEDOUT)
  113. #    define ETIMEDOUT WSAETIMEDOUT
  114. #endif
  115.  
  116. #if !defined(EADDRNOTAVAIL) && defined(WSAEADDRNOTAVAIL)
  117. #    define EADDRNOTAVAIL WSAEADDRNOTAVAIL
  118. #endif
  119.  
  120. #if !defined(EWOULDBLOCK) && defined(WSAEWOULDBLOCK)
  121. #    define EWOULDBLOCK WSAEWOULDBLOCK
  122. #endif
  123.  
  124. #if !defined(EINPROGRESS) && defined(WSAEINPROGRESS)
  125. #    define EINPROGRESS WSAEINPROGRESS
  126. #endif
  127.  
  128. #if !( (defined(WIN32) || defined(_WINDOWS)) && !defined(__CYGWIN__) )\
  129.     && !defined(closesocket)
  130. #    define closesocket close
  131. #endif
  132.  
  133. #if !( (defined(WIN32) && !defined(_WINDOWS)) && !defined(__CYGWIN__) )\
  134.     && !defined(ioctlsocket)
  135. #    define ioctlsocket ioctl
  136. #endif
  137.  
  138. #if (defined(WIN32) || defined(_WINDOWS)) && !defined(__CYGWIN__)
  139. #    define SETERRNO errno = WSAGetLastError();
  140. #    define SETWSATIMEOUTERR WSASetLastError(WSAETIMEDOUT);
  141. #else
  142. #    define SETERRNO
  143. #    define SETWSATIMEOUTERR
  144. #endif
  145.  
  146. /*
  147.  * Definitions for IP type of service (ip_tos)
  148.  */
  149. #ifndef IPTOS_LOWDELAY
  150. #    define IPTOS_LOWDELAY        0x10
  151. #    define IPTOS_THROUGHPUT        0x08
  152. #    define IPTOS_RELIABILITY    0x04
  153. #endif
  154. #if !defined(IPTOS_LOWCOST) && !defined(IPTOS_MINCOST)
  155. #    define IPTOS_LOWCOST        0x02
  156. #    define IPTOS_MINCOST        IPTOS_LOWCOST
  157. #elif !defined(IPTOS_LOWCOST) && defined(IPTOS_MINCOST)
  158. #    define IPTOS_LOWCOST        IPTOS_MINCOST
  159. #elif defined(IPTOS_LOWCOST) && !defined(IPTOS_MINCOST)
  160. #    define IPTOS_MINCOST        IPTOS_LOWCOST
  161. #endif
  162.  
  163. #ifndef INADDR_NONE
  164. #    define INADDR_NONE        (0xffffffff)    /* <netinet/in.h> should have it. */
  165. #endif
  166. #ifndef INADDR_ANY
  167. #    define INADDR_ANY        (0x00000000)
  168. #endif
  169.  
  170.  
  171. typedef void (*sio_sigproc_t)(int);
  172. typedef volatile sio_sigproc_t vsio_sigproc_t;
  173.  
  174. extern int gLibSio_Uses_Me_To_Quiet_Variable_Unused_Warnings;
  175.  
  176. #if (defined(__APPLE_CC__)) && (__APPLE_CC__ < 10000)
  177. #    define LIBSIO_USE_VAR(a) gLibSio_Uses_Me_To_Quiet_Variable_Unused_Warnings = (a == 0)
  178. #    ifndef UNUSED
  179. #        define UNUSED(a) a
  180. #    endif
  181. #elif (defined(__GNUC__)) && (__GNUC__ >= 3)
  182. #    ifndef UNUSED
  183. #        define UNUSED(a) a __attribute__ ((__unused__))
  184. #    endif
  185. #    define LIBSIO_USE_VAR(a)
  186. #elif (defined(__GNUC__)) && (__GNUC__ == 2)
  187. #    ifndef UNUSED
  188. #        define UNUSED(a) a __attribute__ ((unused))
  189. #    endif
  190. #    define LIBSIO_USE_VAR(a)
  191. #else
  192. #    define LIBSIO_USE_VAR(a) gLibSio_Uses_Me_To_Quiet_Variable_Unused_Warnings = (a == 0)
  193. #    ifndef UNUSED
  194. #        define UNUSED(a) a
  195. #    endif
  196. #endif
  197.  
  198. /* DNSUtil.c */
  199. int GetHostByName(struct hostent *const hp, const char *const name, char *const hpbuf, size_t hpbufsize);
  200. int GetHostByAddr(struct hostent *const hp, void *addr, int asize, int atype, char *const hpbuf, size_t hpbufsize);
  201. int GetHostEntry(struct hostent *const hp, const char *const host, struct in_addr *const ip_address, char *const hpbuf, size_t hpbufsize);
  202. int GetOurHostName(char *const host, const size_t siz);
  203. #if (defined(WIN32) || defined(_WINDOWS)) && !defined(__CYGWIN__)
  204. int getdomainname(char *const domain, unsigned int dsize);
  205. #endif
  206.  
  207. /* PRead.c */
  208. int PRead(int, char *const, size_t, int);
  209.  
  210. /* PWrite.c */
  211. int PWrite(int, const char *const, size_t);
  212.  
  213. /* SAcceptA.c */
  214. int SAcceptA(int, struct sockaddr_in *const, int);
  215.  
  216. /* SAcceptS.c */
  217. int SAcceptS(int, struct sockaddr_in *const, int);
  218.  
  219. /* SBind.c */
  220. int SBind(int, const int, const int, const int);
  221. int SListen(int, int);
  222.  
  223. /* SClose.c */
  224. int SClose(int, int);
  225.  
  226. /* SConnect.c */
  227. int SConnect(int, const struct sockaddr_in *const, int);
  228.  
  229. /* SConnectByName.c */
  230. int SConnectByName(int, const char *const, const int);
  231.  
  232. /* SNew.c */
  233. int SNewStreamClient(void);
  234. int SNewDatagramClient(void);
  235. int SNewStreamServer(const int, const int, const int, int);
  236. int SNewDatagramServer(const int, const int, const int);
  237.  
  238. /* SRead.c */
  239. int SRead(int, char *const, size_t, int, int);
  240.  
  241. /* SReadline.c */
  242. void FlushSReadlineInfo(SReadlineInfo *);
  243. int InitSReadlineInfo(SReadlineInfo *, int, char *, size_t, int, int);
  244. void DisposeSReadlineInfo(SReadlineInfo *);
  245. int SReadline(SReadlineInfo *, char *const, size_t);
  246.  
  247. /* SRecv.c */
  248. int SRecv(int, char *const, size_t, int, int, int);
  249.  
  250. /* SRecvfrom.c */
  251. int SRecvfrom(int, char *const, size_t, int, struct sockaddr_in *const, int);
  252.  
  253. /* SRecvmsg.c */
  254. int SRecvmsg(int, void *const, int, int);
  255.  
  256. /* SSelect.c */
  257. void SelectSetInit(SelectSetPtr const, const double);
  258. void SelectSetAdd(SelectSetPtr const, const int);
  259. void SelectSetRemove(SelectSetPtr const, const int);
  260. int SelectW(SelectSetPtr, SelectSetPtr);
  261. int SelectR(SelectSetPtr, SelectSetPtr);
  262.  
  263. /* SSend.c */
  264. int SSend(int, char *, size_t, int, int);
  265.  
  266. /* SSendto.c */
  267. int SSendto(int, const char *const, size_t, int, const struct sockaddr_in *const, int);
  268. int Sendto(int, const char *const, size_t, const struct sockaddr_in *const);
  269.  
  270. /* SSendtoByName.c */
  271. int SSendtoByName(int, const char *const, size_t, int, const char *const, int);
  272. int SendtoByName(int, const char *const, size_t, const char *const);
  273.  
  274. /* SWait.c */
  275. int SWaitUntilReadyForReading(const int sfd, const int tlen);
  276. int SWaitUntilReadyForWriting(const int sfd, const int tlen);
  277.  
  278. /* SWrite.c */
  279. int SWrite(int, const char *const, size_t, int, int);
  280.  
  281. /* SocketUtil.c */
  282. int GetSocketBufSize(const int, size_t *const, size_t *const);
  283. int SetSocketBufSize(const int, const size_t, const size_t);
  284. int GetSocketNagleAlgorithm(const int);
  285. int SetSocketNagleAlgorithm(const int, const int);
  286. int GetSocketLinger(const int, int *const);
  287. int SetSocketLinger(const int, const int, const int);
  288. int GetSocketKeepAlive(const int fd);
  289. int SetSocketKeepAlive(const int fd, const int onoff);
  290. int GetSocketTypeOfService(const int fd);
  291. int SetSocketTypeOfService(const int fd, const int tosType);
  292. int GetSocketInlineOutOfBandData(const int fd);
  293. int SetSocketInlineOutOfBandData(const int fd, const int onoff);
  294.  
  295. /* StrAddr.c */
  296. unsigned int ServiceNameToPortNumber(const char *const s, const int proto);
  297. int ServicePortNumberToName(unsigned short port, char *const dst, const size_t dsize, const int proto);
  298. void InetNtoA(char *dst, struct in_addr *ia, size_t siz);
  299. int AddrStrToAddr(const char *const, struct sockaddr_in *const, const int);
  300. char *AddrToAddrStr(char *const dst, size_t dsize, struct sockaddr_in * const saddrp, int dns, const char *fmt);
  301.  
  302. /* SError.c */
  303. const char *SError(int e);
  304.  
  305. /* main.c */
  306. void SIOHandler(int);
  307. void (*SSignal(int signum, void (*handler)(int)))(int);
  308.  
  309. #ifdef __cplusplus
  310. }
  311. #endif
  312.  
  313. #endif    /* _sio_h_ */
  314.