nsITransport 编辑

netwerk/base/public/nsITransport.idlScriptable This interface provides a common way of accessing i/o streams connected to some resource. This interface does not in any way specify the resource. Inherits from: nsISupports Last changed in Gecko 1.8 (Firefox 1.5 / Thunderbird 1.5 / SeaMonkey 1.0)

This interface provides methods to open blocking or non-blocking, buffered or unbuffered streams to the resource. The name "transport" is meant to connote the inherent data transfer implied by this interface (that is, data is being transfered in some fashion via the streams exposed by this interface).

A transport can have an event sink associated with it. The event sink receives transport-specific events as the transfer is occurring. For a socket transport, these events can include status about the connection. See nsISocketTransport for more info about socket transport specifics.

Method overview

void close(in nsresult aReason);
nsIInputStream openInputStream(in unsigned long aFlags, in unsigned long aSegmentSize, in unsigned long aSegmentCount);
nsIOutputStream openOutputStream(in unsigned long aFlags, in unsigned long aSegmentSize, in unsigned long aSegmentCount);
void setEventSink(in nsITransportEventSink aSink, in nsIEventTarget aEventTarget);

Constants

Open flags.

ConstantValueDescription
OPEN_BLOCKING1<<0Open flags.
OPEN_UNBUFFERED1<<1 

Generic nsITransportEventSink status codes. nsITransport implementations may override these status codes with their own more specific status codes (for example, see nsISocketTransport).

ConstantValueDescription
STATUS_READING0x804b0008 
STATUS_WRITING0x804b0009 

Methods

close()

Close the transport and any open streams.

void close(
  in nsresult aReason
);
Parameters
aReason
The reason for closing the stream.

openInputStream()

Open an input stream on this transport.

nsIInputStream openInputStream(
  in unsigned long aFlags,
  in unsigned long aSegmentSize,
  in unsigned long aSegmentCount
);
Parameters
aFlags
Optional transport specific flags.

Flags have the following meaning:

OPEN_BLOCKING If specified, then the resulting stream will have blocking stream semantics. This means that if the stream has no data and is not closed, then reading from it will block the calling thread until at least one byte is available or until the stream is closed. If this flag is NOT specified, then the stream has non-blocking stream semantics. This means that if the stream has no data and is not closed, then reading from it returns NS_BASE_STREAM_WOULD_BLOCK. In addition, in non-blocking mode, the stream is guaranteed to support nsIAsyncInputStream. This interface allows the consumer of the stream to be notified when the stream can again be read.

OPEN_UNBUFFERED If specified, the resulting stream may not support ReadSegments. ReadSegments is only guaranteed to be implemented when this flag is NOT specified.

aSegmentSize
If OPEN_UNBUFFERED is not set, then this parameter specifies the size of each buffer segment (pass 0 to use default value).
aSegmentCount
If OPEN_UNBUFFERED is not set, then this parameter specifies the maximum number of buffer segments (pass 0 to use default value).
Return value

 

openOutputStream()

Open an output stream on this transport.

nsIOutputStream openOutputStream(
  in unsigned long aFlags,
  in unsigned long aSegmentSize,
  in unsigned long aSegmentCount
);
Parameters
aFlags
Optional transport specific flags.

Flags have the following meaning:

OPEN_BLOCKING If specified, then the resulting stream will have blocking stream semantics. This means that if the stream is full and is not closed, then writing to it will block the calling thread until ALL of the data can be written or until the stream is closed. If this flag is NOT specified, then the stream has non-blocking stream semantics. This means that if the stream is full and is not closed, then writing to it returns NS_BASE_STREAM_WOULD_BLOCK. In addition, in non- blocking mode, the stream is guaranteed to support nsIAsyncOutputStream. This interface allows the consumer of the stream to be notified when the stream can again accept more data.

OPEN_UNBUFFERED If specified, the resulting stream may not support WriteSegments and WriteFrom. WriteSegments and WriteFrom are only guaranteed to be implemented when this flag is NOT specified.

aSegmentSize
If OPEN_UNBUFFERED is not set, then this parameter specifies the size of each buffer segment (pass 0 to use default value).
aSegmentCount
If OPEN_UNBUFFERED is not set, then this parameter specifies the maximum number of buffer segments (pass 0 to use default value).
Return value

 

setEventSink()

Set the transport event sink.

void setEventSink(
  in nsITransportEventSink aSink,
  in nsIEventTarget aEventTarget
);
Parameters
aSink
Receives transport layer notifications.
aEventTarget
Indicates the event target to which the notifications should be delivered. If null, then the notifications may occur on any thread.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:64 次

字数:8297

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文