home *** CD-ROM | disk | FTP | other *** search
/ ftp.ncftp.com / ftp.ncftp.com.zip / ftp.ncftp.com / libncftp / libncftp-3.2.5-src.zip / libncftp-3.2.5 / sio / sio.h < prev    next >
C/C++ Source or Header  |  2010-10-30  |  9KB  |  301 lines

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