On x86 compilers without fastcall, simulate it when invoking traces and un-simulate...
[wine-gecko.git] / xpcom / io / nsIInputStream.idl
blobe494a553e327da9d76d6290ab274366bb1caf234
1 /* -*- Mode: C++; tab-width: 2; 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
13 * License.
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.
22 * Contributor(s):
23 * Warren Harris <warren@netscape.com>
24 * Darin Fisher <darin@netscape.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #include "nsISupports.idl"
42 interface nsIInputStream;
44 %{C++
45 /**
46 * The signature of the writer function passed to ReadSegments. This
47 * is the "consumer" of data that gets read from the stream's buffer.
49 * @param aInStream stream being read
50 * @param aClosure opaque parameter passed to ReadSegments
51 * @param aFromSegment pointer to memory owned by the input stream. This is
52 * where the writer function should start consuming data.
53 * @param aToOffset amount of data already consumed by this writer during this
54 * ReadSegments call. This is also the sum of the aWriteCount
55 * returns from this writer over the previous invocations of
56 * the writer by this ReadSegments call.
57 * @param aCount Number of bytes available to be read starting at aFromSegment
58 * @param [out] aWriteCount number of bytes read by this writer function call
60 * Implementers should return the following:
62 * @return NS_OK and (*aWriteCount > 0) if consumed some data
63 * @return <any-error> if not interested in consuming any data
65 * Errors are never passed to the caller of ReadSegments.
67 * NOTE: returning NS_OK and (*aWriteCount = 0) has undefined behavior.
69 * @status FROZEN
71 typedef NS_CALLBACK(nsWriteSegmentFun)(nsIInputStream *aInStream,
72 void *aClosure,
73 const char *aFromSegment,
74 PRUint32 aToOffset,
75 PRUint32 aCount,
76 PRUint32 *aWriteCount);
79 native nsWriteSegmentFun(nsWriteSegmentFun);
81 /**
82 * nsIInputStream
84 * An interface describing a readable stream of data. An input stream may be
85 * "blocking" or "non-blocking" (see the IsNonBlocking method). A blocking
86 * input stream may suspend the calling thread in order to satisfy a call to
87 * Close, Available, Read, or ReadSegments. A non-blocking input stream, on
88 * the other hand, must not block the calling thread of execution.
90 * NOTE: blocking input streams are often read on a background thread to avoid
91 * locking up the main application thread. For this reason, it is generally
92 * the case that a blocking input stream should be implemented using thread-
93 * safe AddRef and Release.
95 * @status FROZEN
97 [scriptable, uuid(fa9c7f6c-61b3-11d4-9877-00c04fa0cf4a)]
98 interface nsIInputStream : nsISupports
100 /**
101 * Close the stream. This method causes subsequent calls to Read and
102 * ReadSegments to return 0 bytes read to indicate end-of-file. Any
103 * subsequent calls to Available should throw NS_BASE_STREAM_CLOSED.
105 void close();
108 * Determine number of bytes available in the stream. A non-blocking
109 * stream that does not yet have any data to read should return 0 bytes
110 * from this method (i.e., it must not throw the NS_BASE_STREAM_WOULD_BLOCK
111 * exception).
113 * In addition to the number of bytes available in the stream, this method
114 * also informs the caller of the current status of the stream. A stream
115 * that is closed will throw an exception when this method is called. That
116 * enables the caller to know the condition of the stream before attempting
117 * to read from it. If a stream is at end-of-file, but not closed, then
118 * this method should return 0 bytes available.
120 * @return number of bytes currently available in the stream, or
121 * PR_UINT32_MAX if the size of the stream exceeds PR_UINT32_MAX.
123 * @throws NS_BASE_STREAM_CLOSED if the stream is closed normally or at
124 * end-of-file
125 * @throws <other-error> if the stream is closed due to some error
126 * condition
128 unsigned long available();
130 /**
131 * Read data from the stream.
133 * @param aBuf the buffer into which the data is to be read
134 * @param aCount the maximum number of bytes to be read
136 * @return number of bytes read (may be less than aCount).
137 * @return 0 if reached end-of-file
139 * @throws NS_BASE_STREAM_WOULD_BLOCK if reading from the input stream would
140 * block the calling thread (non-blocking mode only)
141 * @throws <other-error> on failure
143 * NOTE: this method should not throw NS_BASE_STREAM_CLOSED.
145 [noscript] unsigned long read(in charPtr aBuf, in unsigned long aCount);
148 * Low-level read method that provides access to the stream's underlying
149 * buffer. The writer function may be called multiple times for segmented
150 * buffers. ReadSegments is expected to keep calling the writer until
151 * either there is nothing left to read or the writer returns an error.
152 * ReadSegments should not call the writer with zero bytes to consume.
154 * @param aWriter the "consumer" of the data to be read
155 * @param aClosure opaque parameter passed to writer
156 * @param aCount the maximum number of bytes to be read
158 * @return number of bytes read (may be less than aCount)
159 * @return 0 if reached end-of-file (or if aWriter refused to consume data)
161 * @throws NS_BASE_STREAM_WOULD_BLOCK if reading from the input stream would
162 * block the calling thread (non-blocking mode only)
163 * @throws NS_ERROR_NOT_IMPLEMENTED if the stream has no underlying buffer
164 * @throws <other-error> on failure
166 * NOTE: this function may be unimplemented if a stream has no underlying
167 * buffer (e.g., socket input stream).
169 * NOTE: this method should not throw NS_BASE_STREAM_CLOSED.
171 [noscript] unsigned long readSegments(in nsWriteSegmentFun aWriter,
172 in voidPtr aClosure,
173 in unsigned long aCount);
176 * @return true if stream is non-blocking
178 * NOTE: reading from a blocking input stream will block the calling thread
179 * until at least one byte of data can be extracted from the stream.
181 * NOTE: a non-blocking input stream may implement nsIAsyncInputStream to
182 * provide consumers with a way to wait for the stream to have more data
183 * once its read method is unable to return any data without blocking.
185 boolean isNonBlocking();