michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: ** File: pprio.h michael@0: ** michael@0: ** Description: Private definitions for I/O related structures michael@0: */ michael@0: michael@0: #ifndef pprio_h___ michael@0: #define pprio_h___ michael@0: michael@0: #include "prtypes.h" michael@0: #include "prio.h" michael@0: michael@0: PR_BEGIN_EXTERN_C michael@0: michael@0: /************************************************************************/ michael@0: /************************************************************************/ michael@0: michael@0: #ifdef _WIN64 michael@0: typedef __int64 PROsfd; michael@0: #else michael@0: typedef PRInt32 PROsfd; michael@0: #endif michael@0: michael@0: /* Return the method tables for files, tcp sockets and udp sockets */ michael@0: NSPR_API(const PRIOMethods*) PR_GetFileMethods(void); michael@0: NSPR_API(const PRIOMethods*) PR_GetTCPMethods(void); michael@0: NSPR_API(const PRIOMethods*) PR_GetUDPMethods(void); michael@0: NSPR_API(const PRIOMethods*) PR_GetPipeMethods(void); michael@0: michael@0: /* michael@0: ** Convert a NSPR socket handle to a native socket handle. michael@0: ** michael@0: ** Using this function makes your code depend on the properties of the michael@0: ** current NSPR implementation, which may change (although extremely michael@0: ** unlikely because of NSPR's backward compatibility requirement). Avoid michael@0: ** using it if you can. michael@0: ** michael@0: ** If you use this function, you need to understand what NSPR does to michael@0: ** the native handle. For example, NSPR puts native socket handles in michael@0: ** non-blocking mode or associates them with an I/O completion port (the michael@0: ** WINNT build configuration only). Your use of the native handle should michael@0: ** not interfere with NSPR's use of the native handle. If your code michael@0: ** changes the configuration of the native handle, (e.g., changes it to michael@0: ** blocking or closes it), NSPR will not work correctly. michael@0: */ michael@0: NSPR_API(PROsfd) PR_FileDesc2NativeHandle(PRFileDesc *); michael@0: NSPR_API(void) PR_ChangeFileDescNativeHandle(PRFileDesc *, PROsfd); michael@0: NSPR_API(PRFileDesc*) PR_AllocFileDesc(PROsfd osfd, michael@0: const PRIOMethods *methods); michael@0: NSPR_API(void) PR_FreeFileDesc(PRFileDesc *fd); michael@0: /* michael@0: ** Import an existing OS file to NSPR. michael@0: */ michael@0: NSPR_API(PRFileDesc*) PR_ImportFile(PROsfd osfd); michael@0: NSPR_API(PRFileDesc*) PR_ImportPipe(PROsfd osfd); michael@0: NSPR_API(PRFileDesc*) PR_ImportTCPSocket(PROsfd osfd); michael@0: NSPR_API(PRFileDesc*) PR_ImportUDPSocket(PROsfd osfd); michael@0: michael@0: michael@0: /* michael@0: ************************************************************************* michael@0: * FUNCTION: PR_CreateSocketPollFd michael@0: * DESCRIPTION: michael@0: * Create a PRFileDesc wrapper for a native socket handle, for use with michael@0: * PR_Poll only michael@0: * INPUTS: michael@0: * None michael@0: * OUTPUTS: michael@0: * None michael@0: * RETURN: PRFileDesc* michael@0: * Upon successful completion, PR_CreateSocketPollFd returns a pointer michael@0: * to the PRFileDesc created for the native socket handle michael@0: * Returns a NULL pointer if the create of a new PRFileDesc failed michael@0: * michael@0: ************************************************************************** michael@0: */ michael@0: michael@0: NSPR_API(PRFileDesc*) PR_CreateSocketPollFd(PROsfd osfd); michael@0: michael@0: /* michael@0: ************************************************************************* michael@0: * FUNCTION: PR_DestroySocketPollFd michael@0: * DESCRIPTION: michael@0: * Destroy the PRFileDesc wrapper created by PR_CreateSocketPollFd michael@0: * INPUTS: michael@0: * None michael@0: * OUTPUTS: michael@0: * None michael@0: * RETURN: PRFileDesc* michael@0: * Upon successful completion, PR_DestroySocketPollFd returns michael@0: * PR_SUCCESS, else PR_FAILURE michael@0: * michael@0: ************************************************************************** michael@0: */ michael@0: michael@0: NSPR_API(PRStatus) PR_DestroySocketPollFd(PRFileDesc *fd); michael@0: michael@0: michael@0: /* michael@0: ** Macros for PR_Socket michael@0: ** michael@0: ** Socket types: PR_SOCK_STREAM, PR_SOCK_DGRAM michael@0: */ michael@0: michael@0: #ifdef WIN32 michael@0: michael@0: #define PR_SOCK_STREAM 1 michael@0: #define PR_SOCK_DGRAM 2 michael@0: michael@0: #else /* WIN32 */ michael@0: michael@0: #define PR_SOCK_STREAM SOCK_STREAM michael@0: #define PR_SOCK_DGRAM SOCK_DGRAM michael@0: michael@0: #endif /* WIN32 */ michael@0: michael@0: /* michael@0: ** Create a new Socket; this function is obsolete. michael@0: */ michael@0: NSPR_API(PRFileDesc*) PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto); michael@0: michael@0: /* FUNCTION: PR_LockFile michael@0: ** DESCRIPTION: michael@0: ** Lock a file for exclusive access. michael@0: ** RETURNS: michael@0: ** PR_SUCCESS when the lock is held michael@0: ** PR_FAILURE otherwise michael@0: */ michael@0: NSPR_API(PRStatus) PR_LockFile(PRFileDesc *fd); michael@0: michael@0: /* FUNCTION: PR_TLockFile michael@0: ** DESCRIPTION: michael@0: ** Test and Lock a file for exclusive access. Do not block if the michael@0: ** file cannot be locked immediately. michael@0: ** RETURNS: michael@0: ** PR_SUCCESS when the lock is held michael@0: ** PR_FAILURE otherwise michael@0: */ michael@0: NSPR_API(PRStatus) PR_TLockFile(PRFileDesc *fd); michael@0: michael@0: /* FUNCTION: PR_UnlockFile michael@0: ** DESCRIPTION: michael@0: ** Unlock a file which has been previously locked successfully by this michael@0: ** process. michael@0: ** RETURNS: michael@0: ** PR_SUCCESS when the lock is released michael@0: ** PR_FAILURE otherwise michael@0: */ michael@0: NSPR_API(PRStatus) PR_UnlockFile(PRFileDesc *fd); michael@0: michael@0: /* michael@0: ** Emulate acceptread by accept and recv. michael@0: */ michael@0: NSPR_API(PRInt32) PR_EmulateAcceptRead(PRFileDesc *sd, PRFileDesc **nd, michael@0: PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime timeout); michael@0: michael@0: /* michael@0: ** Emulate sendfile by reading from the file and writing to the socket. michael@0: ** The file is memory-mapped if memory-mapped files are supported. michael@0: */ michael@0: NSPR_API(PRInt32) PR_EmulateSendFile( michael@0: PRFileDesc *networkSocket, PRSendFileData *sendData, michael@0: PRTransmitFileFlags flags, PRIntervalTime timeout); michael@0: michael@0: #ifdef WIN32 michael@0: /* FUNCTION: PR_NTFast_AcceptRead michael@0: ** DESCRIPTION: michael@0: ** NT has the notion of an "accept context", which is only needed in michael@0: ** order to make certain calls. By default, a socket connected via michael@0: ** AcceptEx can only do a limited number of things without updating michael@0: ** the acceptcontext. The generic version of PR_AcceptRead always michael@0: ** updates the accept context. This version does not. michael@0: **/ michael@0: NSPR_API(PRInt32) PR_NTFast_AcceptRead(PRFileDesc *sd, PRFileDesc **nd, michael@0: PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime t); michael@0: michael@0: typedef void (*_PR_AcceptTimeoutCallback)(void *); michael@0: michael@0: /* FUNCTION: PR_NTFast_AcceptRead_WithTimeoutCallback michael@0: ** DESCRIPTION: michael@0: ** The AcceptEx call combines the accept with the read function. However, michael@0: ** our daemon threads need to be able to wakeup and reliably flush their michael@0: ** log buffers if the Accept times out. However, with the current blocking michael@0: ** interface to AcceptRead, there is no way for us to timeout the Accept; michael@0: ** this is because when we timeout the Read, we can close the newly michael@0: ** socket and continue; but when we timeout the accept itself, there is no michael@0: ** new socket to timeout. So instead, this version of the function is michael@0: ** provided. After the initial timeout period elapses on the accept() michael@0: ** portion of the function, it will call the callback routine and then michael@0: ** continue the accept. If the timeout occurs on the read, it will michael@0: ** close the connection and return error. michael@0: */ michael@0: NSPR_API(PRInt32) PR_NTFast_AcceptRead_WithTimeoutCallback( michael@0: PRFileDesc *sd, michael@0: PRFileDesc **nd, michael@0: PRNetAddr **raddr, michael@0: void *buf, michael@0: PRInt32 amount, michael@0: PRIntervalTime t, michael@0: _PR_AcceptTimeoutCallback callback, michael@0: void *callback_arg); michael@0: michael@0: /* FUNCTION: PR_NTFast_Accept michael@0: ** DESCRIPTION: michael@0: ** NT has the notion of an "accept context", which is only needed in michael@0: ** order to make certain calls. By default, a socket connected via michael@0: ** AcceptEx can only do a limited number of things without updating michael@0: ** the acceptcontext. The generic version of PR_Accept always michael@0: ** updates the accept context. This version does not. michael@0: **/ michael@0: NSPR_API(PRFileDesc*) PR_NTFast_Accept(PRFileDesc *fd, PRNetAddr *addr, michael@0: PRIntervalTime timeout); michael@0: michael@0: /* FUNCTION: PR_NTFast_Update michael@0: ** DESCRIPTION: michael@0: ** For sockets accepted with PR_NTFast_Accept or PR_NTFastAcceptRead, michael@0: ** this function will update the accept context for those sockets, michael@0: ** so that the socket can make general purpose socket calls. michael@0: ** Without calling this, the only operations supported on the socket michael@0: ** Are PR_Read, PR_Write, PR_Transmitfile, and PR_Close. michael@0: */ michael@0: NSPR_API(void) PR_NTFast_UpdateAcceptContext(PRFileDesc *acceptSock, michael@0: PRFileDesc *listenSock); michael@0: michael@0: michael@0: /* FUNCTION: PR_NT_CancelIo michael@0: ** DESCRIPTION: michael@0: ** Cancel IO operations on fd. michael@0: */ michael@0: NSPR_API(PRStatus) PR_NT_CancelIo(PRFileDesc *fd); michael@0: michael@0: michael@0: #endif /* WIN32 */ michael@0: michael@0: PR_END_EXTERN_C michael@0: michael@0: #endif /* pprio_h___ */