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