Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsISupports.idl" |
michael@0 | 7 | |
michael@0 | 8 | interface nsIInputStream; |
michael@0 | 9 | |
michael@0 | 10 | %{C++ |
michael@0 | 11 | /** |
michael@0 | 12 | * The signature of the writer function passed to ReadSegments. This |
michael@0 | 13 | * is the "consumer" of data that gets read from the stream's buffer. |
michael@0 | 14 | * |
michael@0 | 15 | * @param aInStream stream being read |
michael@0 | 16 | * @param aClosure opaque parameter passed to ReadSegments |
michael@0 | 17 | * @param aFromSegment pointer to memory owned by the input stream. This is |
michael@0 | 18 | * where the writer function should start consuming data. |
michael@0 | 19 | * @param aToOffset amount of data already consumed by this writer during this |
michael@0 | 20 | * ReadSegments call. This is also the sum of the aWriteCount |
michael@0 | 21 | * returns from this writer over the previous invocations of |
michael@0 | 22 | * the writer by this ReadSegments call. |
michael@0 | 23 | * @param aCount Number of bytes available to be read starting at aFromSegment |
michael@0 | 24 | * @param [out] aWriteCount number of bytes read by this writer function call |
michael@0 | 25 | * |
michael@0 | 26 | * Implementers should return the following: |
michael@0 | 27 | * |
michael@0 | 28 | * @return NS_OK and (*aWriteCount > 0) if consumed some data |
michael@0 | 29 | * @return <any-error> if not interested in consuming any data |
michael@0 | 30 | * |
michael@0 | 31 | * Errors are never passed to the caller of ReadSegments. |
michael@0 | 32 | * |
michael@0 | 33 | * NOTE: returning NS_OK and (*aWriteCount = 0) has undefined behavior. |
michael@0 | 34 | */ |
michael@0 | 35 | typedef NS_CALLBACK(nsWriteSegmentFun)(nsIInputStream *aInStream, |
michael@0 | 36 | void *aClosure, |
michael@0 | 37 | const char *aFromSegment, |
michael@0 | 38 | uint32_t aToOffset, |
michael@0 | 39 | uint32_t aCount, |
michael@0 | 40 | uint32_t *aWriteCount); |
michael@0 | 41 | %} |
michael@0 | 42 | |
michael@0 | 43 | native nsWriteSegmentFun(nsWriteSegmentFun); |
michael@0 | 44 | |
michael@0 | 45 | /** |
michael@0 | 46 | * nsIInputStream |
michael@0 | 47 | * |
michael@0 | 48 | * An interface describing a readable stream of data. An input stream may be |
michael@0 | 49 | * "blocking" or "non-blocking" (see the IsNonBlocking method). A blocking |
michael@0 | 50 | * input stream may suspend the calling thread in order to satisfy a call to |
michael@0 | 51 | * Close, Available, Read, or ReadSegments. A non-blocking input stream, on |
michael@0 | 52 | * the other hand, must not block the calling thread of execution. |
michael@0 | 53 | * |
michael@0 | 54 | * NOTE: blocking input streams are often read on a background thread to avoid |
michael@0 | 55 | * locking up the main application thread. For this reason, it is generally |
michael@0 | 56 | * the case that a blocking input stream should be implemented using thread- |
michael@0 | 57 | * safe AddRef and Release. |
michael@0 | 58 | */ |
michael@0 | 59 | [scriptable, uuid(53cdbc97-c2d7-4e30-b2c3-45b2ee79db18)] |
michael@0 | 60 | interface nsIInputStream : nsISupports |
michael@0 | 61 | { |
michael@0 | 62 | /** |
michael@0 | 63 | * Close the stream. This method causes subsequent calls to Read and |
michael@0 | 64 | * ReadSegments to return 0 bytes read to indicate end-of-file. Any |
michael@0 | 65 | * subsequent calls to Available should throw NS_BASE_STREAM_CLOSED. |
michael@0 | 66 | */ |
michael@0 | 67 | void close(); |
michael@0 | 68 | |
michael@0 | 69 | /** |
michael@0 | 70 | * Determine number of bytes available in the stream. A non-blocking |
michael@0 | 71 | * stream that does not yet have any data to read should return 0 bytes |
michael@0 | 72 | * from this method (i.e., it must not throw the NS_BASE_STREAM_WOULD_BLOCK |
michael@0 | 73 | * exception). |
michael@0 | 74 | * |
michael@0 | 75 | * In addition to the number of bytes available in the stream, this method |
michael@0 | 76 | * also informs the caller of the current status of the stream. A stream |
michael@0 | 77 | * that is closed will throw an exception when this method is called. That |
michael@0 | 78 | * enables the caller to know the condition of the stream before attempting |
michael@0 | 79 | * to read from it. If a stream is at end-of-file, but not closed, then |
michael@0 | 80 | * this method returns 0 bytes available. (Note: some nsIInputStream |
michael@0 | 81 | * implementations automatically close when eof is reached; some do not). |
michael@0 | 82 | * |
michael@0 | 83 | * @return number of bytes currently available in the stream. |
michael@0 | 84 | * |
michael@0 | 85 | * @throws NS_BASE_STREAM_CLOSED if the stream is closed normally. |
michael@0 | 86 | * @throws <other-error> if the stream is closed due to some error |
michael@0 | 87 | * condition |
michael@0 | 88 | */ |
michael@0 | 89 | unsigned long long available(); |
michael@0 | 90 | |
michael@0 | 91 | /** |
michael@0 | 92 | * Read data from the stream. |
michael@0 | 93 | * |
michael@0 | 94 | * @param aBuf the buffer into which the data is to be read |
michael@0 | 95 | * @param aCount the maximum number of bytes to be read |
michael@0 | 96 | * |
michael@0 | 97 | * @return number of bytes read (may be less than aCount). |
michael@0 | 98 | * @return 0 if reached end-of-file |
michael@0 | 99 | * |
michael@0 | 100 | * @throws NS_BASE_STREAM_WOULD_BLOCK if reading from the input stream would |
michael@0 | 101 | * block the calling thread (non-blocking mode only) |
michael@0 | 102 | * @throws <other-error> on failure |
michael@0 | 103 | * |
michael@0 | 104 | * NOTE: this method should not throw NS_BASE_STREAM_CLOSED. |
michael@0 | 105 | */ |
michael@0 | 106 | [noscript] unsigned long read(in charPtr aBuf, in unsigned long aCount); |
michael@0 | 107 | |
michael@0 | 108 | /** |
michael@0 | 109 | * Low-level read method that provides access to the stream's underlying |
michael@0 | 110 | * buffer. The writer function may be called multiple times for segmented |
michael@0 | 111 | * buffers. ReadSegments is expected to keep calling the writer until |
michael@0 | 112 | * either there is nothing left to read or the writer returns an error. |
michael@0 | 113 | * ReadSegments should not call the writer with zero bytes to consume. |
michael@0 | 114 | * |
michael@0 | 115 | * @param aWriter the "consumer" of the data to be read |
michael@0 | 116 | * @param aClosure opaque parameter passed to writer |
michael@0 | 117 | * @param aCount the maximum number of bytes to be read |
michael@0 | 118 | * |
michael@0 | 119 | * @return number of bytes read (may be less than aCount) |
michael@0 | 120 | * @return 0 if reached end-of-file (or if aWriter refused to consume data) |
michael@0 | 121 | * |
michael@0 | 122 | * @throws NS_BASE_STREAM_WOULD_BLOCK if reading from the input stream would |
michael@0 | 123 | * block the calling thread (non-blocking mode only) |
michael@0 | 124 | * @throws NS_ERROR_NOT_IMPLEMENTED if the stream has no underlying buffer |
michael@0 | 125 | * @throws <other-error> on failure |
michael@0 | 126 | * |
michael@0 | 127 | * NOTE: this function may be unimplemented if a stream has no underlying |
michael@0 | 128 | * buffer (e.g., socket input stream). |
michael@0 | 129 | * |
michael@0 | 130 | * NOTE: this method should not throw NS_BASE_STREAM_CLOSED. |
michael@0 | 131 | */ |
michael@0 | 132 | [noscript] unsigned long readSegments(in nsWriteSegmentFun aWriter, |
michael@0 | 133 | in voidPtr aClosure, |
michael@0 | 134 | in unsigned long aCount); |
michael@0 | 135 | |
michael@0 | 136 | /** |
michael@0 | 137 | * @return true if stream is non-blocking |
michael@0 | 138 | * |
michael@0 | 139 | * NOTE: reading from a blocking input stream will block the calling thread |
michael@0 | 140 | * until at least one byte of data can be extracted from the stream. |
michael@0 | 141 | * |
michael@0 | 142 | * NOTE: a non-blocking input stream may implement nsIAsyncInputStream to |
michael@0 | 143 | * provide consumers with a way to wait for the stream to have more data |
michael@0 | 144 | * once its read method is unable to return any data without blocking. |
michael@0 | 145 | */ |
michael@0 | 146 | boolean isNonBlocking(); |
michael@0 | 147 | }; |