1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or 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 #include
"nsIAsyncInputStream.idl"
39 #include
"nsIAsyncOutputStream.idl"
44 * nsIPipe represents an in-process buffer that can be read using nsIInputStream
45 * and written using nsIOutputStream. The reader and writer of a pipe do not
46 * have to be on the same thread. As a result, the pipe is an ideal mechanism
47 * to bridge data exchange between two threads. For example, a worker thread
48 * might write data to a pipe from which the main thread will read.
50 * Each end of the pipe can be either blocking or non-blocking. Recall that a
51 * non-blocking stream will return NS_BASE_STREAM_WOULD_BLOCK if it cannot be
52 * read or written to without blocking the calling thread. For example, if you
53 * try to read from an empty pipe that has not yet been closed, then if that
54 * pipe's input end is non-blocking, then the read call will fail immediately
55 * with NS_BASE_STREAM_WOULD_BLOCK as the error condition. However, if that
56 * pipe's input end is blocking, then the read call will not return until the
57 * pipe has data or until the pipe is closed. This example presumes that the
58 * pipe is being filled asynchronously on some background thread.
60 * The pipe supports nsIAsyncInputStream and nsIAsyncOutputStream, which give
61 * the user of a non-blocking pipe the ability to wait for the pipe to become
62 * ready again. For example, in the case of an empty non-blocking pipe, the
63 * user can call AsyncWait on the input end of the pipe to be notified when
64 * the pipe has data to read (or when the pipe becomes closed).
66 * NS_NewPipe2 and NS_NewPipe provide convenient pipe constructors. In most
67 * cases nsIPipe is not actually used. It is usually enough to just get
68 * references to the pipe's input and output end. In which case, the pipe is
69 * automatically closed when the respective pipe ends are released.
71 [scriptable
, uuid(f4211abc
-61b3
-11d4
-9877-00c04fa0cf4a
)]
72 interface nsIPipe
: nsISupports
75 * initialize this pipe
77 * @param nonBlockingInput
78 * true specifies non-blocking input stream behavior
79 * @param nonBlockingOutput
80 * true specifies non-blocking output stream behavior
82 * specifies the segment size in bytes (pass 0 to use default value)
84 * specifies the max number of segments (pass 0 to use default
85 * value). Passing PR_UINT32_MAX here causes the pipe to have
86 * "infinite" space. This mode can be useful in some cases, but
87 * should always be used with caution. The default value for this
88 * parameter is a finite value.
89 * @param segmentAllocator
90 * pass reference to nsIMemory to have all pipe allocations use this
91 * allocator (pass null to use the default allocator)
93 void init
(in boolean nonBlockingInput
,
94 in boolean nonBlockingOutput
,
95 in unsigned long segmentSize
,
96 in unsigned long segmentCount
,
97 in nsIMemory segmentAllocator
);
100 * The pipe's input end, which also implements nsISearchableInputStream.
102 readonly attribute nsIAsyncInputStream inputStream
;
105 * The pipe's output end.
107 readonly attribute nsIAsyncOutputStream outputStream
;
111 * XXX this interface doesn't really belong in here. It is here because
112 * currently nsPipeInputStream is the only implementation of this interface.
114 [scriptable
, uuid(8C39EF62
-F7C9
-11d4
-98F5
-001083010E9B
)]
115 interface nsISearchableInputStream
: nsISupports
118 * Searches for a string in the input stream. Since the stream has a notion
119 * of EOF, it is possible that the string may at some time be in the
120 * buffer, but is is not currently found up to some offset. Consequently,
121 * both the found and not found cases return an offset:
122 * if found, return offset where it was found
123 * if not found, return offset of the first byte not searched
124 * In the case the stream is at EOF and the string is not found, the first
125 * byte not searched will correspond to the length of the buffer.
127 void search
(in string forString
,
128 in boolean ignoreCase
,
130 out unsigned long offsetSearchedTo
);
138 * This function supercedes NS_NewPipe. It differs from NS_NewPipe in two
140 * (1) returns nsIAsyncInputStream and nsIAsyncOutputStream, so it is
141 * not necessary to QI in order to access these interfaces.
142 * (2) the size of the pipe is determined by the number of segments
143 * times the size of each segment.
146 * resulting input end of the pipe
148 * resulting output end of the pipe
149 * @param nonBlockingInput
150 * true specifies non-blocking input stream behavior
151 * @param nonBlockingOutput
152 * true specifies non-blocking output stream behavior
154 * specifies the segment size in bytes (pass 0 to use default value)
155 * @param segmentCount
156 * specifies the max number of segments (pass 0 to use default value)
157 * passing PR_UINT32_MAX here causes the pipe to have "infinite" space.
158 * this mode can be useful in some cases, but should always be used with
159 * caution. the default value for this parameter is a finite value.
160 * @param segmentAlloc
161 * pass reference to nsIMemory to have all pipe allocations use this
162 * allocator (pass null to use the default allocator)
164 extern NS_COM nsresult
165 NS_NewPipe2
(nsIAsyncInputStream
**pipeIn
,
166 nsIAsyncOutputStream
**pipeOut
,
167 PRBool nonBlockingInput
= PR_FALSE
,
168 PRBool nonBlockingOutput
= PR_FALSE
,
169 PRUint32 segmentSize
= 0,
170 PRUint32 segmentCount
= 0,
171 nsIMemory
*segmentAlloc
= nsnull
);
176 * Preserved for backwards compatibility. Plus, this interface is more
177 * amiable in certain contexts (e.g., when you don't need the pipe's async
181 * resulting input end of the pipe
183 * resulting output end of the pipe
185 * specifies the segment size in bytes (pass 0 to use default value)
187 * specifies the max size of the pipe (pass 0 to use default value)
188 * number of segments is maxSize / segmentSize, and maxSize must be a
189 * multiple of segmentSize. passing PR_UINT32_MAX here causes the
190 * pipe to have "infinite" space. this mode can be useful in some
191 * cases, but should always be used with caution. the default value
192 * for this parameter is a finite value.
193 * @param nonBlockingInput
194 * true specifies non-blocking input stream behavior
195 * @param nonBlockingOutput
196 * true specifies non-blocking output stream behavior
197 * @param segmentAlloc
198 * pass reference to nsIMemory to have all pipe allocations use this
199 * allocator (pass null to use the default allocator)
201 extern NS_COM nsresult
202 NS_NewPipe
(nsIInputStream
**pipeIn
,
203 nsIOutputStream
**pipeOut
,
204 PRUint32 segmentSize
= 0,
205 PRUint32 maxSize
= 0,
206 PRBool nonBlockingInput
= PR_FALSE
,
207 PRBool nonBlockingOutput
= PR_FALSE
,
208 nsIMemory
*segmentAlloc
= nsnull
);