2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-08-24 08:54:56 +04:00
|
|
|
|
2013-09-23 21:29:27 +04:00
|
|
|
#include "nsISupports.idl"
|
1999-08-24 08:54:56 +04:00
|
|
|
|
2013-09-23 21:29:27 +04:00
|
|
|
interface nsIAsyncInputStream;
|
|
|
|
interface nsIAsyncOutputStream;
|
1999-08-24 08:54:56 +04:00
|
|
|
|
2003-10-09 05:54:07 +04:00
|
|
|
/**
|
|
|
|
* nsIPipe represents an in-process buffer that can be read using nsIInputStream
|
|
|
|
* and written using nsIOutputStream. The reader and writer of a pipe do not
|
|
|
|
* have to be on the same thread. As a result, the pipe is an ideal mechanism
|
|
|
|
* to bridge data exchange between two threads. For example, a worker thread
|
|
|
|
* might write data to a pipe from which the main thread will read.
|
|
|
|
*
|
|
|
|
* Each end of the pipe can be either blocking or non-blocking. Recall that a
|
|
|
|
* non-blocking stream will return NS_BASE_STREAM_WOULD_BLOCK if it cannot be
|
|
|
|
* read or written to without blocking the calling thread. For example, if you
|
|
|
|
* try to read from an empty pipe that has not yet been closed, then if that
|
|
|
|
* pipe's input end is non-blocking, then the read call will fail immediately
|
|
|
|
* with NS_BASE_STREAM_WOULD_BLOCK as the error condition. However, if that
|
|
|
|
* pipe's input end is blocking, then the read call will not return until the
|
|
|
|
* pipe has data or until the pipe is closed. This example presumes that the
|
|
|
|
* pipe is being filled asynchronously on some background thread.
|
|
|
|
*
|
|
|
|
* The pipe supports nsIAsyncInputStream and nsIAsyncOutputStream, which give
|
|
|
|
* the user of a non-blocking pipe the ability to wait for the pipe to become
|
|
|
|
* ready again. For example, in the case of an empty non-blocking pipe, the
|
|
|
|
* user can call AsyncWait on the input end of the pipe to be notified when
|
|
|
|
* the pipe has data to read (or when the pipe becomes closed).
|
|
|
|
*
|
|
|
|
* NS_NewPipe2 and NS_NewPipe provide convenient pipe constructors. In most
|
|
|
|
* cases nsIPipe is not actually used. It is usually enough to just get
|
|
|
|
* references to the pipe's input and output end. In which case, the pipe is
|
|
|
|
* automatically closed when the respective pipe ends are released.
|
|
|
|
*/
|
2013-12-11 23:14:56 +04:00
|
|
|
[scriptable, uuid(25d0de93-685e-4ea4-95d3-d884e31df63c)]
|
2002-03-12 03:59:06 +03:00
|
|
|
interface nsIPipe : nsISupports
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* initialize this pipe
|
2007-09-18 02:30:58 +04:00
|
|
|
*
|
|
|
|
* @param nonBlockingInput
|
|
|
|
* true specifies non-blocking input stream behavior
|
|
|
|
* @param nonBlockingOutput
|
|
|
|
* true specifies non-blocking output stream behavior
|
|
|
|
* @param segmentSize
|
|
|
|
* specifies the segment size in bytes (pass 0 to use default value)
|
|
|
|
* @param segmentCount
|
|
|
|
* specifies the max number of segments (pass 0 to use default
|
2012-09-28 10:57:33 +04:00
|
|
|
* value). Passing UINT32_MAX here causes the pipe to have
|
2007-09-18 02:30:58 +04:00
|
|
|
* "infinite" space. This mode can be useful in some cases, but
|
|
|
|
* should always be used with caution. The default value for this
|
|
|
|
* parameter is a finite value.
|
2002-03-12 03:59:06 +03:00
|
|
|
*/
|
2016-08-17 09:52:48 +03:00
|
|
|
[must_use] void init(in boolean nonBlockingInput,
|
|
|
|
in boolean nonBlockingOutput,
|
|
|
|
in unsigned long segmentSize,
|
|
|
|
in unsigned long segmentCount);
|
2002-03-12 03:59:06 +03:00
|
|
|
|
2003-10-09 05:54:07 +04:00
|
|
|
/**
|
|
|
|
* The pipe's input end, which also implements nsISearchableInputStream.
|
2016-08-17 09:52:48 +03:00
|
|
|
* Getting fails if the pipe hasn't been initialized.
|
2003-10-09 05:54:07 +04:00
|
|
|
*/
|
2016-08-17 09:52:48 +03:00
|
|
|
[must_use] readonly attribute nsIAsyncInputStream inputStream;
|
2003-10-09 05:54:07 +04:00
|
|
|
|
|
|
|
/**
|
2016-08-17 09:52:48 +03:00
|
|
|
* The pipe's output end. Getting fails if the pipe hasn't been
|
|
|
|
* initialized.
|
2003-10-09 05:54:07 +04:00
|
|
|
*/
|
2016-08-17 09:52:48 +03:00
|
|
|
[must_use] readonly attribute nsIAsyncOutputStream outputStream;
|
1999-08-24 08:54:56 +04:00
|
|
|
};
|
|
|
|
|
2003-10-09 05:54:07 +04:00
|
|
|
/**
|
|
|
|
* XXX this interface doesn't really belong in here. It is here because
|
|
|
|
* currently nsPipeInputStream is the only implementation of this interface.
|
|
|
|
*/
|
2001-04-08 01:29:11 +04:00
|
|
|
[scriptable, uuid(8C39EF62-F7C9-11d4-98F5-001083010E9B)]
|
2002-03-12 03:59:06 +03:00
|
|
|
interface nsISearchableInputStream : nsISupports
|
|
|
|
{
|
2001-04-08 01:29:11 +04:00
|
|
|
/**
|
|
|
|
* Searches for a string in the input stream. Since the stream has a notion
|
|
|
|
* of EOF, it is possible that the string may at some time be in the
|
|
|
|
* buffer, but is is not currently found up to some offset. Consequently,
|
|
|
|
* both the found and not found cases return an offset:
|
|
|
|
* if found, return offset where it was found
|
|
|
|
* if not found, return offset of the first byte not searched
|
|
|
|
* In the case the stream is at EOF and the string is not found, the first
|
|
|
|
* byte not searched will correspond to the length of the buffer.
|
|
|
|
*/
|
|
|
|
void search(in string forString,
|
|
|
|
in boolean ignoreCase,
|
|
|
|
out boolean found,
|
|
|
|
out unsigned long offsetSearchedTo);
|
|
|
|
};
|
|
|
|
|
1999-08-24 08:54:56 +04:00
|
|
|
%{C++
|
|
|
|
|
2013-09-23 21:29:27 +04:00
|
|
|
class nsIInputStream;
|
|
|
|
class nsIOutputStream;
|
|
|
|
|
2003-10-09 05:54:07 +04:00
|
|
|
/**
|
|
|
|
* NS_NewPipe2
|
|
|
|
*
|
2010-05-13 16:19:50 +04:00
|
|
|
* This function supersedes NS_NewPipe. It differs from NS_NewPipe in two
|
2003-10-09 05:54:07 +04:00
|
|
|
* major ways:
|
|
|
|
* (1) returns nsIAsyncInputStream and nsIAsyncOutputStream, so it is
|
|
|
|
* not necessary to QI in order to access these interfaces.
|
|
|
|
* (2) the size of the pipe is determined by the number of segments
|
|
|
|
* times the size of each segment.
|
|
|
|
*
|
|
|
|
* @param pipeIn
|
|
|
|
* resulting input end of the pipe
|
|
|
|
* @param pipeOut
|
|
|
|
* resulting output end of the pipe
|
|
|
|
* @param nonBlockingInput
|
|
|
|
* true specifies non-blocking input stream behavior
|
|
|
|
* @param nonBlockingOutput
|
|
|
|
* true specifies non-blocking output stream behavior
|
|
|
|
* @param segmentSize
|
|
|
|
* specifies the segment size in bytes (pass 0 to use default value)
|
|
|
|
* @param segmentCount
|
|
|
|
* specifies the max number of segments (pass 0 to use default value)
|
2012-09-28 10:57:33 +04:00
|
|
|
* passing UINT32_MAX here causes the pipe to have "infinite" space.
|
2003-10-09 05:54:07 +04:00
|
|
|
* this mode can be useful in some cases, but should always be used with
|
|
|
|
* caution. the default value for this parameter is a finite value.
|
|
|
|
*/
|
2016-08-17 09:52:48 +03:00
|
|
|
extern MOZ_MUST_USE nsresult
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_NewPipe2(nsIAsyncInputStream **pipeIn,
|
|
|
|
nsIAsyncOutputStream **pipeOut,
|
2012-09-21 22:40:14 +04:00
|
|
|
bool nonBlockingInput = false,
|
|
|
|
bool nonBlockingOutput = false,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t segmentSize = 0,
|
2013-12-11 23:14:56 +04:00
|
|
|
uint32_t segmentCount = 0);
|
2003-01-18 05:15:14 +03:00
|
|
|
|
2003-10-09 05:54:07 +04:00
|
|
|
/**
|
|
|
|
* NS_NewPipe
|
|
|
|
*
|
|
|
|
* Preserved for backwards compatibility. Plus, this interface is more
|
|
|
|
* amiable in certain contexts (e.g., when you don't need the pipe's async
|
|
|
|
* capabilities).
|
|
|
|
*
|
|
|
|
* @param pipeIn
|
|
|
|
* resulting input end of the pipe
|
|
|
|
* @param pipeOut
|
|
|
|
* resulting output end of the pipe
|
|
|
|
* @param segmentSize
|
|
|
|
* specifies the segment size in bytes (pass 0 to use default value)
|
|
|
|
* @param maxSize
|
|
|
|
* specifies the max size of the pipe (pass 0 to use default value)
|
|
|
|
* number of segments is maxSize / segmentSize, and maxSize must be a
|
2012-09-28 10:57:33 +04:00
|
|
|
* multiple of segmentSize. passing UINT32_MAX here causes the
|
2003-10-09 05:54:07 +04:00
|
|
|
* pipe to have "infinite" space. this mode can be useful in some
|
|
|
|
* cases, but should always be used with caution. the default value
|
|
|
|
* for this parameter is a finite value.
|
|
|
|
* @param nonBlockingInput
|
|
|
|
* true specifies non-blocking input stream behavior
|
|
|
|
* @param nonBlockingOutput
|
|
|
|
* true specifies non-blocking output stream behavior
|
|
|
|
*/
|
2016-08-17 09:52:48 +03:00
|
|
|
extern MOZ_MUST_USE nsresult
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_NewPipe(nsIInputStream **pipeIn,
|
|
|
|
nsIOutputStream **pipeOut,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t segmentSize = 0,
|
|
|
|
uint32_t maxSize = 0,
|
2012-09-21 22:40:14 +04:00
|
|
|
bool nonBlockingInput = false,
|
2013-12-11 23:14:56 +04:00
|
|
|
bool nonBlockingOutput = false);
|
2003-01-18 05:15:14 +03:00
|
|
|
|
1999-08-24 08:54:56 +04:00
|
|
|
%}
|