/security/manager/ssl/src/nsSSLThread.h

http://github.com/zpao/v8monkey · C Header · 158 lines · 52 code · 28 blank · 78 comment · 0 complexity · 6f864297fefc9e609d94f36d7171780a MD5 · raw file

  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3. *
  4. * The contents of this file are subject to the Mozilla Public License Version
  5. * 1.1 (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. * http://www.mozilla.org/MPL/
  8. *
  9. * Software distributed under the License is distributed on an "AS IS" basis,
  10. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. * for the specific language governing rights and limitations under the
  12. * License.
  13. *
  14. * The Original Code is mozilla.org code.
  15. *
  16. * The Initial Developer of the Original Code is
  17. * Red Hat, Inc.
  18. * Portions created by the Initial Developer are Copyright (C) 2006
  19. * the Initial Developer. All Rights Reserved.
  20. *
  21. * Contributor(s):
  22. * Kai Engert <kengert@redhat.com>
  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. #ifndef _NSSSLTHREAD_H_
  38. #define _NSSSLTHREAD_H_
  39. #include "nsCOMPtr.h"
  40. #include "nsIRequest.h"
  41. #include "nsPSMBackgroundThread.h"
  42. class nsNSSSocketInfo;
  43. class nsIHttpChannel;
  44. class nsSSLThread : public nsPSMBackgroundThread
  45. {
  46. private:
  47. // We use mMutex contained in our base class
  48. // to protect access to these variables:
  49. // mBusySocket, mSocketScheduledToBeDestroyed
  50. // and to nsSSLSocketThreadData::mSSLState
  51. // while a socket is the busy socket.
  52. // We use mCond contained in our base class
  53. // to notify the SSL thread that a new SSL I/O
  54. // request has been queued for processing.
  55. // It can be found in the mBusySocket variable,
  56. // containing all details in its member.
  57. // A socket that is currently owned by the SSL thread
  58. // and has pending SSL I/O activity or I/O results
  59. // not yet fetched by the original caller.
  60. nsNSSSocketInfo *mBusySocket;
  61. // A socket that should be closed and destroyed
  62. // as soon as possible. The request was initiated by
  63. // Necko, but it happened at a time when the SSL
  64. // thread had ownership of the socket, so the request
  65. // was delayed. It's now the responsibility of the
  66. // SSL thread to close and destroy this socket.
  67. nsNSSSocketInfo *mSocketScheduledToBeDestroyed;
  68. // Did we receive a request from NSS to fetch HTTP
  69. // data on behalf of NSS? (Most likely this is a OCSP request)
  70. // We track a handle to the HTTP request sent to Necko.
  71. // As this HTTP request depends on some original SSL socket,
  72. // we can use this handle to cancel the dependent HTTP request,
  73. // should we be asked to close the original SSL socket.
  74. nsCOMPtr<nsIRequest> mPendingHTTPRequest;
  75. virtual void Run(void);
  76. // Called from SSL thread only
  77. static PRInt32 checkHandshake(PRInt32 bytesTransfered,
  78. bool wasReading,
  79. PRFileDesc* fd,
  80. nsNSSSocketInfo *socketInfo);
  81. // Function can be called from either Necko or SSL thread
  82. // Caller must lock mMutex before this call.
  83. static void restoreOriginalSocket_locked(nsNSSSocketInfo *si);
  84. // Helper for requestSomething functions,
  85. // caled from the Necko thread only.
  86. static PRFileDesc *getRealSSLFD(nsNSSSocketInfo *si);
  87. // Support of blocking sockets is very rudimentary.
  88. // We only support it because Mozilla's LDAP code requires blocking I/O.
  89. // We do not support switching the blocking mode of a socket.
  90. // We require the blocking state has been set prior to the first
  91. // read/write call, and will stay that way for the remainder of the socket's lifetime.
  92. // This function must be called while holding the lock.
  93. // If the socket is a blocking socket, out_fd will contain the real FD,
  94. // on a non-blocking socket out_fd will be nsnull.
  95. // If there is a failure in obtaining the status of the socket,
  96. // the function will return PR_FAILURE.
  97. static PRStatus getRealFDIfBlockingSocket_locked(nsNSSSocketInfo *si,
  98. PRFileDesc *&out_fd);
  99. public:
  100. nsSSLThread();
  101. ~nsSSLThread();
  102. static nsSSLThread *ssl_thread_singleton;
  103. // All requestSomething functions are called from
  104. // the Necko thread only.
  105. static PRInt32 requestRead(nsNSSSocketInfo *si,
  106. void *buf,
  107. PRInt32 amount,
  108. PRIntervalTime timeout);
  109. static PRInt32 requestWrite(nsNSSSocketInfo *si,
  110. const void *buf,
  111. PRInt32 amount,
  112. PRIntervalTime timeout);
  113. static PRInt16 requestPoll(nsNSSSocketInfo *si,
  114. PRInt16 in_flags,
  115. PRInt16 *out_flags);
  116. static PRInt32 requestRecvMsgPeek(nsNSSSocketInfo *si, void *buf, PRInt32 amount,
  117. PRIntn flags, PRIntervalTime timeout);
  118. static PRStatus requestClose(nsNSSSocketInfo *si);
  119. static PRStatus requestGetsockname(nsNSSSocketInfo *si, PRNetAddr *addr);
  120. static PRStatus requestGetpeername(nsNSSSocketInfo *si, PRNetAddr *addr);
  121. static PRStatus requestGetsocketoption(nsNSSSocketInfo *si,
  122. PRSocketOptionData *data);
  123. static PRStatus requestSetsocketoption(nsNSSSocketInfo *si,
  124. const PRSocketOptionData *data);
  125. static PRStatus requestConnectcontinue(nsNSSSocketInfo *si,
  126. PRInt16 out_flags);
  127. static nsresult requestActivateSSL(nsNSSSocketInfo *si);
  128. static bool stoppedOrStopping();
  129. };
  130. #endif //_NSSSLTHREAD_H_