Bug 452390 Tracemonkey will crash if the compiler doesn't have FASTCALL r=danderson
[wine-gecko.git] / security / manager / ssl / src / nsSSLThread.h
blobd91b2ee77278653c77df7fba67b9039f5de37f55
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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.
14 * The Original Code is mozilla.org code.
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.
21 * Contributor(s):
22 * Kai Engert <kengert@redhat.com>
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.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef _NSSSLTHREAD_H_
39 #define _NSSSLTHREAD_H_
41 #include "nsCOMPtr.h"
42 #include "nsIRequest.h"
43 #include "nsPSMBackgroundThread.h"
45 class nsNSSSocketInfo;
46 class nsIHttpChannel;
48 class nsSSLThread : public nsPSMBackgroundThread
50 private:
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.
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.
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;
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;
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;
84 virtual void Run(void);
86 // Called from SSL thread only
87 static PRInt32 checkHandshake(PRInt32 bytesTransfered,
88 PRBool wasReading,
89 PRFileDesc* fd,
90 nsNSSSocketInfo *socketInfo);
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);
96 // Helper for requestSomething functions,
97 // caled from the Necko thread only.
98 static PRFileDesc *getRealSSLFD(nsNSSSocketInfo *si);
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);
112 public:
113 nsSSLThread();
114 ~nsSSLThread();
116 static nsSSLThread *ssl_thread_singleton;
118 // All requestSomething functions are called from
119 // the Necko thread only.
121 static PRInt32 requestRead(nsNSSSocketInfo *si,
122 void *buf,
123 PRInt32 amount,
124 PRIntervalTime timeout);
126 static PRInt32 requestWrite(nsNSSSocketInfo *si,
127 const void *buf,
128 PRInt32 amount,
129 PRIntervalTime timeout);
131 static PRInt16 requestPoll(nsNSSSocketInfo *si,
132 PRInt16 in_flags,
133 PRInt16 *out_flags);
135 static PRInt32 requestRecvMsgPeek(nsNSSSocketInfo *si, void *buf, PRInt32 amount,
136 PRIntn flags, PRIntervalTime timeout);
138 static PRStatus requestClose(nsNSSSocketInfo *si);
140 static PRStatus requestGetsockname(nsNSSSocketInfo *si, PRNetAddr *addr);
142 static PRStatus requestGetpeername(nsNSSSocketInfo *si, PRNetAddr *addr);
144 static PRStatus requestGetsocketoption(nsNSSSocketInfo *si,
145 PRSocketOptionData *data);
147 static PRStatus requestSetsocketoption(nsNSSSocketInfo *si,
148 const PRSocketOptionData *data);
150 static PRStatus requestConnectcontinue(nsNSSSocketInfo *si,
151 PRInt16 out_flags);
153 static nsresult requestActivateSSL(nsNSSSocketInfo *si);
155 static PRBool exitRequested();
158 #endif //_NSSSLTHREAD_H_