pprio.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is the Netscape Portable Runtime (NSPR).
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communications Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1998-2000
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. /*
  38. ** File: pprio.h
  39. **
  40. ** Description: Private definitions for I/O related structures
  41. */
  42. #ifndef pprio_h___
  43. #define pprio_h___
  44. #include "prtypes.h"
  45. #include "prio.h"
  46. PR_BEGIN_EXTERN_C
  47. /************************************************************************/
  48. /************************************************************************/
  49. /* Return the method tables for files, tcp sockets and udp sockets */
  50. NSPR_API(const PRIOMethods*) PR_GetFileMethods(void);
  51. NSPR_API(const PRIOMethods*) PR_GetTCPMethods(void);
  52. NSPR_API(const PRIOMethods*) PR_GetUDPMethods(void);
  53. NSPR_API(const PRIOMethods*) PR_GetPipeMethods(void);
  54. /*
  55. ** Convert a NSPR Socket Handle to a Native Socket handle.
  56. ** This function will be obsoleted with the next release; avoid using it.
  57. */
  58. NSPR_API(PRInt32) PR_FileDesc2NativeHandle(PRFileDesc *);
  59. NSPR_API(void) PR_ChangeFileDescNativeHandle(PRFileDesc *, PRInt32);
  60. NSPR_API(PRFileDesc*) PR_AllocFileDesc(PRInt32 osfd,
  61. const PRIOMethods *methods);
  62. NSPR_API(void) PR_FreeFileDesc(PRFileDesc *fd);
  63. /*
  64. ** Import an existing OS file to NSPR.
  65. */
  66. NSPR_API(PRFileDesc*) PR_ImportFile(PRInt32 osfd);
  67. NSPR_API(PRFileDesc*) PR_ImportPipe(PRInt32 osfd);
  68. NSPR_API(PRFileDesc*) PR_ImportTCPSocket(PRInt32 osfd);
  69. NSPR_API(PRFileDesc*) PR_ImportUDPSocket(PRInt32 osfd);
  70. /*
  71. *************************************************************************
  72. * FUNCTION: PR_CreateSocketPollFd
  73. * DESCRIPTION:
  74. * Create a PRFileDesc wrapper for a native socket handle, for use with
  75. * PR_Poll only
  76. * INPUTS:
  77. * None
  78. * OUTPUTS:
  79. * None
  80. * RETURN: PRFileDesc*
  81. * Upon successful completion, PR_CreateSocketPollFd returns a pointer
  82. * to the PRFileDesc created for the native socket handle
  83. * Returns a NULL pointer if the create of a new PRFileDesc failed
  84. *
  85. **************************************************************************
  86. */
  87. NSPR_API(PRFileDesc*) PR_CreateSocketPollFd(PRInt32 osfd);
  88. /*
  89. *************************************************************************
  90. * FUNCTION: PR_DestroySocketPollFd
  91. * DESCRIPTION:
  92. * Destroy the PRFileDesc wrapper created by PR_CreateSocketPollFd
  93. * INPUTS:
  94. * None
  95. * OUTPUTS:
  96. * None
  97. * RETURN: PRFileDesc*
  98. * Upon successful completion, PR_DestroySocketPollFd returns
  99. * PR_SUCCESS, else PR_FAILURE
  100. *
  101. **************************************************************************
  102. */
  103. NSPR_API(PRStatus) PR_DestroySocketPollFd(PRFileDesc *fd);
  104. /*
  105. ** Macros for PR_Socket
  106. **
  107. ** Socket types: PR_SOCK_STREAM, PR_SOCK_DGRAM
  108. */
  109. #ifdef WIN32
  110. #define PR_SOCK_STREAM 1
  111. #define PR_SOCK_DGRAM 2
  112. #else /* WIN32 */
  113. #define PR_SOCK_STREAM SOCK_STREAM
  114. #define PR_SOCK_DGRAM SOCK_DGRAM
  115. #endif /* WIN32 */
  116. /*
  117. ** Create a new Socket; this function is obsolete.
  118. */
  119. NSPR_API(PRFileDesc*) PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto);
  120. /* FUNCTION: PR_LockFile
  121. ** DESCRIPTION:
  122. ** Lock a file for exclusive access.
  123. ** RETURNS:
  124. ** PR_SUCCESS when the lock is held
  125. ** PR_FAILURE otherwise
  126. */
  127. NSPR_API(PRStatus) PR_LockFile(PRFileDesc *fd);
  128. /* FUNCTION: PR_TLockFile
  129. ** DESCRIPTION:
  130. ** Test and Lock a file for exclusive access. Do not block if the
  131. ** file cannot be locked immediately.
  132. ** RETURNS:
  133. ** PR_SUCCESS when the lock is held
  134. ** PR_FAILURE otherwise
  135. */
  136. NSPR_API(PRStatus) PR_TLockFile(PRFileDesc *fd);
  137. /* FUNCTION: PR_UnlockFile
  138. ** DESCRIPTION:
  139. ** Unlock a file which has been previously locked successfully by this
  140. ** process.
  141. ** RETURNS:
  142. ** PR_SUCCESS when the lock is released
  143. ** PR_FAILURE otherwise
  144. */
  145. NSPR_API(PRStatus) PR_UnlockFile(PRFileDesc *fd);
  146. /*
  147. ** Emulate acceptread by accept and recv.
  148. */
  149. NSPR_API(PRInt32) PR_EmulateAcceptRead(PRFileDesc *sd, PRFileDesc **nd,
  150. PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime timeout);
  151. /*
  152. ** Emulate sendfile by reading from the file and writing to the socket.
  153. ** The file is memory-mapped if memory-mapped files are supported.
  154. */
  155. NSPR_API(PRInt32) PR_EmulateSendFile(
  156. PRFileDesc *networkSocket, PRSendFileData *sendData,
  157. PRTransmitFileFlags flags, PRIntervalTime timeout);
  158. #ifdef WIN32
  159. /* FUNCTION: PR_NTFast_AcceptRead
  160. ** DESCRIPTION:
  161. ** NT has the notion of an "accept context", which is only needed in
  162. ** order to make certain calls. By default, a socket connected via
  163. ** AcceptEx can only do a limited number of things without updating
  164. ** the acceptcontext. The generic version of PR_AcceptRead always
  165. ** updates the accept context. This version does not.
  166. **/
  167. NSPR_API(PRInt32) PR_NTFast_AcceptRead(PRFileDesc *sd, PRFileDesc **nd,
  168. PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime t);
  169. typedef void (*_PR_AcceptTimeoutCallback)(void *);
  170. /* FUNCTION: PR_NTFast_AcceptRead_WithTimeoutCallback
  171. ** DESCRIPTION:
  172. ** The AcceptEx call combines the accept with the read function. However,
  173. ** our daemon threads need to be able to wakeup and reliably flush their
  174. ** log buffers if the Accept times out. However, with the current blocking
  175. ** interface to AcceptRead, there is no way for us to timeout the Accept;
  176. ** this is because when we timeout the Read, we can close the newly
  177. ** socket and continue; but when we timeout the accept itself, there is no
  178. ** new socket to timeout. So instead, this version of the function is
  179. ** provided. After the initial timeout period elapses on the accept()
  180. ** portion of the function, it will call the callback routine and then
  181. ** continue the accept. If the timeout occurs on the read, it will
  182. ** close the connection and return error.
  183. */
  184. NSPR_API(PRInt32) PR_NTFast_AcceptRead_WithTimeoutCallback(
  185. PRFileDesc *sd,
  186. PRFileDesc **nd,
  187. PRNetAddr **raddr,
  188. void *buf,
  189. PRInt32 amount,
  190. PRIntervalTime t,
  191. _PR_AcceptTimeoutCallback callback,
  192. void *callback_arg);
  193. /* FUNCTION: PR_NTFast_Accept
  194. ** DESCRIPTION:
  195. ** NT has the notion of an "accept context", which is only needed in
  196. ** order to make certain calls. By default, a socket connected via
  197. ** AcceptEx can only do a limited number of things without updating
  198. ** the acceptcontext. The generic version of PR_Accept always
  199. ** updates the accept context. This version does not.
  200. **/
  201. NSPR_API(PRFileDesc*) PR_NTFast_Accept(PRFileDesc *fd, PRNetAddr *addr,
  202. PRIntervalTime timeout);
  203. /* FUNCTION: PR_NTFast_Update
  204. ** DESCRIPTION:
  205. ** For sockets accepted with PR_NTFast_Accept or PR_NTFastAcceptRead,
  206. ** this function will update the accept context for those sockets,
  207. ** so that the socket can make general purpose socket calls.
  208. ** Without calling this, the only operations supported on the socket
  209. ** Are PR_Read, PR_Write, PR_Transmitfile, and PR_Close.
  210. */
  211. NSPR_API(void) PR_NTFast_UpdateAcceptContext(PRFileDesc *acceptSock,
  212. PRFileDesc *listenSock);
  213. /* FUNCTION: PR_NT_CancelIo
  214. ** DESCRIPTION:
  215. ** Cancel IO operations on fd.
  216. */
  217. NSPR_API(PRStatus) PR_NT_CancelIo(PRFileDesc *fd);
  218. #endif /* WIN32 */
  219. /*
  220. ** Need external access to this on Mac so we can first set up our faux
  221. ** environment vars
  222. */
  223. #ifdef XP_MAC
  224. NSPR_API(void) PR_Init_Log(void);
  225. #endif
  226. PR_END_EXTERN_C
  227. #endif /* pprio_h___ */