Mozilla Cross-Reference mozilla-central
mozilla/ xpcom/ io/ nsIOutputStream.idl
Hg Log
Hg Blame
Diff file
Raw file
view using tree:

Inheritance diagram for nsIOutputStream:

Inheritance graph

Collaboration diagram for nsIOutputStream:

Collaboration graph

[ nsIOutputStream Interface Reference | Graph Legend ]

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