prio.h 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /*
  6. * File: prio.h
  7. *
  8. * Description: PR i/o related stuff, such as file system access, file
  9. * i/o, socket i/o, etc.
  10. */
  11. #ifndef prio_h___
  12. #define prio_h___
  13. #include "prlong.h"
  14. #include "prtime.h"
  15. #include "prinrval.h"
  16. #include "prinet.h"
  17. PR_BEGIN_EXTERN_C
  18. /* Typedefs */
  19. typedef struct PRDir PRDir;
  20. typedef struct PRDirEntry PRDirEntry;
  21. #ifdef MOZ_UNICODE
  22. typedef struct PRDirUTF16 PRDirUTF16;
  23. typedef struct PRDirEntryUTF16 PRDirEntryUTF16;
  24. #endif /* MOZ_UNICODE */
  25. typedef struct PRFileDesc PRFileDesc;
  26. typedef struct PRFileInfo PRFileInfo;
  27. typedef struct PRFileInfo64 PRFileInfo64;
  28. typedef union PRNetAddr PRNetAddr;
  29. typedef struct PRIOMethods PRIOMethods;
  30. typedef struct PRPollDesc PRPollDesc;
  31. typedef struct PRFilePrivate PRFilePrivate;
  32. typedef struct PRSendFileData PRSendFileData;
  33. /*
  34. ***************************************************************************
  35. ** The file descriptor.
  36. ** This is the primary structure to represent any active open socket,
  37. ** whether it be a normal file or a network connection. Such objects
  38. ** are stackable (or layerable). Each layer may have its own set of
  39. ** method pointers and context private to that layer. All each layer
  40. ** knows about its neighbors is how to get to their method table.
  41. ***************************************************************************
  42. */
  43. typedef PRIntn PRDescIdentity; /* see: Layering file descriptors */
  44. struct PRFileDesc {
  45. const PRIOMethods *methods; /* the I/O methods table */
  46. PRFilePrivate *secret; /* layer dependent data */
  47. PRFileDesc *lower, *higher; /* pointers to adjacent layers */
  48. void (PR_CALLBACK *dtor)(PRFileDesc *fd);
  49. /* A destructor function for layer */
  50. PRDescIdentity identity; /* Identity of this particular layer */
  51. };
  52. /*
  53. ***************************************************************************
  54. ** PRTransmitFileFlags
  55. **
  56. ** Flags for PR_TransmitFile. Pass PR_TRANSMITFILE_CLOSE_SOCKET to
  57. ** PR_TransmitFile if the connection should be closed after the file
  58. ** is transmitted.
  59. ***************************************************************************
  60. */
  61. typedef enum PRTransmitFileFlags {
  62. PR_TRANSMITFILE_KEEP_OPEN = 0, /* socket is left open after file
  63. * is transmitted. */
  64. PR_TRANSMITFILE_CLOSE_SOCKET = 1 /* socket is closed after file
  65. * is transmitted. */
  66. } PRTransmitFileFlags;
  67. /*
  68. **************************************************************************
  69. ** Macros for PRNetAddr
  70. **
  71. ** Address families: PR_AF_INET, PR_AF_INET6, PR_AF_LOCAL
  72. ** IP addresses: PR_INADDR_ANY, PR_INADDR_LOOPBACK, PR_INADDR_BROADCAST
  73. **************************************************************************
  74. */
  75. #ifdef WIN32
  76. #define PR_AF_INET 2
  77. #define PR_AF_LOCAL 1
  78. #define PR_INADDR_ANY (unsigned long)0x00000000
  79. #define PR_INADDR_LOOPBACK 0x7f000001
  80. #define PR_INADDR_BROADCAST (unsigned long)0xffffffff
  81. #else /* WIN32 */
  82. #define PR_AF_INET AF_INET
  83. #define PR_AF_LOCAL AF_UNIX
  84. #define PR_INADDR_ANY INADDR_ANY
  85. #define PR_INADDR_LOOPBACK INADDR_LOOPBACK
  86. #define PR_INADDR_BROADCAST INADDR_BROADCAST
  87. #endif /* WIN32 */
  88. /*
  89. ** Define PR_AF_INET6 in prcpucfg.h with the same
  90. ** value as AF_INET6 on platforms with IPv6 support.
  91. ** Otherwise define it here.
  92. */
  93. #ifndef PR_AF_INET6
  94. #define PR_AF_INET6 100
  95. #endif
  96. #define PR_AF_INET_SDP 101
  97. #define PR_AF_INET6_SDP 102
  98. #ifndef PR_AF_UNSPEC
  99. #define PR_AF_UNSPEC 0
  100. #endif
  101. /*
  102. **************************************************************************
  103. ** A network address
  104. **
  105. ** Only Internet Protocol (IPv4 and IPv6) addresses are supported.
  106. ** The address family must always represent IPv4 (AF_INET, probably == 2)
  107. ** or IPv6 (AF_INET6).
  108. **************************************************************************
  109. *************************************************************************/
  110. struct PRIPv6Addr {
  111. union {
  112. PRUint8 _S6_u8[16];
  113. PRUint16 _S6_u16[8];
  114. PRUint32 _S6_u32[4];
  115. PRUint64 _S6_u64[2];
  116. } _S6_un;
  117. };
  118. #define pr_s6_addr _S6_un._S6_u8
  119. #define pr_s6_addr16 _S6_un._S6_u16
  120. #define pr_s6_addr32 _S6_un._S6_u32
  121. #define pr_s6_addr64 _S6_un._S6_u64
  122. typedef struct PRIPv6Addr PRIPv6Addr;
  123. union PRNetAddr {
  124. struct {
  125. PRUint16 family; /* address family (0x00ff maskable) */
  126. #ifdef XP_BEOS
  127. char data[10]; /* Be has a smaller structure */
  128. #else
  129. char data[14]; /* raw address data */
  130. #endif
  131. } raw;
  132. struct {
  133. PRUint16 family; /* address family (AF_INET) */
  134. PRUint16 port; /* port number */
  135. PRUint32 ip; /* The actual 32 bits of address */
  136. #ifdef XP_BEOS
  137. char pad[4]; /* Be has a smaller structure */
  138. #else
  139. char pad[8];
  140. #endif
  141. } inet;
  142. struct {
  143. PRUint16 family; /* address family (AF_INET6) */
  144. PRUint16 port; /* port number */
  145. PRUint32 flowinfo; /* routing information */
  146. PRIPv6Addr ip; /* the actual 128 bits of address */
  147. PRUint32 scope_id; /* set of interfaces for a scope */
  148. } ipv6;
  149. #if defined(XP_UNIX) || defined(XP_OS2) || defined(XP_WIN)
  150. struct { /* Unix domain socket address */
  151. PRUint16 family; /* address family (AF_UNIX) */
  152. #ifdef XP_OS2
  153. char path[108]; /* null-terminated pathname */
  154. /* bind fails if size is not 108. */
  155. #else
  156. char path[104]; /* null-terminated pathname */
  157. #endif
  158. } local;
  159. #endif
  160. };
  161. /*
  162. ***************************************************************************
  163. ** PRSockOption
  164. **
  165. ** The file descriptors can have predefined options set after they file
  166. ** descriptor is created to change their behavior. Only the options in
  167. ** the following enumeration are supported.
  168. ***************************************************************************
  169. */
  170. typedef enum PRSockOption
  171. {
  172. PR_SockOpt_Nonblocking, /* nonblocking io */
  173. PR_SockOpt_Linger, /* linger on close if data present */
  174. PR_SockOpt_Reuseaddr, /* allow local address reuse */
  175. PR_SockOpt_Keepalive, /* keep connections alive */
  176. PR_SockOpt_RecvBufferSize, /* receive buffer size */
  177. PR_SockOpt_SendBufferSize, /* send buffer size */
  178. PR_SockOpt_IpTimeToLive, /* time to live */
  179. PR_SockOpt_IpTypeOfService, /* type of service and precedence */
  180. PR_SockOpt_AddMember, /* add an IP group membership */
  181. PR_SockOpt_DropMember, /* drop an IP group membership */
  182. PR_SockOpt_McastInterface, /* multicast interface address */
  183. PR_SockOpt_McastTimeToLive, /* multicast timetolive */
  184. PR_SockOpt_McastLoopback, /* multicast loopback */
  185. PR_SockOpt_NoDelay, /* don't delay send to coalesce packets */
  186. PR_SockOpt_MaxSegment, /* maximum segment size */
  187. PR_SockOpt_Broadcast, /* enable broadcast */
  188. PR_SockOpt_Reuseport, /* allow local address & port reuse on
  189. * platforms that support it */
  190. PR_SockOpt_Last
  191. } PRSockOption;
  192. typedef struct PRLinger {
  193. PRBool polarity; /* Polarity of the option's setting */
  194. PRIntervalTime linger; /* Time to linger before closing */
  195. } PRLinger;
  196. typedef struct PRMcastRequest {
  197. PRNetAddr mcaddr; /* IP multicast address of group */
  198. PRNetAddr ifaddr; /* local IP address of interface */
  199. } PRMcastRequest;
  200. typedef struct PRSocketOptionData
  201. {
  202. PRSockOption option;
  203. union
  204. {
  205. PRUintn ip_ttl; /* IP time to live */
  206. PRUintn mcast_ttl; /* IP multicast time to live */
  207. PRUintn tos; /* IP type of service and precedence */
  208. PRBool non_blocking; /* Non-blocking (network) I/O */
  209. PRBool reuse_addr; /* Allow local address reuse */
  210. PRBool reuse_port; /* Allow local address & port reuse on
  211. * platforms that support it */
  212. PRBool keep_alive; /* Keep connections alive */
  213. PRBool mcast_loopback; /* IP multicast loopback */
  214. PRBool no_delay; /* Don't delay send to coalesce packets */
  215. PRBool broadcast; /* Enable broadcast */
  216. PRSize max_segment; /* Maximum segment size */
  217. PRSize recv_buffer_size; /* Receive buffer size */
  218. PRSize send_buffer_size; /* Send buffer size */
  219. PRLinger linger; /* Time to linger on close if data present */
  220. PRMcastRequest add_member; /* add an IP group membership */
  221. PRMcastRequest drop_member; /* Drop an IP group membership */
  222. PRNetAddr mcast_if; /* multicast interface address */
  223. } value;
  224. } PRSocketOptionData;
  225. /*
  226. ***************************************************************************
  227. ** PRIOVec
  228. **
  229. ** The I/O vector is used by the write vector method to describe the areas
  230. ** that are affected by the ouput operation.
  231. ***************************************************************************
  232. */
  233. typedef struct PRIOVec {
  234. char *iov_base;
  235. int iov_len;
  236. } PRIOVec;
  237. /*
  238. ***************************************************************************
  239. ** Discover what type of socket is being described by the file descriptor.
  240. ***************************************************************************
  241. */
  242. typedef enum PRDescType
  243. {
  244. PR_DESC_FILE = 1,
  245. PR_DESC_SOCKET_TCP = 2,
  246. PR_DESC_SOCKET_UDP = 3,
  247. PR_DESC_LAYERED = 4,
  248. PR_DESC_PIPE = 5
  249. } PRDescType;
  250. typedef enum PRSeekWhence {
  251. PR_SEEK_SET = 0,
  252. PR_SEEK_CUR = 1,
  253. PR_SEEK_END = 2
  254. } PRSeekWhence;
  255. NSPR_API(PRDescType) PR_GetDescType(PRFileDesc *file);
  256. /*
  257. ***************************************************************************
  258. ** PRIOMethods
  259. **
  260. ** The I/O methods table provides procedural access to the functions of
  261. ** the file descriptor. It is the responsibility of a layer implementor
  262. ** to provide suitable functions at every entry point. If a layer provides
  263. ** no functionality, it should call the next lower(higher) function of the
  264. ** same name (e.g., return fd->lower->method->close(fd->lower));
  265. **
  266. ** Not all functions are implemented for all types of files. In cases where
  267. ** that is true, the function will return a error indication with an error
  268. ** code of PR_INVALID_METHOD_ERROR.
  269. ***************************************************************************
  270. */
  271. typedef PRStatus (PR_CALLBACK *PRCloseFN)(PRFileDesc *fd);
  272. typedef PRInt32 (PR_CALLBACK *PRReadFN)(PRFileDesc *fd, void *buf, PRInt32 amount);
  273. typedef PRInt32 (PR_CALLBACK *PRWriteFN)(PRFileDesc *fd, const void *buf, PRInt32 amount);
  274. typedef PRInt32 (PR_CALLBACK *PRAvailableFN)(PRFileDesc *fd);
  275. typedef PRInt64 (PR_CALLBACK *PRAvailable64FN)(PRFileDesc *fd);
  276. typedef PRStatus (PR_CALLBACK *PRFsyncFN)(PRFileDesc *fd);
  277. typedef PROffset32 (PR_CALLBACK *PRSeekFN)(PRFileDesc *fd, PROffset32 offset, PRSeekWhence how);
  278. typedef PROffset64 (PR_CALLBACK *PRSeek64FN)(PRFileDesc *fd, PROffset64 offset, PRSeekWhence how);
  279. typedef PRStatus (PR_CALLBACK *PRFileInfoFN)(PRFileDesc *fd, PRFileInfo *info);
  280. typedef PRStatus (PR_CALLBACK *PRFileInfo64FN)(PRFileDesc *fd, PRFileInfo64 *info);
  281. typedef PRInt32 (PR_CALLBACK *PRWritevFN)(
  282. PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size,
  283. PRIntervalTime timeout);
  284. typedef PRStatus (PR_CALLBACK *PRConnectFN)(
  285. PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout);
  286. typedef PRFileDesc* (PR_CALLBACK *PRAcceptFN) (
  287. PRFileDesc *fd, PRNetAddr *addr, PRIntervalTime timeout);
  288. typedef PRStatus (PR_CALLBACK *PRBindFN)(PRFileDesc *fd, const PRNetAddr *addr);
  289. typedef PRStatus (PR_CALLBACK *PRListenFN)(PRFileDesc *fd, PRIntn backlog);
  290. typedef PRStatus (PR_CALLBACK *PRShutdownFN)(PRFileDesc *fd, PRIntn how);
  291. typedef PRInt32 (PR_CALLBACK *PRRecvFN)(
  292. PRFileDesc *fd, void *buf, PRInt32 amount,
  293. PRIntn flags, PRIntervalTime timeout);
  294. typedef PRInt32 (PR_CALLBACK *PRSendFN) (
  295. PRFileDesc *fd, const void *buf, PRInt32 amount,
  296. PRIntn flags, PRIntervalTime timeout);
  297. typedef PRInt32 (PR_CALLBACK *PRRecvfromFN)(
  298. PRFileDesc *fd, void *buf, PRInt32 amount,
  299. PRIntn flags, PRNetAddr *addr, PRIntervalTime timeout);
  300. typedef PRInt32 (PR_CALLBACK *PRSendtoFN)(
  301. PRFileDesc *fd, const void *buf, PRInt32 amount,
  302. PRIntn flags, const PRNetAddr *addr, PRIntervalTime timeout);
  303. typedef PRInt16 (PR_CALLBACK *PRPollFN)(
  304. PRFileDesc *fd, PRInt16 in_flags, PRInt16 *out_flags);
  305. typedef PRInt32 (PR_CALLBACK *PRAcceptreadFN)(
  306. PRFileDesc *sd, PRFileDesc **nd, PRNetAddr **raddr,
  307. void *buf, PRInt32 amount, PRIntervalTime t);
  308. typedef PRInt32 (PR_CALLBACK *PRTransmitfileFN)(
  309. PRFileDesc *sd, PRFileDesc *fd, const void *headers,
  310. PRInt32 hlen, PRTransmitFileFlags flags, PRIntervalTime t);
  311. typedef PRStatus (PR_CALLBACK *PRGetsocknameFN)(PRFileDesc *fd, PRNetAddr *addr);
  312. typedef PRStatus (PR_CALLBACK *PRGetpeernameFN)(PRFileDesc *fd, PRNetAddr *addr);
  313. typedef PRStatus (PR_CALLBACK *PRGetsocketoptionFN)(
  314. PRFileDesc *fd, PRSocketOptionData *data);
  315. typedef PRStatus (PR_CALLBACK *PRSetsocketoptionFN)(
  316. PRFileDesc *fd, const PRSocketOptionData *data);
  317. typedef PRInt32 (PR_CALLBACK *PRSendfileFN)(
  318. PRFileDesc *networkSocket, PRSendFileData *sendData,
  319. PRTransmitFileFlags flags, PRIntervalTime timeout);
  320. typedef PRStatus (PR_CALLBACK *PRConnectcontinueFN)(
  321. PRFileDesc *fd, PRInt16 out_flags);
  322. typedef PRIntn (PR_CALLBACK *PRReservedFN)(PRFileDesc *fd);
  323. struct PRIOMethods {
  324. PRDescType file_type; /* Type of file represented (tos) */
  325. PRCloseFN close; /* close file and destroy descriptor */
  326. PRReadFN read; /* read up to specified bytes into buffer */
  327. PRWriteFN write; /* write specified bytes from buffer */
  328. PRAvailableFN available; /* determine number of bytes available */
  329. PRAvailable64FN available64; /* ditto, 64 bit */
  330. PRFsyncFN fsync; /* flush all buffers to permanent store */
  331. PRSeekFN seek; /* position the file to the desired place */
  332. PRSeek64FN seek64; /* ditto, 64 bit */
  333. PRFileInfoFN fileInfo; /* Get information about an open file */
  334. PRFileInfo64FN fileInfo64; /* ditto, 64 bit */
  335. PRWritevFN writev; /* Write segments as described by iovector */
  336. PRConnectFN connect; /* Connect to the specified (net) address */
  337. PRAcceptFN accept; /* Accept a connection for a (net) peer */
  338. PRBindFN bind; /* Associate a (net) address with the fd */
  339. PRListenFN listen; /* Prepare to listen for (net) connections */
  340. PRShutdownFN shutdown; /* Shutdown a (net) connection */
  341. PRRecvFN recv; /* Solicit up the the specified bytes */
  342. PRSendFN send; /* Send all the bytes specified */
  343. PRRecvfromFN recvfrom; /* Solicit (net) bytes and report source */
  344. PRSendtoFN sendto; /* Send bytes to (net) address specified */
  345. PRPollFN poll; /* Test the fd to see if it is ready */
  346. PRAcceptreadFN acceptread; /* Accept and read on a new (net) fd */
  347. PRTransmitfileFN transmitfile; /* Transmit at entire file */
  348. PRGetsocknameFN getsockname; /* Get (net) address associated with fd */
  349. PRGetpeernameFN getpeername; /* Get peer's (net) address */
  350. PRReservedFN reserved_fn_6; /* reserved for future use */
  351. PRReservedFN reserved_fn_5; /* reserved for future use */
  352. PRGetsocketoptionFN getsocketoption;
  353. /* Get current setting of specified option */
  354. PRSetsocketoptionFN setsocketoption;
  355. /* Set value of specified option */
  356. PRSendfileFN sendfile; /* Send a (partial) file with header/trailer*/
  357. PRConnectcontinueFN connectcontinue;
  358. /* Continue a nonblocking connect */
  359. PRReservedFN reserved_fn_3; /* reserved for future use */
  360. PRReservedFN reserved_fn_2; /* reserved for future use */
  361. PRReservedFN reserved_fn_1; /* reserved for future use */
  362. PRReservedFN reserved_fn_0; /* reserved for future use */
  363. };
  364. /*
  365. **************************************************************************
  366. * FUNCTION: PR_GetSpecialFD
  367. * DESCRIPTION: Get the file descriptor that represents the standard input,
  368. * output, or error stream.
  369. * INPUTS:
  370. * PRSpecialFD id
  371. * A value indicating the type of stream desired:
  372. * PR_StandardInput: standard input
  373. * PR_StandardOuput: standard output
  374. * PR_StandardError: standard error
  375. * OUTPUTS: none
  376. * RETURNS: PRFileDesc *
  377. * If the argument is valid, PR_GetSpecialFD returns a file descriptor
  378. * that represents the corresponding standard I/O stream. Otherwise,
  379. * PR_GetSpecialFD returns NULL and sets error PR_INVALID_ARGUMENT_ERROR.
  380. **************************************************************************
  381. */
  382. typedef enum PRSpecialFD
  383. {
  384. PR_StandardInput, /* standard input */
  385. PR_StandardOutput, /* standard output */
  386. PR_StandardError /* standard error */
  387. } PRSpecialFD;
  388. NSPR_API(PRFileDesc*) PR_GetSpecialFD(PRSpecialFD id);
  389. #define PR_STDIN PR_GetSpecialFD(PR_StandardInput)
  390. #define PR_STDOUT PR_GetSpecialFD(PR_StandardOutput)
  391. #define PR_STDERR PR_GetSpecialFD(PR_StandardError)
  392. /*
  393. **************************************************************************
  394. * Layering file descriptors
  395. *
  396. * File descriptors may be layered. Each layer has it's own identity.
  397. * Identities are allocated by the runtime and are to be associated
  398. * (by the layer implementor) with all layers that are of that type.
  399. * It is then possible to scan the chain of layers and find a layer
  400. * that one recongizes and therefore predict that it will implement
  401. * a desired protocol.
  402. *
  403. * There are three well-known identities:
  404. * PR_INVALID_IO_LAYER => an invalid layer identity, for error return
  405. * PR_TOP_IO_LAYER => the identity of the top of the stack
  406. * PR_NSPR_IO_LAYER => the identity used by NSPR proper
  407. * PR_TOP_IO_LAYER may be used as a shorthand for identifying the topmost
  408. * layer of an existing stack. Ie., the following two constructs are
  409. * equivalent.
  410. *
  411. * rv = PR_PushIOLayer(stack, PR_TOP_IO_LAYER, my_layer);
  412. * rv = PR_PushIOLayer(stack, PR_GetLayersIdentity(stack), my_layer)
  413. *
  414. * A string may be associated with the creation of the identity. It
  415. * will be copied by the runtime. If queried the runtime will return
  416. * a reference to that copied string (not yet another copy). There
  417. * is no facility for deleting an identity.
  418. **************************************************************************
  419. */
  420. #define PR_IO_LAYER_HEAD (PRDescIdentity)-3
  421. #define PR_INVALID_IO_LAYER (PRDescIdentity)-1
  422. #define PR_TOP_IO_LAYER (PRDescIdentity)-2
  423. #define PR_NSPR_IO_LAYER (PRDescIdentity)0
  424. NSPR_API(PRDescIdentity) PR_GetUniqueIdentity(const char *layer_name);
  425. NSPR_API(const char*) PR_GetNameForIdentity(PRDescIdentity ident);
  426. NSPR_API(PRDescIdentity) PR_GetLayersIdentity(PRFileDesc* fd);
  427. NSPR_API(PRFileDesc*) PR_GetIdentitiesLayer(PRFileDesc* fd_stack, PRDescIdentity id);
  428. /*
  429. **************************************************************************
  430. * PR_GetDefaultIOMethods: Accessing the default methods table.
  431. * You may get a pointer to the default methods table by calling this function.
  432. * You may then select any elements from that table with which to build your
  433. * layer's methods table. You may NOT modify the table directly.
  434. **************************************************************************
  435. */
  436. NSPR_API(const PRIOMethods *) PR_GetDefaultIOMethods(void);
  437. /*
  438. **************************************************************************
  439. * Creating a layer
  440. *
  441. * A new layer may be allocated by calling PR_CreateIOLayerStub(). The
  442. * file descriptor returned will contain the pointer to the methods table
  443. * provided. The runtime will not modify the table nor test its correctness.
  444. **************************************************************************
  445. */
  446. NSPR_API(PRFileDesc*) PR_CreateIOLayerStub(
  447. PRDescIdentity ident, const PRIOMethods *methods);
  448. /*
  449. **************************************************************************
  450. * Creating a layer
  451. *
  452. * A new stack may be created by calling PR_CreateIOLayer(). The
  453. * file descriptor returned will point to the top of the stack, which has
  454. * the layer 'fd' as the topmost layer.
  455. *
  456. * NOTE: This function creates a new style stack, which has a fixed, dummy
  457. * header. The old style stack, created by a call to PR_PushIOLayer,
  458. * results in modifying contents of the top layer of the stack, when
  459. * pushing and popping layers of the stack.
  460. **************************************************************************
  461. */
  462. NSPR_API(PRFileDesc*) PR_CreateIOLayer(PRFileDesc* fd);
  463. /*
  464. **************************************************************************
  465. * Pushing a layer
  466. *
  467. * A file descriptor (perhaps allocated using PR_CreateIOLayerStub()) may
  468. * be pushed into an existing stack of file descriptors at any point the
  469. * caller deems appropriate. The new layer will be inserted into the stack
  470. * just above the layer with the indicated identity.
  471. *
  472. * Note: Even if the identity parameter indicates the top-most layer of
  473. * the stack, the value of the file descriptor describing the original
  474. * stack will not change.
  475. **************************************************************************
  476. */
  477. NSPR_API(PRStatus) PR_PushIOLayer(
  478. PRFileDesc *fd_stack, PRDescIdentity id, PRFileDesc *layer);
  479. /*
  480. **************************************************************************
  481. * Popping a layer
  482. *
  483. * A layer may be popped from a stack by indicating the identity of the
  484. * layer to be removed. If found, a pointer to the removed object will
  485. * be returned to the caller. The object then becomes the responsibility
  486. * of the caller.
  487. *
  488. * Note: Even if the identity indicates the top layer of the stack, the
  489. * reference returned will not be the file descriptor for the stack and
  490. * that file descriptor will remain valid.
  491. **************************************************************************
  492. */
  493. NSPR_API(PRFileDesc*) PR_PopIOLayer(PRFileDesc *fd_stack, PRDescIdentity id);
  494. /*
  495. **************************************************************************
  496. * FUNCTION: PR_Open
  497. * DESCRIPTION: Open a file for reading, writing, or both.
  498. * INPUTS:
  499. * const char *name
  500. * The path name of the file to be opened
  501. * PRIntn flags
  502. * The file status flags.
  503. * It is a bitwise OR of the following bit flags (only one of
  504. * the first three flags below may be used):
  505. * PR_RDONLY Open for reading only.
  506. * PR_WRONLY Open for writing only.
  507. * PR_RDWR Open for reading and writing.
  508. * PR_CREATE_FILE If the file does not exist, the file is created
  509. * If the file exists, this flag has no effect.
  510. * PR_SYNC If set, each write will wait for both the file data
  511. * and file status to be physically updated.
  512. * PR_APPEND The file pointer is set to the end of
  513. * the file prior to each write.
  514. * PR_TRUNCATE If the file exists, its length is truncated to 0.
  515. * PR_EXCL With PR_CREATE_FILE, if the file does not exist,
  516. * the file is created. If the file already
  517. * exists, no action and NULL is returned
  518. *
  519. * PRIntn mode
  520. * The access permission bits of the file mode, if the file is
  521. * created when PR_CREATE_FILE is on.
  522. * OUTPUTS: None
  523. * RETURNS: PRFileDesc *
  524. * If the file is successfully opened,
  525. * returns a pointer to the PRFileDesc
  526. * created for the newly opened file.
  527. * Returns a NULL pointer if the open
  528. * failed.
  529. * SIDE EFFECTS:
  530. * RESTRICTIONS:
  531. * MEMORY:
  532. * The return value, if not NULL, points to a dynamically allocated
  533. * PRFileDesc object.
  534. * ALGORITHM:
  535. **************************************************************************
  536. */
  537. /* Open flags */
  538. #define PR_RDONLY 0x01
  539. #define PR_WRONLY 0x02
  540. #define PR_RDWR 0x04
  541. #define PR_CREATE_FILE 0x08
  542. #define PR_APPEND 0x10
  543. #define PR_TRUNCATE 0x20
  544. #define PR_SYNC 0x40
  545. #define PR_EXCL 0x80
  546. /*
  547. ** File modes ....
  548. **
  549. ** CAVEAT: 'mode' is currently only applicable on UNIX platforms.
  550. ** The 'mode' argument may be ignored by PR_Open on other platforms.
  551. **
  552. ** 00400 Read by owner.
  553. ** 00200 Write by owner.
  554. ** 00100 Execute (search if a directory) by owner.
  555. ** 00040 Read by group.
  556. ** 00020 Write by group.
  557. ** 00010 Execute by group.
  558. ** 00004 Read by others.
  559. ** 00002 Write by others
  560. ** 00001 Execute by others.
  561. **
  562. */
  563. NSPR_API(PRFileDesc*) PR_Open(const char *name, PRIntn flags, PRIntn mode);
  564. /*
  565. **************************************************************************
  566. * FUNCTION: PR_OpenFile
  567. * DESCRIPTION:
  568. * Open a file for reading, writing, or both.
  569. * PR_OpenFile has the same prototype as PR_Open but implements
  570. * the specified file mode where possible.
  571. **************************************************************************
  572. */
  573. /* File mode bits */
  574. #define PR_IRWXU 00700 /* read, write, execute/search by owner */
  575. #define PR_IRUSR 00400 /* read permission, owner */
  576. #define PR_IWUSR 00200 /* write permission, owner */
  577. #define PR_IXUSR 00100 /* execute/search permission, owner */
  578. #define PR_IRWXG 00070 /* read, write, execute/search by group */
  579. #define PR_IRGRP 00040 /* read permission, group */
  580. #define PR_IWGRP 00020 /* write permission, group */
  581. #define PR_IXGRP 00010 /* execute/search permission, group */
  582. #define PR_IRWXO 00007 /* read, write, execute/search by others */
  583. #define PR_IROTH 00004 /* read permission, others */
  584. #define PR_IWOTH 00002 /* write permission, others */
  585. #define PR_IXOTH 00001 /* execute/search permission, others */
  586. NSPR_API(PRFileDesc*) PR_OpenFile(
  587. const char *name, PRIntn flags, PRIntn mode);
  588. #ifdef MOZ_UNICODE
  589. /*
  590. * EXPERIMENTAL: This function may be removed in a future release.
  591. */
  592. NSPR_API(PRFileDesc*) PR_OpenFileUTF16(
  593. const PRUnichar *name, PRIntn flags, PRIntn mode);
  594. #endif /* MOZ_UNICODE */
  595. /*
  596. **************************************************************************
  597. * FUNCTION: PR_Close
  598. * DESCRIPTION:
  599. * Close a file or socket.
  600. * INPUTS:
  601. * PRFileDesc *fd
  602. * a pointer to a PRFileDesc.
  603. * OUTPUTS:
  604. * None.
  605. * RETURN:
  606. * PRStatus
  607. * SIDE EFFECTS:
  608. * RESTRICTIONS:
  609. * None.
  610. * MEMORY:
  611. * The dynamic memory pointed to by the argument fd is freed.
  612. **************************************************************************
  613. */
  614. NSPR_API(PRStatus) PR_Close(PRFileDesc *fd);
  615. /*
  616. **************************************************************************
  617. * FUNCTION: PR_Read
  618. * DESCRIPTION:
  619. * Read bytes from a file or socket.
  620. * The operation will block until either an end of stream indication is
  621. * encountered, some positive number of bytes are transferred, or there
  622. * is an error. No more than 'amount' bytes will be transferred.
  623. * INPUTS:
  624. * PRFileDesc *fd
  625. * pointer to the PRFileDesc object for the file or socket
  626. * void *buf
  627. * pointer to a buffer to hold the data read in.
  628. * PRInt32 amount
  629. * the size of 'buf' (in bytes)
  630. * OUTPUTS:
  631. * RETURN:
  632. * PRInt32
  633. * a positive number indicates the number of bytes actually read in.
  634. * 0 means end of file is reached or the network connection is closed.
  635. * -1 indicates a failure. The reason for the failure is obtained
  636. * by calling PR_GetError().
  637. * SIDE EFFECTS:
  638. * data is written into the buffer pointed to by 'buf'.
  639. * RESTRICTIONS:
  640. * None.
  641. * MEMORY:
  642. * N/A
  643. * ALGORITHM:
  644. * N/A
  645. **************************************************************************
  646. */
  647. NSPR_API(PRInt32) PR_Read(PRFileDesc *fd, void *buf, PRInt32 amount);
  648. /*
  649. ***************************************************************************
  650. * FUNCTION: PR_Write
  651. * DESCRIPTION:
  652. * Write a specified number of bytes to a file or socket. The thread
  653. * invoking this function blocks until all the data is written.
  654. * INPUTS:
  655. * PRFileDesc *fd
  656. * pointer to a PRFileDesc object that refers to a file or socket
  657. * const void *buf
  658. * pointer to the buffer holding the data
  659. * PRInt32 amount
  660. * amount of data in bytes to be written from the buffer
  661. * OUTPUTS:
  662. * None.
  663. * RETURN: PRInt32
  664. * A positive number indicates the number of bytes successfully written.
  665. * A -1 is an indication that the operation failed. The reason
  666. * for the failure is obtained by calling PR_GetError().
  667. ***************************************************************************
  668. */
  669. NSPR_API(PRInt32) PR_Write(PRFileDesc *fd,const void *buf,PRInt32 amount);
  670. /*
  671. ***************************************************************************
  672. * FUNCTION: PR_Writev
  673. * DESCRIPTION:
  674. * Write data to a socket. The data is organized in a PRIOVec array. The
  675. * operation will block until all the data is written or the operation
  676. * fails.
  677. * INPUTS:
  678. * PRFileDesc *fd
  679. * Pointer that points to a PRFileDesc object for a socket.
  680. * const PRIOVec *iov
  681. * An array of PRIOVec. PRIOVec is a struct with the following
  682. * two fields:
  683. * char *iov_base;
  684. * int iov_len;
  685. * PRInt32 iov_size
  686. * Number of elements in the iov array. The value of this
  687. * argument must not be greater than PR_MAX_IOVECTOR_SIZE.
  688. * If it is, the method will fail (PR_BUFFER_OVERFLOW_ERROR).
  689. * PRIntervalTime timeout
  690. * Time limit for completion of the entire write operation.
  691. * OUTPUTS:
  692. * None
  693. * RETURN:
  694. * A positive number indicates the number of bytes successfully written.
  695. * A -1 is an indication that the operation failed. The reason
  696. * for the failure is obtained by calling PR_GetError().
  697. ***************************************************************************
  698. */
  699. #define PR_MAX_IOVECTOR_SIZE 16 /* 'iov_size' must be <= */
  700. NSPR_API(PRInt32) PR_Writev(
  701. PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size,
  702. PRIntervalTime timeout);
  703. /*
  704. ***************************************************************************
  705. * FUNCTION: PR_Delete
  706. * DESCRIPTION:
  707. * Delete a file from the filesystem. The operation may fail if the
  708. * file is open.
  709. * INPUTS:
  710. * const char *name
  711. * Path name of the file to be deleted.
  712. * OUTPUTS:
  713. * None.
  714. * RETURN: PRStatus
  715. * The function returns PR_SUCCESS if the file is successfully
  716. * deleted, otherwise it returns PR_FAILURE.
  717. ***************************************************************************
  718. */
  719. NSPR_API(PRStatus) PR_Delete(const char *name);
  720. /**************************************************************************/
  721. typedef enum PRFileType
  722. {
  723. PR_FILE_FILE = 1,
  724. PR_FILE_DIRECTORY = 2,
  725. PR_FILE_OTHER = 3
  726. } PRFileType;
  727. struct PRFileInfo {
  728. PRFileType type; /* Type of file */
  729. PROffset32 size; /* Size, in bytes, of file's contents */
  730. PRTime creationTime; /* Creation time per definition of PRTime */
  731. PRTime modifyTime; /* Last modification time per definition of PRTime */
  732. };
  733. struct PRFileInfo64 {
  734. PRFileType type; /* Type of file */
  735. PROffset64 size; /* Size, in bytes, of file's contents */
  736. PRTime creationTime; /* Creation time per definition of PRTime */
  737. PRTime modifyTime; /* Last modification time per definition of PRTime */
  738. };
  739. /****************************************************************************
  740. * FUNCTION: PR_GetFileInfo, PR_GetFileInfo64
  741. * DESCRIPTION:
  742. * Get the information about the file with the given path name. This is
  743. * applicable only to NSFileDesc describing 'file' types (see
  744. * INPUTS:
  745. * const char *fn
  746. * path name of the file
  747. * OUTPUTS:
  748. * PRFileInfo *info
  749. * Information about the given file is written into the file
  750. * information object pointer to by 'info'.
  751. * RETURN: PRStatus
  752. * PR_GetFileInfo returns PR_SUCCESS if file information is successfully
  753. * obtained, otherwise it returns PR_FAILURE.
  754. ***************************************************************************
  755. */
  756. NSPR_API(PRStatus) PR_GetFileInfo(const char *fn, PRFileInfo *info);
  757. NSPR_API(PRStatus) PR_GetFileInfo64(const char *fn, PRFileInfo64 *info);
  758. #ifdef MOZ_UNICODE
  759. /*
  760. * EXPERIMENTAL: This function may be removed in a future release.
  761. */
  762. NSPR_API(PRStatus) PR_GetFileInfo64UTF16(const PRUnichar *fn, PRFileInfo64 *info);
  763. #endif /* MOZ_UNICODE */
  764. /*
  765. **************************************************************************
  766. * FUNCTION: PR_GetOpenFileInfo, PR_GetOpenFileInfo64
  767. * DESCRIPTION:
  768. * Get information about an open file referred to by the
  769. * given PRFileDesc object.
  770. * INPUTS:
  771. * const PRFileDesc *fd
  772. * A reference to a valid, open file.
  773. * OUTPUTS:
  774. * Same as PR_GetFileInfo, PR_GetFileInfo64
  775. * RETURN: PRStatus
  776. * PR_GetFileInfo returns PR_SUCCESS if file information is successfully
  777. * obtained, otherwise it returns PR_FAILURE.
  778. ***************************************************************************
  779. */
  780. NSPR_API(PRStatus) PR_GetOpenFileInfo(PRFileDesc *fd, PRFileInfo *info);
  781. NSPR_API(PRStatus) PR_GetOpenFileInfo64(PRFileDesc *fd, PRFileInfo64 *info);
  782. /*
  783. **************************************************************************
  784. * FUNCTION: PR_Rename
  785. * DESCRIPTION:
  786. * Rename a file from the old name 'from' to the new name 'to'.
  787. * INPUTS:
  788. * const char *from
  789. * The old name of the file to be renamed.
  790. * const char *to
  791. * The new name of the file.
  792. * OUTPUTS:
  793. * None.
  794. * RETURN: PRStatus
  795. **************************************************************************
  796. */
  797. NSPR_API(PRStatus) PR_Rename(const char *from, const char *to);
  798. /*
  799. *************************************************************************
  800. * FUNCTION: PR_Access
  801. * DESCRIPTION:
  802. * Determine accessibility of a file.
  803. * INPUTS:
  804. * const char *name
  805. * path name of the file
  806. * PRAccessHow how
  807. * specifies which access permission to check for.
  808. * It can be one of the following values:
  809. * PR_ACCESS_READ_OK Test for read permission
  810. * PR_ACCESS_WRITE_OK Test for write permission
  811. * PR_ACCESS_EXISTS Check existence of file
  812. * OUTPUTS:
  813. * None.
  814. * RETURN: PRStatus
  815. * PR_SUCCESS is returned if the requested access is permitted.
  816. * Otherwise, PR_FAILURE is returned. Additional information
  817. * regarding the reason for the failure may be retrieved from
  818. * PR_GetError().
  819. *************************************************************************
  820. */
  821. typedef enum PRAccessHow {
  822. PR_ACCESS_EXISTS = 1,
  823. PR_ACCESS_WRITE_OK = 2,
  824. PR_ACCESS_READ_OK = 3
  825. } PRAccessHow;
  826. NSPR_API(PRStatus) PR_Access(const char *name, PRAccessHow how);
  827. /*
  828. *************************************************************************
  829. * FUNCTION: PR_Seek, PR_Seek64
  830. * DESCRIPTION:
  831. * Moves read-write file offset
  832. * INPUTS:
  833. * PRFileDesc *fd
  834. * Pointer to a PRFileDesc object.
  835. * PROffset32, PROffset64 offset
  836. * Specifies a value, in bytes, that is used in conjunction
  837. * with the 'whence' parameter to set the file pointer. A
  838. * negative value causes seeking in the reverse direction.
  839. * PRSeekWhence whence
  840. * Specifies how to interpret the 'offset' parameter in setting
  841. * the file pointer associated with the 'fd' parameter.
  842. * Values for the 'whence' parameter are:
  843. * PR_SEEK_SET Sets the file pointer to the value of the
  844. * 'offset' parameter
  845. * PR_SEEK_CUR Sets the file pointer to its current location
  846. * plus the value of the offset parameter.
  847. * PR_SEEK_END Sets the file pointer to the size of the
  848. * file plus the value of the offset parameter.
  849. * OUTPUTS:
  850. * None.
  851. * RETURN: PROffset32, PROffset64
  852. * Upon successful completion, the resulting pointer location,
  853. * measured in bytes from the beginning of the file, is returned.
  854. * If the PR_Seek() function fails, the file offset remains
  855. * unchanged, and the returned value is -1. The error code can
  856. * then be retrieved via PR_GetError().
  857. *************************************************************************
  858. */
  859. NSPR_API(PROffset32) PR_Seek(PRFileDesc *fd, PROffset32 offset, PRSeekWhence whence);
  860. NSPR_API(PROffset64) PR_Seek64(PRFileDesc *fd, PROffset64 offset, PRSeekWhence whence);
  861. /*
  862. ************************************************************************
  863. * FUNCTION: PR_Available
  864. * DESCRIPTION:
  865. * Determine the amount of data in bytes available for reading
  866. * in the given file or socket.
  867. * INPUTS:
  868. * PRFileDesc *fd
  869. * Pointer to a PRFileDesc object that refers to a file or
  870. * socket.
  871. * OUTPUTS:
  872. * None
  873. * RETURN: PRInt32, PRInt64
  874. * Upon successful completion, PR_Available returns the number of
  875. * bytes beyond the current read pointer that is available for
  876. * reading. Otherwise, it returns a -1 and the reason for the
  877. * failure can be retrieved via PR_GetError().
  878. ************************************************************************
  879. */
  880. NSPR_API(PRInt32) PR_Available(PRFileDesc *fd);
  881. NSPR_API(PRInt64) PR_Available64(PRFileDesc *fd);
  882. /*
  883. ************************************************************************
  884. * FUNCTION: PR_Sync
  885. * DESCRIPTION:
  886. * Sync any buffered data for a fd to its backing device (disk).
  887. * INPUTS:
  888. * PRFileDesc *fd
  889. * Pointer to a PRFileDesc object that refers to a file or
  890. * socket
  891. * OUTPUTS:
  892. * None
  893. * RETURN: PRStatus
  894. * PR_SUCCESS is returned if the requested access is permitted.
  895. * Otherwise, PR_FAILURE is returned.
  896. ************************************************************************
  897. */
  898. NSPR_API(PRStatus) PR_Sync(PRFileDesc *fd);
  899. /************************************************************************/
  900. struct PRDirEntry {
  901. const char *name; /* name of entry, relative to directory name */
  902. };
  903. #ifdef MOZ_UNICODE
  904. struct PRDirEntryUTF16 {
  905. const PRUnichar *name; /* name of entry in UTF16, relative to
  906. * directory name */
  907. };
  908. #endif /* MOZ_UNICODE */
  909. #if !defined(NO_NSPR_10_SUPPORT)
  910. #define PR_DirName(dirEntry) (dirEntry->name)
  911. #endif
  912. /*
  913. *************************************************************************
  914. * FUNCTION: PR_OpenDir
  915. * DESCRIPTION:
  916. * Open the directory by the given name
  917. * INPUTS:
  918. * const char *name
  919. * path name of the directory to be opened
  920. * OUTPUTS:
  921. * None
  922. * RETURN: PRDir *
  923. * If the directory is sucessfully opened, a PRDir object is
  924. * dynamically allocated and a pointer to it is returned.
  925. * If the directory cannot be opened, a NULL pointer is returned.
  926. * MEMORY:
  927. * Upon successful completion, the return value points to
  928. * dynamically allocated memory.
  929. *************************************************************************
  930. */
  931. NSPR_API(PRDir*) PR_OpenDir(const char *name);
  932. #ifdef MOZ_UNICODE
  933. /*
  934. * EXPERIMENTAL: This function may be removed in a future release.
  935. */
  936. NSPR_API(PRDirUTF16*) PR_OpenDirUTF16(const PRUnichar *name);
  937. #endif /* MOZ_UNICODE */
  938. /*
  939. *************************************************************************
  940. * FUNCTION: PR_ReadDir
  941. * DESCRIPTION:
  942. * INPUTS:
  943. * PRDir *dir
  944. * pointer to a PRDir object that designates an open directory
  945. * PRDirFlags flags
  946. * PR_SKIP_NONE Do not skip any files
  947. * PR_SKIP_DOT Skip the directory entry "." that
  948. * represents the current directory
  949. * PR_SKIP_DOT_DOT Skip the directory entry ".." that
  950. * represents the parent directory.
  951. * PR_SKIP_BOTH Skip both '.' and '..'
  952. * PR_SKIP_HIDDEN Skip hidden files
  953. * OUTPUTS:
  954. * RETURN: PRDirEntry*
  955. * Returns a pointer to the next entry in the directory. Returns
  956. * a NULL pointer upon reaching the end of the directory or when an
  957. * error occurs. The actual reason can be retrieved via PR_GetError().
  958. *************************************************************************
  959. */
  960. typedef enum PRDirFlags {
  961. PR_SKIP_NONE = 0x0,
  962. PR_SKIP_DOT = 0x1,
  963. PR_SKIP_DOT_DOT = 0x2,
  964. PR_SKIP_BOTH = 0x3,
  965. PR_SKIP_HIDDEN = 0x4
  966. } PRDirFlags;
  967. NSPR_API(PRDirEntry*) PR_ReadDir(PRDir *dir, PRDirFlags flags);
  968. #ifdef MOZ_UNICODE
  969. /*
  970. * EXPERIMENTAL: This function may be removed in a future release.
  971. */
  972. NSPR_API(PRDirEntryUTF16*) PR_ReadDirUTF16(PRDirUTF16 *dir, PRDirFlags flags);
  973. #endif /* MOZ_UNICODE */
  974. /*
  975. *************************************************************************
  976. * FUNCTION: PR_CloseDir
  977. * DESCRIPTION:
  978. * Close the specified directory.
  979. * INPUTS:
  980. * PRDir *dir
  981. * The directory to be closed.
  982. * OUTPUTS:
  983. * None
  984. * RETURN: PRStatus
  985. * If successful, will return a status of PR_SUCCESS. Otherwise
  986. * a value of PR_FAILURE. The reason for the failure may be re-
  987. * trieved using PR_GetError().
  988. *************************************************************************
  989. */
  990. NSPR_API(PRStatus) PR_CloseDir(PRDir *dir);
  991. #ifdef MOZ_UNICODE
  992. /*
  993. * EXPERIMENTAL: This function may be removed in a future release.
  994. */
  995. NSPR_API(PRStatus) PR_CloseDirUTF16(PRDirUTF16 *dir);
  996. #endif /* MOZ_UNICODE */
  997. /*
  998. *************************************************************************
  999. * FUNCTION: PR_MkDir
  1000. * DESCRIPTION:
  1001. * Create a new directory with the given name and access mode.
  1002. * INPUTS:
  1003. * const char *name
  1004. * The name of the directory to be created. All the path components
  1005. * up to but not including the leaf component must already exist.
  1006. * PRIntn mode
  1007. * See 'mode' definiton in PR_Open().
  1008. * OUTPUTS:
  1009. * None
  1010. * RETURN: PRStatus
  1011. * If successful, will return a status of PR_SUCCESS. Otherwise
  1012. * a value of PR_FAILURE. The reason for the failure may be re-
  1013. * trieved using PR_GetError().
  1014. *************************************************************************
  1015. */
  1016. NSPR_API(PRStatus) PR_MkDir(const char *name, PRIntn mode);
  1017. /*
  1018. *************************************************************************
  1019. * FUNCTION: PR_MakeDir
  1020. * DESCRIPTION:
  1021. * Create a new directory with the given name and access mode.
  1022. * PR_MakeDir has the same prototype as PR_MkDir but implements
  1023. * the specified access mode where possible.
  1024. *************************************************************************
  1025. */
  1026. NSPR_API(PRStatus) PR_MakeDir(const char *name, PRIntn mode);
  1027. /*
  1028. *************************************************************************
  1029. * FUNCTION: PR_RmDir
  1030. * DESCRIPTION:
  1031. * Remove a directory by the given name.
  1032. * INPUTS:
  1033. * const char *name
  1034. * The name of the directory to be removed. All the path components
  1035. * must already exist. Only the leaf component will be removed.
  1036. * OUTPUTS:
  1037. * None
  1038. * RETURN: PRStatus
  1039. * If successful, will return a status of PR_SUCCESS. Otherwise
  1040. * a value of PR_FAILURE. The reason for the failure may be re-
  1041. * trieved using PR_GetError().
  1042. **************************************************************************
  1043. */
  1044. NSPR_API(PRStatus) PR_RmDir(const char *name);
  1045. /*
  1046. *************************************************************************
  1047. * FUNCTION: PR_NewUDPSocket
  1048. * DESCRIPTION:
  1049. * Create a new UDP socket.
  1050. * INPUTS:
  1051. * None
  1052. * OUTPUTS:
  1053. * None
  1054. * RETURN: PRFileDesc*
  1055. * Upon successful completion, PR_NewUDPSocket returns a pointer
  1056. * to the PRFileDesc created for the newly opened UDP socket.
  1057. * Returns a NULL pointer if the creation of a new UDP socket failed.
  1058. *
  1059. **************************************************************************
  1060. */
  1061. NSPR_API(PRFileDesc*) PR_NewUDPSocket(void);
  1062. /*
  1063. *************************************************************************
  1064. * FUNCTION: PR_NewTCPSocket
  1065. * DESCRIPTION:
  1066. * Create a new TCP socket.
  1067. * INPUTS:
  1068. * None
  1069. * OUTPUTS:
  1070. * None
  1071. * RETURN: PRFileDesc*
  1072. * Upon successful completion, PR_NewTCPSocket returns a pointer
  1073. * to the PRFileDesc created for the newly opened TCP socket.
  1074. * Returns a NULL pointer if the creation of a new TCP socket failed.
  1075. *
  1076. **************************************************************************
  1077. */
  1078. NSPR_API(PRFileDesc*) PR_NewTCPSocket(void);
  1079. /*
  1080. *************************************************************************
  1081. * FUNCTION: PR_OpenUDPSocket
  1082. * DESCRIPTION:
  1083. * Create a new UDP socket of the specified address family.
  1084. * INPUTS:
  1085. * PRIntn af
  1086. * Address family
  1087. * OUTPUTS:
  1088. * None
  1089. * RETURN: PRFileDesc*
  1090. * Upon successful completion, PR_OpenUDPSocket returns a pointer
  1091. * to the PRFileDesc created for the newly opened UDP socket.
  1092. * Returns a NULL pointer if the creation of a new UDP socket failed.
  1093. *
  1094. **************************************************************************
  1095. */
  1096. NSPR_API(PRFileDesc*) PR_OpenUDPSocket(PRIntn af);
  1097. /*
  1098. *************************************************************************
  1099. * FUNCTION: PR_OpenTCPSocket
  1100. * DESCRIPTION:
  1101. * Create a new TCP socket of the specified address family.
  1102. * INPUTS:
  1103. * PRIntn af
  1104. * Address family
  1105. * OUTPUTS:
  1106. * None
  1107. * RETURN: PRFileDesc*
  1108. * Upon successful completion, PR_NewTCPSocket returns a pointer
  1109. * to the PRFileDesc created for the newly opened TCP socket.
  1110. * Returns a NULL pointer if the creation of a new TCP socket failed.
  1111. *
  1112. **************************************************************************
  1113. */
  1114. NSPR_API(PRFileDesc*) PR_OpenTCPSocket(PRIntn af);
  1115. /*
  1116. *************************************************************************
  1117. * FUNCTION: PR_Connect
  1118. * DESCRIPTION:
  1119. * Initiate a connection on a socket.
  1120. * INPUTS:
  1121. * PRFileDesc *fd
  1122. * Points to a PRFileDesc object representing a socket
  1123. * PRNetAddr *addr
  1124. * Specifies the address of the socket in its own communication
  1125. * space.
  1126. * PRIntervalTime timeout
  1127. * The function uses the lesser of the provided timeout and
  1128. * the OS's connect timeout. In particular, if you specify
  1129. * PR_INTERVAL_NO_TIMEOUT as the timeout, the OS's connection
  1130. * time limit will be used.
  1131. *
  1132. * OUTPUTS:
  1133. * None
  1134. * RETURN: PRStatus
  1135. * Upon successful completion of connection initiation, PR_Connect
  1136. * returns PR_SUCCESS. Otherwise, it returns PR_FAILURE. Further
  1137. * failure information can be obtained by calling PR_GetError().
  1138. **************************************************************************
  1139. */
  1140. NSPR_API(PRStatus) PR_Connect(
  1141. PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout);
  1142. /*
  1143. *************************************************************************
  1144. * FUNCTION: PR_ConnectContinue
  1145. * DESCRIPTION:
  1146. * Continue a nonblocking connect. After a nonblocking connect
  1147. * is initiated with PR_Connect() (which fails with
  1148. * PR_IN_PROGRESS_ERROR), one should call PR_Poll() on the socket,
  1149. * with the in_flags PR_POLL_WRITE | PR_POLL_EXCEPT. When
  1150. * PR_Poll() returns, one calls PR_ConnectContinue() on the
  1151. * socket to determine whether the nonblocking connect has
  1152. * completed or is still in progress. Repeat the PR_Poll(),
  1153. * PR_ConnectContinue() sequence until the nonblocking connect
  1154. * has completed.
  1155. * INPUTS:
  1156. * PRFileDesc *fd
  1157. * the file descriptor representing a socket
  1158. * PRInt16 out_flags
  1159. * the out_flags field of the poll descriptor returned by
  1160. * PR_Poll()
  1161. * RETURN: PRStatus
  1162. * If the nonblocking connect has successfully completed,
  1163. * PR_ConnectContinue returns PR_SUCCESS. If PR_ConnectContinue()
  1164. * returns PR_FAILURE, call PR_GetError():
  1165. * - PR_IN_PROGRESS_ERROR: the nonblocking connect is still in
  1166. * progress and has not completed yet. The caller should poll
  1167. * on the file descriptor for the in_flags
  1168. * PR_POLL_WRITE|PR_POLL_EXCEPT and retry PR_ConnectContinue
  1169. * later when PR_Poll() returns.
  1170. * - Other errors: the nonblocking connect has failed with this
  1171. * error code.
  1172. */
  1173. NSPR_API(PRStatus) PR_ConnectContinue(PRFileDesc *fd, PRInt16 out_flags);
  1174. /*
  1175. *************************************************************************
  1176. * THIS FUNCTION IS DEPRECATED. USE PR_ConnectContinue INSTEAD.
  1177. *
  1178. * FUNCTION: PR_GetConnectStatus
  1179. * DESCRIPTION:
  1180. * Get the completion status of a nonblocking connect. After
  1181. * a nonblocking connect is initiated with PR_Connect() (which
  1182. * fails with PR_IN_PROGRESS_ERROR), one should call PR_Poll()
  1183. * on the socket, with the in_flags PR_POLL_WRITE | PR_POLL_EXCEPT.
  1184. * When PR_Poll() returns, one calls PR_GetConnectStatus on the
  1185. * PRPollDesc structure to determine whether the nonblocking
  1186. * connect has succeeded or failed.
  1187. * INPUTS:
  1188. * const PRPollDesc *pd
  1189. * Pointer to a PRPollDesc whose fd member is the socket,
  1190. * and in_flags must contain PR_POLL_WRITE and PR_POLL_EXCEPT.
  1191. * PR_Poll() should have been called and set the out_flags.
  1192. * RETURN: PRStatus
  1193. * If the nonblocking connect has successfully completed,
  1194. * PR_GetConnectStatus returns PR_SUCCESS. If PR_GetConnectStatus()
  1195. * returns PR_FAILURE, call PR_GetError():
  1196. * - PR_IN_PROGRESS_ERROR: the nonblocking connect is still in
  1197. * progress and has not completed yet.
  1198. * - Other errors: the nonblocking connect has failed with this
  1199. * error code.
  1200. */
  1201. NSPR_API(PRStatus) PR_GetConnectStatus(const PRPollDesc *pd);
  1202. /*
  1203. *************************************************************************
  1204. * FUNCTION: PR_Accept
  1205. * DESCRIPTION:
  1206. * Accept a connection on a socket.
  1207. * INPUTS:
  1208. * PRFileDesc *fd
  1209. * Points to a PRFileDesc object representing the rendezvous socket
  1210. * on which the caller is willing to accept new connections.
  1211. * PRIntervalTime timeout
  1212. * Time limit for completion of the accept operation.
  1213. * OUTPUTS:
  1214. * PRNetAddr *addr
  1215. * Returns the address of the connecting entity in its own
  1216. * communication space. It may be NULL.
  1217. * RETURN: PRFileDesc*
  1218. * Upon successful acceptance of a connection, PR_Accept
  1219. * returns a valid file descriptor. Otherwise, it returns NULL.
  1220. * Further failure information can be obtained by calling PR_GetError().
  1221. **************************************************************************
  1222. */
  1223. NSPR_API(PRFileDesc*) PR_Accept(
  1224. PRFileDesc *fd, PRNetAddr *addr, PRIntervalTime timeout);
  1225. /*
  1226. *************************************************************************
  1227. * FUNCTION: PR_Bind
  1228. * DESCRIPTION:
  1229. * Bind an address to a socket.
  1230. * INPUTS:
  1231. * PRFileDesc *fd
  1232. * Points to a PRFileDesc object representing a socket.
  1233. * PRNetAddr *addr
  1234. * Specifies the address to which the socket will be bound.
  1235. * OUTPUTS:
  1236. * None
  1237. * RETURN: PRStatus
  1238. * Upon successful binding of an address to a socket, PR_Bind
  1239. * returns PR_SUCCESS. Otherwise, it returns PR_FAILURE. Further
  1240. * failure information can be obtained by calling PR_GetError().
  1241. **************************************************************************
  1242. */
  1243. NSPR_API(PRStatus) PR_Bind(PRFileDesc *fd, const PRNetAddr *addr);
  1244. /*
  1245. *************************************************************************
  1246. * FUNCTION: PR_Listen
  1247. * DESCRIPTION:
  1248. * Listen for connections on a socket.
  1249. * INPUTS:
  1250. * PRFileDesc *fd
  1251. * Points to a PRFileDesc object representing a socket that will be
  1252. * used to listen for new connections.
  1253. * PRIntn backlog
  1254. * Specifies the maximum length of the queue of pending connections.
  1255. * OUTPUTS:
  1256. * None
  1257. * RETURN: PRStatus
  1258. * Upon successful completion of listen request, PR_Listen
  1259. * returns PR_SUCCESS. Otherwise, it returns PR_FAILURE. Further
  1260. * failure information can be obtained by calling PR_GetError().
  1261. **************************************************************************
  1262. */
  1263. NSPR_API(PRStatus) PR_Listen(PRFileDesc *fd, PRIntn backlog);
  1264. /*
  1265. *************************************************************************
  1266. * FUNCTION: PR_Shutdown
  1267. * DESCRIPTION:
  1268. * Shut down part of a full-duplex connection on a socket.
  1269. * INPUTS:
  1270. * PRFileDesc *fd
  1271. * Points to a PRFileDesc object representing a connected socket.
  1272. * PRIntn how
  1273. * Specifies the kind of disallowed operations on the socket.
  1274. * PR_SHUTDOWN_RCV - Further receives will be disallowed
  1275. * PR_SHUTDOWN_SEND - Further sends will be disallowed
  1276. * PR_SHUTDOWN_BOTH - Further sends and receives will be disallowed
  1277. * OUTPUTS:
  1278. * None
  1279. * RETURN: PRStatus
  1280. * Upon successful completion of shutdown request, PR_Shutdown
  1281. * returns PR_SUCCESS. Otherwise, it returns PR_FAILURE. Further
  1282. * failure information can be obtained by calling PR_GetError().
  1283. **************************************************************************
  1284. */
  1285. typedef enum PRShutdownHow
  1286. {
  1287. PR_SHUTDOWN_RCV = 0, /* disallow further receives */
  1288. PR_SHUTDOWN_SEND = 1, /* disallow further sends */
  1289. PR_SHUTDOWN_BOTH = 2 /* disallow further receives and sends */
  1290. } PRShutdownHow;
  1291. NSPR_API(PRStatus) PR_Shutdown(PRFileDesc *fd, PRShutdownHow how);
  1292. /*
  1293. *************************************************************************
  1294. * FUNCTION: PR_Recv
  1295. * DESCRIPTION:
  1296. * Receive a specified number of bytes from a connected socket.
  1297. * The operation will block until some positive number of bytes are
  1298. * transferred, a time out has occurred, or there is an error.
  1299. * No more than 'amount' bytes will be transferred.
  1300. * INPUTS:
  1301. * PRFileDesc *fd
  1302. * points to a PRFileDesc object representing a socket.
  1303. * void *buf
  1304. * pointer to a buffer to hold the data received.
  1305. * PRInt32 amount
  1306. * the size of 'buf' (in bytes)
  1307. * PRIntn flags
  1308. * must be zero or PR_MSG_PEEK.
  1309. * PRIntervalTime timeout
  1310. * Time limit for completion of the receive operation.
  1311. * OUTPUTS:
  1312. * None
  1313. * RETURN: PRInt32
  1314. * a positive number indicates the number of bytes actually received.
  1315. * 0 means the network connection is closed.
  1316. * -1 indicates a failure. The reason for the failure is obtained
  1317. * by calling PR_GetError().
  1318. **************************************************************************
  1319. */
  1320. #define PR_MSG_PEEK 0x2
  1321. NSPR_API(PRInt32) PR_Recv(PRFileDesc *fd, void *buf, PRInt32 amount,
  1322. PRIntn flags, PRIntervalTime timeout);
  1323. /*
  1324. *************************************************************************
  1325. * FUNCTION: PR_Send
  1326. * DESCRIPTION:
  1327. * Send a specified number of bytes from a connected socket.
  1328. * The operation will block until all bytes are
  1329. * processed, a time out has occurred, or there is an error.
  1330. * INPUTS:
  1331. * PRFileDesc *fd
  1332. * points to a PRFileDesc object representing a socket.
  1333. * void *buf
  1334. * pointer to a buffer from where the data is sent.
  1335. * PRInt32 amount
  1336. * the size of 'buf' (in bytes)
  1337. * PRIntn flags
  1338. * (OBSOLETE - must always be zero)
  1339. * PRIntervalTime timeout
  1340. * Time limit for completion of the send operation.
  1341. * OUTPUTS:
  1342. * None
  1343. * RETURN: PRInt32
  1344. * A positive number indicates the number of bytes successfully processed.
  1345. * This number must always equal 'amount'. A -1 is an indication that the
  1346. * operation failed. The reason for the failure is obtained by calling
  1347. * PR_GetError().
  1348. **************************************************************************
  1349. */
  1350. NSPR_API(PRInt32) PR_Send(PRFileDesc *fd, const void *buf, PRInt32 amount,
  1351. PRIntn flags, PRIntervalTime timeout);
  1352. /*
  1353. *************************************************************************
  1354. * FUNCTION: PR_RecvFrom
  1355. * DESCRIPTION:
  1356. * Receive up to a specified number of bytes from socket which may
  1357. * or may not be connected.
  1358. * The operation will block until one or more bytes are
  1359. * transferred, a time out has occurred, or there is an error.
  1360. * No more than 'amount' bytes will be transferred.
  1361. * INPUTS:
  1362. * PRFileDesc *fd
  1363. * points to a PRFileDesc object representing a socket.
  1364. * void *buf
  1365. * pointer to a buffer to hold the data received.
  1366. * PRInt32 amount
  1367. * the size of 'buf' (in bytes)
  1368. * PRIntn flags
  1369. * (OBSOLETE - must always be zero)
  1370. * PRNetAddr *addr
  1371. * Specifies the address of the sending peer. It may be NULL.
  1372. * PRIntervalTime timeout
  1373. * Time limit for completion of the receive operation.
  1374. * OUTPUTS:
  1375. * None
  1376. * RETURN: PRInt32
  1377. * a positive number indicates the number of bytes actually received.
  1378. * 0 means the network connection is closed.
  1379. * -1 indicates a failure. The reason for the failure is obtained
  1380. * by calling PR_GetError().
  1381. **************************************************************************
  1382. */
  1383. NSPR_API(PRInt32) PR_RecvFrom(
  1384. PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
  1385. PRNetAddr *addr, PRIntervalTime timeout);
  1386. /*
  1387. *************************************************************************
  1388. * FUNCTION: PR_SendTo
  1389. * DESCRIPTION:
  1390. * Send a specified number of bytes from an unconnected socket.
  1391. * The operation will block until all bytes are
  1392. * sent, a time out has occurred, or there is an error.
  1393. * INPUTS:
  1394. * PRFileDesc *fd
  1395. * points to a PRFileDesc object representing an unconnected socket.
  1396. * void *buf
  1397. * pointer to a buffer from where the data is sent.
  1398. * PRInt32 amount
  1399. * the size of 'buf' (in bytes)
  1400. * PRIntn flags
  1401. * (OBSOLETE - must always be zero)
  1402. * PRNetAddr *addr
  1403. * Specifies the address of the peer.
  1404. .* PRIntervalTime timeout
  1405. * Time limit for completion of the send operation.
  1406. * OUTPUTS:
  1407. * None
  1408. * RETURN: PRInt32
  1409. * A positive number indicates the number of bytes successfully sent.
  1410. * -1 indicates a failure. The reason for the failure is obtained
  1411. * by calling PR_GetError().
  1412. **************************************************************************
  1413. */
  1414. NSPR_API(PRInt32) PR_SendTo(
  1415. PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
  1416. const PRNetAddr *addr, PRIntervalTime timeout);
  1417. /*
  1418. *************************************************************************
  1419. ** FUNCTION: PR_TransmitFile
  1420. ** DESCRIPTION:
  1421. ** Transmitfile sends a complete file (sourceFile) across a socket
  1422. ** (networkSocket). If headers is non-NULL, the headers will be sent across
  1423. ** the socket prior to sending the file.
  1424. **
  1425. ** Optionally, the PR_TRANSMITFILE_CLOSE_SOCKET flag may be passed to
  1426. ** transmitfile. This flag specifies that transmitfile should close the
  1427. ** socket after sending the data.
  1428. **
  1429. ** INPUTS:
  1430. ** PRFileDesc *networkSocket
  1431. ** The socket to send data over
  1432. ** PRFileDesc *sourceFile
  1433. ** The file to send
  1434. ** const void *headers
  1435. ** A pointer to headers to be sent before sending data
  1436. ** PRInt32 hlen
  1437. ** length of header buffers in bytes.
  1438. ** PRTransmitFileFlags flags
  1439. ** If the flags indicate that the connection should be closed,
  1440. ** it will be done immediately after transferring the file, unless
  1441. ** the operation is unsuccessful.
  1442. .* PRIntervalTime timeout
  1443. * Time limit for completion of the transmit operation.
  1444. **
  1445. ** RETURNS:
  1446. ** Returns the number of bytes written or -1 if the operation failed.
  1447. ** If an error occurs while sending the file, the PR_TRANSMITFILE_CLOSE_
  1448. ** SOCKET flag is ignored. The reason for the failure is obtained
  1449. ** by calling PR_GetError().
  1450. **************************************************************************
  1451. */
  1452. NSPR_API(PRInt32) PR_TransmitFile(
  1453. PRFileDesc *networkSocket, PRFileDesc *sourceFile,
  1454. const void *headers, PRInt32 hlen, PRTransmitFileFlags flags,
  1455. PRIntervalTime timeout);
  1456. /*
  1457. *************************************************************************
  1458. ** FUNCTION: PR_SendFile
  1459. ** DESCRIPTION:
  1460. ** PR_SendFile sends data from a file (sendData->fd) across a socket
  1461. ** (networkSocket). If specified, a header and/or trailer buffer are sent
  1462. ** before and after the file, respectively. The file offset, number of bytes
  1463. ** of file data to send, the header and trailer buffers are specified in the
  1464. ** sendData argument.
  1465. **
  1466. ** Optionally, if the PR_TRANSMITFILE_CLOSE_SOCKET flag is passed, the
  1467. ** socket is closed after successfully sending the data.
  1468. **
  1469. ** INPUTS:
  1470. ** PRFileDesc *networkSocket
  1471. ** The socket to send data over
  1472. ** PRSendFileData *sendData
  1473. ** Contains the FD, file offset and length, header and trailer
  1474. ** buffer specifications.
  1475. ** PRTransmitFileFlags flags
  1476. ** If the flags indicate that the connection should be closed,
  1477. ** it will be done immediately after transferring the file, unless
  1478. ** the operation is unsuccessful.
  1479. .* PRIntervalTime timeout
  1480. * Time limit for completion of the send operation.
  1481. **
  1482. ** RETURNS:
  1483. ** Returns the number of bytes written or -1 if the operation failed.
  1484. ** If an error occurs while sending the file, the PR_TRANSMITFILE_CLOSE_
  1485. ** SOCKET flag is ignored. The reason for the failure is obtained
  1486. ** by calling PR_GetError().
  1487. **************************************************************************
  1488. */
  1489. struct PRSendFileData {
  1490. PRFileDesc *fd; /* file to send */
  1491. PRUint32 file_offset; /* file offset */
  1492. PRSize file_nbytes; /* number of bytes of file data to send */
  1493. /* if 0, send data from file_offset to */
  1494. /* end-of-file. */
  1495. const void *header; /* header buffer */
  1496. PRInt32 hlen; /* header len */
  1497. const void *trailer; /* trailer buffer */
  1498. PRInt32 tlen; /* trailer len */
  1499. };
  1500. NSPR_API(PRInt32) PR_SendFile(
  1501. PRFileDesc *networkSocket, PRSendFileData *sendData,
  1502. PRTransmitFileFlags flags, PRIntervalTime timeout);
  1503. /*
  1504. *************************************************************************
  1505. ** FUNCTION: PR_AcceptRead
  1506. ** DESCRIPTION:
  1507. ** AcceptRead accepts a new connection, returns the newly created
  1508. ** socket's descriptor and also returns the connecting peer's address.
  1509. ** AcceptRead, as its name suggests, also receives the first block of data
  1510. ** sent by the peer.
  1511. **
  1512. ** INPUTS:
  1513. ** PRFileDesc *listenSock
  1514. ** A socket descriptor that has been called with the PR_Listen()
  1515. ** function, also known as the rendezvous socket.
  1516. ** void *buf
  1517. ** A pointer to a buffer to receive data sent by the client. This
  1518. ** buffer must be large enough to receive <amount> bytes of data
  1519. ** and two PRNetAddr structures, plus an extra 32 bytes. See:
  1520. ** PR_ACCEPT_READ_BUF_OVERHEAD.
  1521. ** PRInt32 amount
  1522. ** The number of bytes of client data to receive. Does not include
  1523. ** the size of the PRNetAddr structures. If 0, no data will be read
  1524. ** from the client.
  1525. ** PRIntervalTime timeout
  1526. ** The timeout interval only applies to the read portion of the
  1527. ** operation. PR_AcceptRead will block indefinitely until the
  1528. ** connection is accepted; the read will timeout after the timeout
  1529. ** interval elapses.
  1530. ** OUTPUTS:
  1531. ** PRFileDesc **acceptedSock
  1532. ** The file descriptor for the newly connected socket. This parameter
  1533. ** will only be valid if the function return does not indicate failure.
  1534. ** PRNetAddr **peerAddr,
  1535. ** The address of the remote socket. This parameter will only be
  1536. ** valid if the function return does not indicate failure. The
  1537. ** returned address is not guaranteed to be properly aligned.
  1538. **
  1539. ** RETURNS:
  1540. ** The number of bytes read from the client or -1 on failure. The reason
  1541. ** for the failure is obtained by calling PR_GetError().
  1542. **************************************************************************
  1543. **/
  1544. /* define buffer overhead constant. Add this value to the user's
  1545. ** data length when allocating a buffer to accept data.
  1546. ** Example:
  1547. ** #define USER_DATA_SIZE 10
  1548. ** char buf[USER_DATA_SIZE + PR_ACCEPT_READ_BUF_OVERHEAD];
  1549. ** bytesRead = PR_AcceptRead( s, fd, &a, &p, USER_DATA_SIZE, ...);
  1550. */
  1551. #define PR_ACCEPT_READ_BUF_OVERHEAD (32+(2*sizeof(PRNetAddr)))
  1552. NSPR_API(PRInt32) PR_AcceptRead(
  1553. PRFileDesc *listenSock, PRFileDesc **acceptedSock,
  1554. PRNetAddr **peerAddr, void *buf, PRInt32 amount, PRIntervalTime timeout);
  1555. /*
  1556. *************************************************************************
  1557. ** FUNCTION: PR_NewTCPSocketPair
  1558. ** DESCRIPTION:
  1559. ** Create a new TCP socket pair. The returned descriptors can be used
  1560. ** interchangeably; they are interconnected full-duplex descriptors: data
  1561. ** written to one can be read from the other and vice-versa.
  1562. **
  1563. ** INPUTS:
  1564. ** None
  1565. ** OUTPUTS:
  1566. ** PRFileDesc *fds[2]
  1567. ** The file descriptor pair for the newly created TCP sockets.
  1568. ** RETURN: PRStatus
  1569. ** Upon successful completion of TCP socket pair, PR_NewTCPSocketPair
  1570. ** returns PR_SUCCESS. Otherwise, it returns PR_FAILURE. Further
  1571. ** failure information can be obtained by calling PR_GetError().
  1572. ** XXX can we implement this on windoze and mac?
  1573. **************************************************************************
  1574. **/
  1575. NSPR_API(PRStatus) PR_NewTCPSocketPair(PRFileDesc *fds[2]);
  1576. /*
  1577. *************************************************************************
  1578. ** FUNCTION: PR_GetSockName
  1579. ** DESCRIPTION:
  1580. ** Get socket name. Return the network address for this socket.
  1581. **
  1582. ** INPUTS:
  1583. ** PRFileDesc *fd
  1584. ** Points to a PRFileDesc object representing the socket.
  1585. ** OUTPUTS:
  1586. ** PRNetAddr *addr
  1587. ** Returns the address of the socket in its own communication space.
  1588. ** RETURN: PRStatus
  1589. ** Upon successful completion, PR_GetSockName returns PR_SUCCESS.
  1590. ** Otherwise, it returns PR_FAILURE. Further failure information can
  1591. ** be obtained by calling PR_GetError().
  1592. **************************************************************************
  1593. **/
  1594. NSPR_API(PRStatus) PR_GetSockName(PRFileDesc *fd, PRNetAddr *addr);
  1595. /*
  1596. *************************************************************************
  1597. ** FUNCTION: PR_GetPeerName
  1598. ** DESCRIPTION:
  1599. ** Get name of the connected peer. Return the network address for the
  1600. ** connected peer socket.
  1601. **
  1602. ** INPUTS:
  1603. ** PRFileDesc *fd
  1604. ** Points to a PRFileDesc object representing the connected peer.
  1605. ** OUTPUTS:
  1606. ** PRNetAddr *addr
  1607. ** Returns the address of the connected peer in its own communication
  1608. ** space.
  1609. ** RETURN: PRStatus
  1610. ** Upon successful completion, PR_GetPeerName returns PR_SUCCESS.
  1611. ** Otherwise, it returns PR_FAILURE. Further failure information can
  1612. ** be obtained by calling PR_GetError().
  1613. **************************************************************************
  1614. **/
  1615. NSPR_API(PRStatus) PR_GetPeerName(PRFileDesc *fd, PRNetAddr *addr);
  1616. NSPR_API(PRStatus) PR_GetSocketOption(
  1617. PRFileDesc *fd, PRSocketOptionData *data);
  1618. NSPR_API(PRStatus) PR_SetSocketOption(
  1619. PRFileDesc *fd, const PRSocketOptionData *data);
  1620. /*
  1621. *********************************************************************
  1622. *
  1623. * File descriptor inheritance
  1624. *
  1625. *********************************************************************
  1626. */
  1627. /*
  1628. ************************************************************************
  1629. * FUNCTION: PR_SetFDInheritable
  1630. * DESCRIPTION:
  1631. * Set the inheritance attribute of a file descriptor.
  1632. *
  1633. * INPUTS:
  1634. * PRFileDesc *fd
  1635. * Points to a PRFileDesc object.
  1636. * PRBool inheritable
  1637. * If PR_TRUE, the file descriptor fd is set to be inheritable
  1638. * by a child process. If PR_FALSE, the file descriptor is set
  1639. * to be not inheritable by a child process.
  1640. * RETURN: PRStatus
  1641. * Upon successful completion, PR_SetFDInheritable returns PR_SUCCESS.
  1642. * Otherwise, it returns PR_FAILURE. Further failure information can
  1643. * be obtained by calling PR_GetError().
  1644. *************************************************************************
  1645. */
  1646. NSPR_API(PRStatus) PR_SetFDInheritable(
  1647. PRFileDesc *fd,
  1648. PRBool inheritable);
  1649. /*
  1650. ************************************************************************
  1651. * FUNCTION: PR_GetInheritedFD
  1652. * DESCRIPTION:
  1653. * Get an inherited file descriptor with the specified name.
  1654. *
  1655. * INPUTS:
  1656. * const char *name
  1657. * The name of the inherited file descriptor.
  1658. * RETURN: PRFileDesc *
  1659. * Upon successful completion, PR_GetInheritedFD returns the
  1660. * inherited file descriptor with the specified name. Otherwise,
  1661. * it returns NULL. Further failure information can be obtained
  1662. * by calling PR_GetError().
  1663. *************************************************************************
  1664. */
  1665. NSPR_API(PRFileDesc *) PR_GetInheritedFD(const char *name);
  1666. /*
  1667. *********************************************************************
  1668. *
  1669. * Memory-mapped files
  1670. *
  1671. *********************************************************************
  1672. */
  1673. typedef struct PRFileMap PRFileMap;
  1674. /*
  1675. * protection options for read and write accesses of a file mapping
  1676. */
  1677. typedef enum PRFileMapProtect {
  1678. PR_PROT_READONLY, /* read only */
  1679. PR_PROT_READWRITE, /* readable, and write is shared */
  1680. PR_PROT_WRITECOPY /* readable, and write is private (copy-on-write) */
  1681. } PRFileMapProtect;
  1682. NSPR_API(PRFileMap *) PR_CreateFileMap(
  1683. PRFileDesc *fd,
  1684. PRInt64 size,
  1685. PRFileMapProtect prot);
  1686. /*
  1687. * return the alignment (in bytes) of the offset argument to PR_MemMap
  1688. */
  1689. NSPR_API(PRInt32) PR_GetMemMapAlignment(void);
  1690. NSPR_API(void *) PR_MemMap(
  1691. PRFileMap *fmap,
  1692. PROffset64 offset, /* must be aligned and sized according to the
  1693. * return value of PR_GetMemMapAlignment() */
  1694. PRUint32 len);
  1695. NSPR_API(PRStatus) PR_MemUnmap(void *addr, PRUint32 len);
  1696. NSPR_API(PRStatus) PR_CloseFileMap(PRFileMap *fmap);
  1697. /*
  1698. * Synchronously flush the given memory-mapped address range of the given open
  1699. * file to disk. The function does not return until all modified data have
  1700. * been written to disk.
  1701. *
  1702. * On some platforms, the function will call PR_Sync(fd) internally if it is
  1703. * necessary for flushing modified data to disk synchronously.
  1704. */
  1705. NSPR_API(PRStatus) PR_SyncMemMap(
  1706. PRFileDesc *fd,
  1707. void *addr,
  1708. PRUint32 len);
  1709. /*
  1710. ******************************************************************
  1711. *
  1712. * Interprocess communication
  1713. *
  1714. ******************************************************************
  1715. */
  1716. /*
  1717. * Creates an anonymous pipe and returns file descriptors for the
  1718. * read and write ends of the pipe.
  1719. */
  1720. NSPR_API(PRStatus) PR_CreatePipe(
  1721. PRFileDesc **readPipe,
  1722. PRFileDesc **writePipe
  1723. );
  1724. /************************************************************************/
  1725. /************** The following definitions are for poll ******************/
  1726. /************************************************************************/
  1727. struct PRPollDesc {
  1728. PRFileDesc* fd;
  1729. PRInt16 in_flags;
  1730. PRInt16 out_flags;
  1731. };
  1732. /*
  1733. ** Bit values for PRPollDesc.in_flags or PRPollDesc.out_flags. Binary-or
  1734. ** these together to produce the desired poll request.
  1735. */
  1736. #if defined(_PR_POLL_BACKCOMPAT)
  1737. #include <poll.h>
  1738. #define PR_POLL_READ POLLIN
  1739. #define PR_POLL_WRITE POLLOUT
  1740. #define PR_POLL_EXCEPT POLLPRI
  1741. #define PR_POLL_ERR POLLERR /* only in out_flags */
  1742. #define PR_POLL_NVAL POLLNVAL /* only in out_flags when fd is bad */
  1743. #define PR_POLL_HUP POLLHUP /* only in out_flags */
  1744. #else /* _PR_POLL_BACKCOMPAT */
  1745. #define PR_POLL_READ 0x1
  1746. #define PR_POLL_WRITE 0x2
  1747. #define PR_POLL_EXCEPT 0x4
  1748. #define PR_POLL_ERR 0x8 /* only in out_flags */
  1749. #define PR_POLL_NVAL 0x10 /* only in out_flags when fd is bad */
  1750. #define PR_POLL_HUP 0x20 /* only in out_flags */
  1751. #endif /* _PR_POLL_BACKCOMPAT */
  1752. /*
  1753. *************************************************************************
  1754. ** FUNCTION: PR_Poll
  1755. ** DESCRIPTION:
  1756. **
  1757. ** The call returns as soon as I/O is ready on one or more of the underlying
  1758. ** socket objects. A count of the number of ready descriptors is
  1759. ** returned unless a timeout occurs in which case zero is returned.
  1760. **
  1761. ** PRPollDesc.fd should be set to a pointer to a PRFileDesc object
  1762. ** representing a socket. This field can be set to NULL to indicate to
  1763. ** PR_Poll that this PRFileDesc object should be ignored.
  1764. ** PRPollDesc.in_flags should be set to the desired request
  1765. ** (read/write/except or some combination). Upon successful return from
  1766. ** this call PRPollDesc.out_flags will be set to indicate what kind of
  1767. ** i/o can be performed on the respective descriptor. PR_Poll() uses the
  1768. ** out_flags fields as scratch variables during the call. If PR_Poll()
  1769. ** returns 0 or -1, the out_flags fields do not contain meaningful values
  1770. ** and must not be used.
  1771. **
  1772. ** INPUTS:
  1773. ** PRPollDesc *pds A pointer to an array of PRPollDesc
  1774. **
  1775. ** PRIntn npds The number of elements in the array
  1776. ** If this argument is zero PR_Poll is
  1777. ** equivalent to a PR_Sleep(timeout).
  1778. **
  1779. ** PRIntervalTime timeout Amount of time the call will block waiting
  1780. ** for I/O to become ready. If this time expires
  1781. ** w/o any I/O becoming ready, the result will
  1782. ** be zero.
  1783. **
  1784. ** OUTPUTS: None
  1785. ** RETURN:
  1786. ** PRInt32 Number of PRPollDesc's with events or zero
  1787. ** if the function timed out or -1 on failure.
  1788. ** The reason for the failure is obtained by
  1789. ** calling PR_GetError().
  1790. **************************************************************************
  1791. */
  1792. NSPR_API(PRInt32) PR_Poll(
  1793. PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout);
  1794. /*
  1795. **************************************************************************
  1796. **
  1797. ** Pollable events
  1798. **
  1799. ** A pollable event is a special kind of file descriptor.
  1800. ** The only I/O operation you can perform on a pollable event
  1801. ** is to poll it with the PR_POLL_READ flag. You can't
  1802. ** read from or write to a pollable event.
  1803. **
  1804. ** The purpose of a pollable event is to combine event waiting
  1805. ** with I/O waiting in a single PR_Poll call. Pollable events
  1806. ** are implemented using a pipe or a pair of TCP sockets
  1807. ** connected via the loopback address, therefore setting and
  1808. ** waiting for pollable events are expensive operating system
  1809. ** calls. Do not use pollable events for general thread
  1810. ** synchronization. Use condition variables instead.
  1811. **
  1812. ** A pollable event has two states: set and unset. Events
  1813. ** are not queued, so there is no notion of an event count.
  1814. ** A pollable event is either set or unset.
  1815. **
  1816. ** A new pollable event is created by a PR_NewPollableEvent
  1817. ** call and is initially in the unset state.
  1818. **
  1819. ** PR_WaitForPollableEvent blocks the calling thread until
  1820. ** the pollable event is set, and then it atomically unsets
  1821. ** the pollable event before it returns.
  1822. **
  1823. ** To set a pollable event, call PR_SetPollableEvent.
  1824. **
  1825. ** One can call PR_Poll with the PR_POLL_READ flag on a pollable
  1826. ** event. When the pollable event is set, PR_Poll returns with
  1827. ** the PR_POLL_READ flag set in the out_flags.
  1828. **
  1829. ** To close a pollable event, call PR_DestroyPollableEvent
  1830. ** (not PR_Close).
  1831. **
  1832. **************************************************************************
  1833. */
  1834. NSPR_API(PRFileDesc *) PR_NewPollableEvent(void);
  1835. NSPR_API(PRStatus) PR_DestroyPollableEvent(PRFileDesc *event);
  1836. NSPR_API(PRStatus) PR_SetPollableEvent(PRFileDesc *event);
  1837. NSPR_API(PRStatus) PR_WaitForPollableEvent(PRFileDesc *event);
  1838. PR_END_EXTERN_C
  1839. #endif /* prio_h___ */