prio.h 76 KB

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