prio.h 76 KB

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