xpcom/io/nsIOutputStream.idl

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 nsIOutputStream;
michael@0 9 interface nsIInputStream;
michael@0 10
michael@0 11 %{C++
michael@0 12 /**
michael@0 13 * The signature for the reader function passed to WriteSegments. This
michael@0 14 * is the "provider" of data that gets written into the stream's buffer.
michael@0 15 *
michael@0 16 * @param aOutStream stream being written to
michael@0 17 * @param aClosure opaque parameter passed to WriteSegments
michael@0 18 * @param aToSegment pointer to memory owned by the output stream
michael@0 19 * @param aFromOffset amount already written (since WriteSegments was called)
michael@0 20 * @param aCount length of toSegment
michael@0 21 * @param aReadCount number of bytes written
michael@0 22 *
michael@0 23 * Implementers should return the following:
michael@0 24 *
michael@0 25 * @throws <any-error> if not interested in providing any data
michael@0 26 *
michael@0 27 * Errors are never passed to the caller of WriteSegments.
michael@0 28 */
michael@0 29 typedef NS_CALLBACK(nsReadSegmentFun)(nsIOutputStream *aOutStream,
michael@0 30 void *aClosure,
michael@0 31 char *aToSegment,
michael@0 32 uint32_t aFromOffset,
michael@0 33 uint32_t aCount,
michael@0 34 uint32_t *aReadCount);
michael@0 35 %}
michael@0 36
michael@0 37 native nsReadSegmentFun(nsReadSegmentFun);
michael@0 38
michael@0 39 /**
michael@0 40 * nsIOutputStream
michael@0 41 *
michael@0 42 * An interface describing a writable stream of data. An output stream may be
michael@0 43 * "blocking" or "non-blocking" (see the IsNonBlocking method). A blocking
michael@0 44 * output stream may suspend the calling thread in order to satisfy a call to
michael@0 45 * Close, Flush, Write, WriteFrom, or WriteSegments. A non-blocking output
michael@0 46 * stream, on the other hand, must not block the calling thread of execution.
michael@0 47 *
michael@0 48 * NOTE: blocking output streams are often written to on a background thread to
michael@0 49 * avoid locking up the main application thread. For this reason, it is
michael@0 50 * generally the case that a blocking output stream should be implemented using
michael@0 51 * thread- safe AddRef and Release.
michael@0 52 */
michael@0 53 [scriptable, uuid(0d0acd2a-61b4-11d4-9877-00c04fa0cf4a)]
michael@0 54 interface nsIOutputStream : nsISupports
michael@0 55 {
michael@0 56 /**
michael@0 57 * Close the stream. Forces the output stream to flush any buffered data.
michael@0 58 *
michael@0 59 * @throws NS_BASE_STREAM_WOULD_BLOCK if unable to flush without blocking
michael@0 60 * the calling thread (non-blocking mode only)
michael@0 61 */
michael@0 62 void close();
michael@0 63
michael@0 64 /**
michael@0 65 * Flush the stream.
michael@0 66 *
michael@0 67 * @throws NS_BASE_STREAM_WOULD_BLOCK if unable to flush without blocking
michael@0 68 * the calling thread (non-blocking mode only)
michael@0 69 */
michael@0 70 void flush();
michael@0 71
michael@0 72 /**
michael@0 73 * Write data into the stream.
michael@0 74 *
michael@0 75 * @param aBuf the buffer containing the data to be written
michael@0 76 * @param aCount the maximum number of bytes to be written
michael@0 77 *
michael@0 78 * @return number of bytes written (may be less than aCount)
michael@0 79 *
michael@0 80 * @throws NS_BASE_STREAM_WOULD_BLOCK if writing to the output stream would
michael@0 81 * block the calling thread (non-blocking mode only)
michael@0 82 * @throws <other-error> on failure
michael@0 83 */
michael@0 84 unsigned long write(in string aBuf, in unsigned long aCount);
michael@0 85
michael@0 86 /**
michael@0 87 * Writes data into the stream from an input stream.
michael@0 88 *
michael@0 89 * @param aFromStream the stream containing the data to be written
michael@0 90 * @param aCount the maximum number of bytes to be written
michael@0 91 *
michael@0 92 * @return number of bytes written (may be less than aCount)
michael@0 93 *
michael@0 94 * @throws NS_BASE_STREAM_WOULD_BLOCK if writing to the output stream would
michael@0 95 * block the calling thread (non-blocking mode only)
michael@0 96 * @throws <other-error> on failure
michael@0 97 *
michael@0 98 * NOTE: This method is defined by this interface in order to allow the
michael@0 99 * output stream to efficiently copy the data from the input stream into
michael@0 100 * its internal buffer (if any). If this method was provided as an external
michael@0 101 * facility, a separate char* buffer would need to be used in order to call
michael@0 102 * the output stream's other Write method.
michael@0 103 */
michael@0 104 unsigned long writeFrom(in nsIInputStream aFromStream,
michael@0 105 in unsigned long aCount);
michael@0 106
michael@0 107 /**
michael@0 108 * Low-level write method that has access to the stream's underlying buffer.
michael@0 109 * The reader function may be called multiple times for segmented buffers.
michael@0 110 * WriteSegments is expected to keep calling the reader until either there
michael@0 111 * is nothing left to write or the reader returns an error. WriteSegments
michael@0 112 * should not call the reader with zero bytes to provide.
michael@0 113 *
michael@0 114 * @param aReader the "provider" of the data to be written
michael@0 115 * @param aClosure opaque parameter passed to reader
michael@0 116 * @param aCount the maximum number of bytes to be written
michael@0 117 *
michael@0 118 * @return number of bytes written (may be less than aCount)
michael@0 119 *
michael@0 120 * @throws NS_BASE_STREAM_WOULD_BLOCK if writing to the output stream would
michael@0 121 * block the calling thread (non-blocking mode only)
michael@0 122 * @throws NS_ERROR_NOT_IMPLEMENTED if the stream has no underlying buffer
michael@0 123 * @throws <other-error> on failure
michael@0 124 *
michael@0 125 * NOTE: this function may be unimplemented if a stream has no underlying
michael@0 126 * buffer (e.g., socket output stream).
michael@0 127 */
michael@0 128 [noscript] unsigned long writeSegments(in nsReadSegmentFun aReader,
michael@0 129 in voidPtr aClosure,
michael@0 130 in unsigned long aCount);
michael@0 131
michael@0 132 /**
michael@0 133 * @return true if stream is non-blocking
michael@0 134 *
michael@0 135 * NOTE: writing to a blocking output stream will block the calling thread
michael@0 136 * until all given data can be consumed by the stream.
michael@0 137 *
michael@0 138 * NOTE: a non-blocking output stream may implement nsIAsyncOutputStream to
michael@0 139 * provide consumers with a way to wait for the stream to accept more data
michael@0 140 * once its write method is unable to accept any data without blocking.
michael@0 141 */
michael@0 142 boolean isNonBlocking();
michael@0 143 };

mercurial