Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / xpcom / io / nsIPipe.idl
blobcb5a035a32dbb37abf6cb5a45fd4bc6618604c38
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsISupports.idl"
8 interface nsIAsyncInputStream;
9 interface nsIAsyncOutputStream;
11 /**
12 * nsIPipe represents an in-process buffer that can be read using nsIInputStream
13 * and written using nsIOutputStream. The reader and writer of a pipe do not
14 * have to be on the same thread. As a result, the pipe is an ideal mechanism
15 * to bridge data exchange between two threads. For example, a worker thread
16 * might write data to a pipe from which the main thread will read.
18 * Each end of the pipe can be either blocking or non-blocking. Recall that a
19 * non-blocking stream will return NS_BASE_STREAM_WOULD_BLOCK if it cannot be
20 * read or written to without blocking the calling thread. For example, if you
21 * try to read from an empty pipe that has not yet been closed, then if that
22 * pipe's input end is non-blocking, then the read call will fail immediately
23 * with NS_BASE_STREAM_WOULD_BLOCK as the error condition. However, if that
24 * pipe's input end is blocking, then the read call will not return until the
25 * pipe has data or until the pipe is closed. This example presumes that the
26 * pipe is being filled asynchronously on some background thread.
28 * The pipe supports nsIAsyncInputStream and nsIAsyncOutputStream, which give
29 * the user of a non-blocking pipe the ability to wait for the pipe to become
30 * ready again. For example, in the case of an empty non-blocking pipe, the
31 * user can call AsyncWait on the input end of the pipe to be notified when
32 * the pipe has data to read (or when the pipe becomes closed).
34 * NS_NewPipe2 and NS_NewPipe provide convenient pipe constructors. In most
35 * cases nsIPipe is not actually used. It is usually enough to just get
36 * references to the pipe's input and output end. In which case, the pipe is
37 * automatically closed when the respective pipe ends are released.
39 [scriptable, uuid(25d0de93-685e-4ea4-95d3-d884e31df63c)]
40 interface nsIPipe : nsISupports
42 /**
43 * initialize this pipe
45 * @param nonBlockingInput
46 * true specifies non-blocking input stream behavior
47 * @param nonBlockingOutput
48 * true specifies non-blocking output stream behavior
49 * @param segmentSize
50 * specifies the segment size in bytes (pass 0 to use default value)
51 * @param segmentCount
52 * specifies the max number of segments (pass 0 to use default
53 * value). Passing UINT32_MAX here causes the pipe to have
54 * "infinite" space. This mode can be useful in some cases, but
55 * should always be used with caution. The default value for this
56 * parameter is a finite value.
58 [must_use] void init(in boolean nonBlockingInput,
59 in boolean nonBlockingOutput,
60 in unsigned long segmentSize,
61 in unsigned long segmentCount);
63 /**
64 * The pipe's input end, which also implements nsISearchableInputStream.
65 * Getting fails if the pipe hasn't been initialized.
67 [must_use] readonly attribute nsIAsyncInputStream inputStream;
69 /**
70 * The pipe's output end. Getting fails if the pipe hasn't been
71 * initialized.
73 [must_use] readonly attribute nsIAsyncOutputStream outputStream;
76 /**
77 * XXX this interface doesn't really belong in here. It is here because
78 * currently nsPipeInputStream is the only implementation of this interface.
80 [scriptable, uuid(8C39EF62-F7C9-11d4-98F5-001083010E9B)]
81 interface nsISearchableInputStream : nsISupports
83 /**
84 * Searches for a string in the input stream. Since the stream has a notion
85 * of EOF, it is possible that the string may at some time be in the
86 * buffer, but is is not currently found up to some offset. Consequently,
87 * both the found and not found cases return an offset:
88 * if found, return offset where it was found
89 * if not found, return offset of the first byte not searched
90 * In the case the stream is at EOF and the string is not found, the first
91 * byte not searched will correspond to the length of the buffer.
93 void search(in string forString,
94 in boolean ignoreCase,
95 out boolean found,
96 out unsigned long offsetSearchedTo);
99 %{C++
101 class nsIInputStream;
102 class nsIOutputStream;
105 * NS_NewPipe2
107 * This function supersedes NS_NewPipe. It differs from NS_NewPipe in two
108 * major ways:
109 * (1) returns nsIAsyncInputStream and nsIAsyncOutputStream, so it is
110 * not necessary to QI in order to access these interfaces.
111 * (2) the size of the pipe is determined by the number of segments
112 * times the size of each segment.
114 * @param pipeIn
115 * resulting input end of the pipe
116 * @param pipeOut
117 * resulting output end of the pipe
118 * @param nonBlockingInput
119 * true specifies non-blocking input stream behavior
120 * @param nonBlockingOutput
121 * true specifies non-blocking output stream behavior
122 * @param segmentSize
123 * specifies the segment size in bytes (pass 0 to use default value)
124 * @param segmentCount
125 * specifies the max number of segments (pass 0 to use default value)
126 * passing UINT32_MAX here causes the pipe to have "infinite" space.
127 * this mode can be useful in some cases, but should always be used with
128 * caution. the default value for this parameter is a finite value.
130 extern void
131 NS_NewPipe2(nsIAsyncInputStream **pipeIn,
132 nsIAsyncOutputStream **pipeOut,
133 bool nonBlockingInput = false,
134 bool nonBlockingOutput = false,
135 uint32_t segmentSize = 0,
136 uint32_t segmentCount = 0);
139 * NS_NewPipe
141 * Preserved for backwards compatibility. Plus, this interface is more
142 * amiable in certain contexts (e.g., when you don't need the pipe's async
143 * capabilities).
145 * @param pipeIn
146 * resulting input end of the pipe
147 * @param pipeOut
148 * resulting output end of the pipe
149 * @param segmentSize
150 * specifies the segment size in bytes (pass 0 to use default value)
151 * @param maxSize
152 * specifies the max size of the pipe (pass 0 to use default value)
153 * number of segments is maxSize / segmentSize, and maxSize must be a
154 * multiple of segmentSize. passing UINT32_MAX here causes the
155 * pipe to have "infinite" space. this mode can be useful in some
156 * cases, but should always be used with caution. the default value
157 * for this parameter is a finite value.
158 * @param nonBlockingInput
159 * true specifies non-blocking input stream behavior
160 * @param nonBlockingOutput
161 * true specifies non-blocking output stream behavior
163 extern void
164 NS_NewPipe(nsIInputStream **pipeIn,
165 nsIOutputStream **pipeOut,
166 uint32_t segmentSize = 0,
167 uint32_t maxSize = 0,
168 bool nonBlockingInput = false,
169 bool nonBlockingOutput = false);