PageRenderTime 25ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/gecko_api/include/private/pprio.h

http://firefox-mac-pdf.googlecode.com/
C Header | 271 lines | 65 code | 39 blank | 167 comment | 0 complexity | c838f89daec93b05037ed50bec755b0c MD5 | raw file
  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. #ifdef _WIN64
  50. typedef __int64 PROsfd;
  51. #else
  52. typedef PRInt32 PROsfd;
  53. #endif
  54. /* Return the method tables for files, tcp sockets and udp sockets */
  55. NSPR_API(const PRIOMethods*) PR_GetFileMethods(void);
  56. NSPR_API(const PRIOMethods*) PR_GetTCPMethods(void);
  57. NSPR_API(const PRIOMethods*) PR_GetUDPMethods(void);
  58. NSPR_API(const PRIOMethods*) PR_GetPipeMethods(void);
  59. /*
  60. ** Convert a NSPR Socket Handle to a Native Socket handle.
  61. ** This function will be obsoleted with the next release; avoid using it.
  62. */
  63. NSPR_API(PROsfd) PR_FileDesc2NativeHandle(PRFileDesc *);
  64. NSPR_API(void) PR_ChangeFileDescNativeHandle(PRFileDesc *, PROsfd);
  65. NSPR_API(PRFileDesc*) PR_AllocFileDesc(PROsfd osfd,
  66. const PRIOMethods *methods);
  67. NSPR_API(void) PR_FreeFileDesc(PRFileDesc *fd);
  68. /*
  69. ** Import an existing OS file to NSPR.
  70. */
  71. NSPR_API(PRFileDesc*) PR_ImportFile(PROsfd osfd);
  72. NSPR_API(PRFileDesc*) PR_ImportPipe(PROsfd osfd);
  73. NSPR_API(PRFileDesc*) PR_ImportTCPSocket(PROsfd osfd);
  74. NSPR_API(PRFileDesc*) PR_ImportUDPSocket(PROsfd osfd);
  75. /*
  76. *************************************************************************
  77. * FUNCTION: PR_CreateSocketPollFd
  78. * DESCRIPTION:
  79. * Create a PRFileDesc wrapper for a native socket handle, for use with
  80. * PR_Poll only
  81. * INPUTS:
  82. * None
  83. * OUTPUTS:
  84. * None
  85. * RETURN: PRFileDesc*
  86. * Upon successful completion, PR_CreateSocketPollFd returns a pointer
  87. * to the PRFileDesc created for the native socket handle
  88. * Returns a NULL pointer if the create of a new PRFileDesc failed
  89. *
  90. **************************************************************************
  91. */
  92. NSPR_API(PRFileDesc*) PR_CreateSocketPollFd(PROsfd osfd);
  93. /*
  94. *************************************************************************
  95. * FUNCTION: PR_DestroySocketPollFd
  96. * DESCRIPTION:
  97. * Destroy the PRFileDesc wrapper created by PR_CreateSocketPollFd
  98. * INPUTS:
  99. * None
  100. * OUTPUTS:
  101. * None
  102. * RETURN: PRFileDesc*
  103. * Upon successful completion, PR_DestroySocketPollFd returns
  104. * PR_SUCCESS, else PR_FAILURE
  105. *
  106. **************************************************************************
  107. */
  108. NSPR_API(PRStatus) PR_DestroySocketPollFd(PRFileDesc *fd);
  109. /*
  110. ** Macros for PR_Socket
  111. **
  112. ** Socket types: PR_SOCK_STREAM, PR_SOCK_DGRAM
  113. */
  114. #ifdef WIN32
  115. #define PR_SOCK_STREAM 1
  116. #define PR_SOCK_DGRAM 2
  117. #else /* WIN32 */
  118. #define PR_SOCK_STREAM SOCK_STREAM
  119. #define PR_SOCK_DGRAM SOCK_DGRAM
  120. #endif /* WIN32 */
  121. /*
  122. ** Create a new Socket; this function is obsolete.
  123. */
  124. NSPR_API(PRFileDesc*) PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto);
  125. /* FUNCTION: PR_LockFile
  126. ** DESCRIPTION:
  127. ** Lock a file for exclusive access.
  128. ** RETURNS:
  129. ** PR_SUCCESS when the lock is held
  130. ** PR_FAILURE otherwise
  131. */
  132. NSPR_API(PRStatus) PR_LockFile(PRFileDesc *fd);
  133. /* FUNCTION: PR_TLockFile
  134. ** DESCRIPTION:
  135. ** Test and Lock a file for exclusive access. Do not block if the
  136. ** file cannot be locked immediately.
  137. ** RETURNS:
  138. ** PR_SUCCESS when the lock is held
  139. ** PR_FAILURE otherwise
  140. */
  141. NSPR_API(PRStatus) PR_TLockFile(PRFileDesc *fd);
  142. /* FUNCTION: PR_UnlockFile
  143. ** DESCRIPTION:
  144. ** Unlock a file which has been previously locked successfully by this
  145. ** process.
  146. ** RETURNS:
  147. ** PR_SUCCESS when the lock is released
  148. ** PR_FAILURE otherwise
  149. */
  150. NSPR_API(PRStatus) PR_UnlockFile(PRFileDesc *fd);
  151. /*
  152. ** Emulate acceptread by accept and recv.
  153. */
  154. NSPR_API(PRInt32) PR_EmulateAcceptRead(PRFileDesc *sd, PRFileDesc **nd,
  155. PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime timeout);
  156. /*
  157. ** Emulate sendfile by reading from the file and writing to the socket.
  158. ** The file is memory-mapped if memory-mapped files are supported.
  159. */
  160. NSPR_API(PRInt32) PR_EmulateSendFile(
  161. PRFileDesc *networkSocket, PRSendFileData *sendData,
  162. PRTransmitFileFlags flags, PRIntervalTime timeout);
  163. #ifdef WIN32
  164. /* FUNCTION: PR_NTFast_AcceptRead
  165. ** DESCRIPTION:
  166. ** NT has the notion of an "accept context", which is only needed in
  167. ** order to make certain calls. By default, a socket connected via
  168. ** AcceptEx can only do a limited number of things without updating
  169. ** the acceptcontext. The generic version of PR_AcceptRead always
  170. ** updates the accept context. This version does not.
  171. **/
  172. NSPR_API(PRInt32) PR_NTFast_AcceptRead(PRFileDesc *sd, PRFileDesc **nd,
  173. PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime t);
  174. typedef void (*_PR_AcceptTimeoutCallback)(void *);
  175. /* FUNCTION: PR_NTFast_AcceptRead_WithTimeoutCallback
  176. ** DESCRIPTION:
  177. ** The AcceptEx call combines the accept with the read function. However,
  178. ** our daemon threads need to be able to wakeup and reliably flush their
  179. ** log buffers if the Accept times out. However, with the current blocking
  180. ** interface to AcceptRead, there is no way for us to timeout the Accept;
  181. ** this is because when we timeout the Read, we can close the newly
  182. ** socket and continue; but when we timeout the accept itself, there is no
  183. ** new socket to timeout. So instead, this version of the function is
  184. ** provided. After the initial timeout period elapses on the accept()
  185. ** portion of the function, it will call the callback routine and then
  186. ** continue the accept. If the timeout occurs on the read, it will
  187. ** close the connection and return error.
  188. */
  189. NSPR_API(PRInt32) PR_NTFast_AcceptRead_WithTimeoutCallback(
  190. PRFileDesc *sd,
  191. PRFileDesc **nd,
  192. PRNetAddr **raddr,
  193. void *buf,
  194. PRInt32 amount,
  195. PRIntervalTime t,
  196. _PR_AcceptTimeoutCallback callback,
  197. void *callback_arg);
  198. /* FUNCTION: PR_NTFast_Accept
  199. ** DESCRIPTION:
  200. ** NT has the notion of an "accept context", which is only needed in
  201. ** order to make certain calls. By default, a socket connected via
  202. ** AcceptEx can only do a limited number of things without updating
  203. ** the acceptcontext. The generic version of PR_Accept always
  204. ** updates the accept context. This version does not.
  205. **/
  206. NSPR_API(PRFileDesc*) PR_NTFast_Accept(PRFileDesc *fd, PRNetAddr *addr,
  207. PRIntervalTime timeout);
  208. /* FUNCTION: PR_NTFast_Update
  209. ** DESCRIPTION:
  210. ** For sockets accepted with PR_NTFast_Accept or PR_NTFastAcceptRead,
  211. ** this function will update the accept context for those sockets,
  212. ** so that the socket can make general purpose socket calls.
  213. ** Without calling this, the only operations supported on the socket
  214. ** Are PR_Read, PR_Write, PR_Transmitfile, and PR_Close.
  215. */
  216. NSPR_API(void) PR_NTFast_UpdateAcceptContext(PRFileDesc *acceptSock,
  217. PRFileDesc *listenSock);
  218. /* FUNCTION: PR_NT_CancelIo
  219. ** DESCRIPTION:
  220. ** Cancel IO operations on fd.
  221. */
  222. NSPR_API(PRStatus) PR_NT_CancelIo(PRFileDesc *fd);
  223. #endif /* WIN32 */
  224. /*
  225. ** Need external access to this on Mac so we can first set up our faux
  226. ** environment vars
  227. */
  228. #ifdef XP_MAC
  229. NSPR_API(void) PR_Init_Log(void);
  230. #endif
  231. PR_END_EXTERN_C
  232. #endif /* pprio_h___ */