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.
20
* Alternatively, the contents of this file may be used under the
21
* terms of the GNU General Public License (the "GPL"), in which case
22
* the provisions of the GPL are applicable instead of
23
* those above. If you wish to allow use of your version of this
24
* file only under the terms of the GPL and not to allow
25
* others to use your version of this file under the MPL, indicate
26
* your decision by deleting the provisions above and replace them
27
* with the notice and other provisions required by the GPL.
28
* If you do not delete the provisions above, a recipient
29
* may use your version of this file under either the MPL or the
33
#ifndef nsPipeTransport_h__
34
#define nsPipeTransport_h__
37
#include "IPCProcess.h"
39
#include "nsIPipeTransport.h"
40
#include "nsIPipeListener.h"
41
#include "nsIRunnable.h"
42
#include "nsIEventQueueService.h"
43
#include "nsIInterfaceRequestor.h"
44
#include "nsITransport.h"
45
#include "nsIChannel.h"
48
#include "nsIThread.h"
49
#include "nsILoadGroup.h"
52
#include "nsIStreamListener.h"
53
#include "nsIInputStream.h"
54
#include "nsIOutputStream.h"
56
#ifdef MOZILLA_VERSION
57
#include "nsIAsyncInputStream.h"
58
#include "nsIAsyncOutputStream.h"
60
// Mods for Mozilla version prior to 1.3b
61
#include "nsIObservableInputStream.h"
62
#include "nsIObservableOutputStream.h"
65
#define NS_PIPE_TRANSPORT_DEFAULT_SEGMENT_SIZE (2*1024)
66
#define NS_PIPE_TRANSPORT_DEFAULT_BUFFER_SIZE (8*1024)
67
#define NS_PIPE_TRANSPORT_DEFAULT_HEADERS_SIZE (4*1024)
71
class nsPipeTransport : public nsIPipeTransport,
72
public nsIPipeTransportListener,
73
public nsIOutputStream,
74
public nsIStreamListener,
75
#ifdef MOZILLA_VERSION
76
public nsIInputStreamCallback,
77
public nsIOutputStreamCallback
79
// Mods for Mozilla version prior to 1.3b
80
public nsIInputStreamObserver,
81
public nsIOutputStreamObserver
87
NS_DECL_NSIPIPETRANSPORT
88
NS_DECL_NSIPIPETRANSPORTHEADERS
89
NS_DECL_NSIPIPETRANSPORTLISTENER
91
NS_DECL_NSIREQUESTOBSERVER
92
NS_DECL_NSIOUTPUTSTREAM
93
NS_DECL_NSISTREAMLISTENER
95
#ifdef MOZILLA_VERSION
96
NS_DECL_NSIINPUTSTREAMCALLBACK
97
NS_DECL_NSIOUTPUTSTREAMCALLBACK
99
// Mods for Mozilla version prior to 1.3b
100
NS_DECL_NSIINPUTSTREAMOBSERVER
101
NS_DECL_NSIOUTPUTSTREAMOBSERVER
104
// nsPipeTransport methods:
106
// Always make the destructor virtual:
107
virtual ~nsPipeTransport();
109
nsresult Finalize(PRBool destructor);
111
void KillProcess(void);
113
// Define a Create method to be used with a factory:
115
Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
124
STREAM_NOT_YET_OPENED,
133
PRBool mStartedRequest;
136
PipeState mPipeState;
137
StreamState mStdoutStream;
138
nsresult mCancelStatus;
140
nsLoadFlags mLoadFlags;
141
PRUint32 mNotificationFlags;
143
nsCString mExecutable;
145
nsCString mKillString;
147
IPCProcess* mProcess;
148
PRIntervalTime mKillWaitInterval;
151
PRUint32 mBufferSegmentSize;
152
PRUint32 mBufferMaxSize;
153
PRUint32 mHeadersMaxSize;
157
IPCFileDesc* mStdinWrite;
160
nsCOMPtr<nsIPipeTransportPoller> mStdoutPoller;
161
nsCOMPtr<nsIPipeListener> mConsole;
162
nsCOMPtr<nsIPipeTransportHeaders> mHeaderProcessor;
164
nsCOMPtr<nsIInputStream> mInputStream;
165
nsCOMPtr<nsIOutputStream> mOutputStream;
167
nsCOMPtr<nsIStreamListener> mListener;
168
nsCOMPtr<nsISupports> mContext;
169
nsCOMPtr<nsILoadGroup> mLoadGroup;
172
// Helper class to handle polling of STDOUT pipe
173
class nsStdoutPoller : public nsIPipeTransportPoller,
178
NS_DECL_NSIPIPETRANSPORTPOLLER
182
virtual ~nsStdoutPoller();
184
nsresult Init(IPCFileDesc* aStdoutRead,
185
IPCFileDesc* aStderrRead,
186
PRIntervalTime aTimeoutInterval,
187
nsIPipeListener* aConsole);
189
nsresult Finalize(PRBool destructor);
191
PRBool IsInterrupted(void);
193
nsresult GetPolledFD(PRFileDesc*& aFileDesc);
195
nsresult HeaderSearch(const char* buf, PRUint32 count,
196
PRUint32 *headerOffset);
202
PRBool mLoggingEnabled;
203
PRBool mJoinableThread;
205
PRIntervalTime mTimeoutInterval;
207
nsCString mHeadersBuf;
208
PRUint32 mHeadersBufSize;
209
PRUint32 mHeadersLastNewline;
210
PRBool mRequestStarted;
211
PRInt32 mContentLength;
213
IPCFileDesc* mStdoutRead;
214
IPCFileDesc* mStderrRead;
217
PRFileDesc* mPollableEvent;
221
nsCOMPtr<nsIThread> mStdoutThread;
222
nsCOMPtr<nsIOutputStream> mOutputStream;
223
nsCOMPtr<nsIPipeTransportListener> mProxyPipeListener;
224
nsCOMPtr<nsIPipeListener> mConsole;
227
// Helper class to handle write to pipe
228
class nsStdinWriter : public nsIPipeTransportWriter,
233
NS_DECL_NSIPIPETRANSPORTWRITER
237
virtual ~nsStdinWriter();
240
nsCOMPtr<nsIInputStream> mInputStream;
243
PRBool mCloseAfterWrite;
246
#endif // nsPipeTransport_h__