2
* The contents of this file are subject to the Mozilla Public
3
* License Version 1.1 (the "MPL"); you may not use this file
4
* except in compliance with the MPL. You may obtain a copy of
5
* the MPL at http://www.mozilla.org/MPL/
7
* Software distributed under the MPL is distributed on an "AS
8
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9
* implied. See the MPL for the specific language governing
10
* rights and limitations under the MPL.
12
* The Original Code is protoZilla.
14
* The Initial Developer of the Original Code is Ramalingam Saravanan.
15
* Portions created by Ramalingam Saravanan <svn@xmlterm.org> are
16
* Copyright (C) 2000 Ramalingam Saravanan. All Rights Reserved.
19
* Patrick Brunschwig <patrick@mozilla-enigmail.org>
21
* Alternatively, the contents of this file may be used under the
22
* terms of the GNU General Public License (the "GPL"), in which case
23
* the provisions of the GPL are applicable instead of
24
* those above. If you wish to allow use of your version of this
25
* file only under the terms of the GPL and not to allow
26
* others to use your version of this file under the MPL, indicate
27
* your decision by deleting the provisions above and replace them
28
* with the notice and other provisions required by the GPL.
29
* If you do not delete the provisions above, a recipient
30
* may use your version of this file under either the MPL or the
34
#ifndef nsPipeTransport_h__
35
#define nsPipeTransport_h__
38
#include "IPCProcess.h"
40
#include "nsIPipeTransport.h"
41
#include "nsIPipeListener.h"
42
#include "nsIRunnable.h"
43
#include "nsIInterfaceRequestor.h"
44
#include "nsITransport.h"
45
#include "nsIChannel.h"
48
#include "nsIThread.h"
49
#include "nsILoadGroup.h"
51
#include "nsIStreamListener.h"
52
#include "nsIInputStream.h"
53
#include "nsIOutputStream.h"
54
#include "nsThreadUtils.h"
56
#ifndef _IPC_FORCE_INTERNAL_API
57
#include "nsStringAPI.h"
63
#include "nsIAsyncInputStream.h"
64
#include "nsIAsyncOutputStream.h"
66
#define NS_PIPE_TRANSPORT_DEFAULT_SEGMENT_SIZE (2*1024)
67
#define NS_PIPE_TRANSPORT_DEFAULT_BUFFER_SIZE (8*1024)
68
#define NS_PIPE_TRANSPORT_DEFAULT_HEADERS_SIZE (4*1024)
72
class nsPipeTransport : public nsIPipeTransport,
73
public nsIPipeTransportListener,
74
public nsIOutputStream,
75
public nsIStreamListener,
76
public nsIInputStreamCallback,
77
public nsIOutputStreamCallback
81
NS_DECL_NSIPIPETRANSPORT
82
NS_DECL_NSIPIPETRANSPORTHEADERS
83
NS_DECL_NSIPIPETRANSPORTLISTENER
85
NS_DECL_NSIREQUESTOBSERVER
86
NS_DECL_NSIOUTPUTSTREAM
87
NS_DECL_NSISTREAMLISTENER
88
NS_DECL_NSIINPUTSTREAMCALLBACK
89
NS_DECL_NSIOUTPUTSTREAMCALLBACK
91
// nsPipeTransport methods:
93
// Always make the destructor virtual:
94
virtual ~nsPipeTransport();
96
nsresult Finalize(PRBool destructor);
98
void KillProcess(void);
100
// Define a Create method to be used with a factory:
102
Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
111
STREAM_NOT_YET_OPENED,
120
PRBool mStartedRequest;
123
PipeState mPipeState;
124
StreamState mStdoutStream;
125
nsresult mCancelStatus;
127
nsLoadFlags mLoadFlags;
128
PRUint32 mNotificationFlags;
130
nsCString mExecutable;
132
nsCString mKillString;
134
PRUint32 mStartupFlags;
136
IPCProcess* mProcess;
137
PRIntervalTime mKillWaitInterval;
140
PRUint32 mBufferSegmentSize;
141
PRUint32 mBufferMaxSize;
142
PRUint32 mHeadersMaxSize;
146
IPCFileDesc* mStdinWrite;
149
nsCOMPtr<nsIPipeTransportPoller> mStdoutPoller;
150
nsCOMPtr<nsIPipeListener> mConsole;
151
nsCOMPtr<nsIPipeTransportHeaders> mHeaderProcessor;
153
nsCOMPtr<nsIInputStream> mInputStream;
154
nsCOMPtr<nsIOutputStream> mOutputStream;
156
nsCOMPtr<nsIStreamListener> mListener;
157
nsCOMPtr<nsISupports> mContext;
158
nsCOMPtr<nsILoadGroup> mLoadGroup;
159
nsCOMPtr<nsIPipeTransportWriter> mPipeTransportWriter;
162
// Helper class to handle polling of STDOUT pipe
163
class nsStdoutPoller : public nsIPipeTransportPoller,
168
NS_DECL_NSIPIPETRANSPORTPOLLER
172
virtual ~nsStdoutPoller();
174
nsresult Init(IPCFileDesc* aStdoutRead,
175
IPCFileDesc* aStderrRead,
176
PRIntervalTime aTimeoutInterval,
177
nsIPipeListener* aConsole);
179
nsresult Finalize(PRBool destructor);
181
PRBool IsInterrupted(void);
183
nsresult GetPolledFD(PRFileDesc*& aFileDesc);
185
nsresult HeaderSearch(const char* buf, PRUint32 count,
186
PRUint32 *headerOffset);
192
PRBool mLoggingEnabled;
193
PRBool mJoinableThread;
195
PRIntervalTime mTimeoutInterval;
197
nsCString mHeadersBuf;
198
PRUint32 mHeadersBufSize;
199
PRUint32 mHeadersLastNewline;
200
PRBool mRequestStarted;
201
PRInt32 mContentLength;
203
IPCFileDesc* mStdoutRead;
204
IPCFileDesc* mStderrRead;
207
PRFileDesc* mPollableEvent;
211
nsCOMPtr<nsIThread> mStdoutThread;
212
nsCOMPtr<nsIOutputStream> mOutputStream;
213
nsCOMPtr<nsIPipeTransportListener> mProxyPipeListener;
214
nsCOMPtr<nsIPipeListener> mConsole;
217
// Helper class to handle write to pipe
218
class nsStdinWriter : public nsIPipeTransportWriter,
223
NS_DECL_NSIPIPETRANSPORTWRITER
227
virtual ~nsStdinWriter();
230
nsCOMPtr<nsIInputStream> mInputStream;
233
PRBool mCloseAfterWrite;
234
nsCOMPtr<nsIThread> mThread;
237
#endif // nsPipeTransport_h__