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