PageRenderTime 18ms CodeModel.GetById 8ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 38#ifndef _NSSSLTHREAD_H_
 39#define _NSSSLTHREAD_H_
 40
 41#include "nsCOMPtr.h"
 42#include "nsIRequest.h"
 43#include "nsPSMBackgroundThread.h"
 44
 45class nsNSSSocketInfo;
 46class nsIHttpChannel;
 47
 48class nsSSLThread : public nsPSMBackgroundThread
 49{
 50private:
 51  // We use mMutex contained in our base class
 52  // to protect access to these variables:
 53  //   mBusySocket, mSocketScheduledToBeDestroyed
 54  // and to nsSSLSocketThreadData::mSSLState
 55  // while a socket is the busy socket.
 56
 57  // We use mCond contained in our base class
 58  // to notify the SSL thread that a new SSL I/O 
 59  // request has been queued for processing.
 60  // It can be found in the mBusySocket variable,
 61  // containing all details in its member.
 62
 63  // A socket that is currently owned by the SSL thread 
 64  // and has pending SSL I/O activity or I/O results 
 65  // not yet fetched by the original caller.
 66  nsNSSSocketInfo *mBusySocket;
 67  
 68  // A socket that should be closed and destroyed
 69  // as soon as possible. The request was initiated by
 70  // Necko, but it happened at a time when the SSL
 71  // thread had ownership of the socket, so the request
 72  // was delayed. It's now the responsibility of the
 73  // SSL thread to close and destroy this socket.
 74  nsNSSSocketInfo *mSocketScheduledToBeDestroyed;
 75
 76  // Did we receive a request from NSS to fetch HTTP 
 77  // data on behalf of NSS? (Most likely this is a OCSP request)
 78  // We track a handle to the HTTP request sent to Necko.
 79  // As this HTTP request depends on some original SSL socket,
 80  // we can use this handle to cancel the dependent HTTP request,
 81  // should we be asked to close the original SSL socket.
 82  nsCOMPtr<nsIRequest> mPendingHTTPRequest;
 83
 84  virtual void Run(void);
 85
 86  // Called from SSL thread only
 87  static PRInt32 checkHandshake(PRInt32 bytesTransfered, 
 88                                bool wasReading,
 89                                PRFileDesc* fd, 
 90                                nsNSSSocketInfo *socketInfo);
 91
 92  // Function can be called from either Necko or SSL thread
 93  // Caller must lock mMutex before this call.
 94  static void restoreOriginalSocket_locked(nsNSSSocketInfo *si);
 95
 96  // Helper for requestSomething functions, 
 97  // caled from the Necko thread only.
 98  static PRFileDesc *getRealSSLFD(nsNSSSocketInfo *si);
 99
100  // Support of blocking sockets is very rudimentary.
101  // We only support it because Mozilla's LDAP code requires blocking I/O.
102  // We do not support switching the blocking mode of a socket.
103  // We require the blocking state has been set prior to the first 
104  // read/write call, and will stay that way for the remainder of the socket's lifetime.
105  // This function must be called while holding the lock.
106  // If the socket is a blocking socket, out_fd will contain the real FD, 
107  // on a non-blocking socket out_fd will be nsnull.
108  // If there is a failure in obtaining the status of the socket,
109  // the function will return PR_FAILURE.
110  static PRStatus getRealFDIfBlockingSocket_locked(nsNSSSocketInfo *si, 
111                                                   PRFileDesc *&out_fd);
112public:
113  nsSSLThread();
114  ~nsSSLThread();
115
116  static nsSSLThread *ssl_thread_singleton;
117
118  // All requestSomething functions are called from 
119  // the Necko thread only.
120
121  static PRInt32 requestRead(nsNSSSocketInfo *si, 
122                             void *buf, 
123                             PRInt32 amount,
124                             PRIntervalTime timeout);
125
126  static PRInt32 requestWrite(nsNSSSocketInfo *si, 
127                              const void *buf, 
128                              PRInt32 amount,
129                              PRIntervalTime timeout);
130
131  static PRInt16 requestPoll(nsNSSSocketInfo *si, 
132                             PRInt16 in_flags, 
133                             PRInt16 *out_flags);
134
135  static PRInt32 requestRecvMsgPeek(nsNSSSocketInfo *si, void *buf, PRInt32 amount,
136                                    PRIntn flags, PRIntervalTime timeout);
137
138  static PRStatus requestClose(nsNSSSocketInfo *si);
139
140  static PRStatus requestGetsockname(nsNSSSocketInfo *si, PRNetAddr *addr);
141
142  static PRStatus requestGetpeername(nsNSSSocketInfo *si, PRNetAddr *addr);
143
144  static PRStatus requestGetsocketoption(nsNSSSocketInfo *si, 
145                                         PRSocketOptionData *data);
146
147  static PRStatus requestSetsocketoption(nsNSSSocketInfo *si, 
148                                         const PRSocketOptionData *data);
149
150  static PRStatus requestConnectcontinue(nsNSSSocketInfo *si, 
151                                         PRInt16 out_flags);
152
153  static nsresult requestActivateSSL(nsNSSSocketInfo *si);
154  
155  static bool stoppedOrStopping();
156};
157
158#endif //_NSSSLTHREAD_H_