nsISocketTransport 编辑
netwerk/base/public/nsISocketTransport.idl
Scriptable This interface specializes nsITransport
for communication over network sockets. It provides methods to open blocking or non-blocking, buffered or unbuffered streams between two end-point in a IP based network. Inherits from: nsITransport
Last changed in Gecko 6.0 (Firefox 6.0 / Thunderbird 6.0 / SeaMonkey 2.3) Note: Connection setup is triggered by opening an input or output stream, it does not start on its own. Completion of the connection setup is indicated by a STATUS_CONNECTED_TO
notification to the event sink (if set).To create an instance, call nsISocketTransportService.createTransport()
Method overview
PRNetAddr getPeerAddr(); Native code only! |
PRNetAddr getSelfAddr(); Native code only! |
unsigned long getTimeout(in unsigned long aType); |
boolean isAlive(); |
void setTimeout(in unsigned long aType, in unsigned long aValue); |
Attributes
Attribute | Type | Description |
connectionFlags | unsigned long | A bitmask that can be used to modify underlying behavior of the socket connection. See Connection Flag Constants for more details. |
host | AUTF8String | Get the host for the underlying socket connection. Read only. |
port | long | Get the port for the underlying socket connection. Read only. |
securityCallbacks | nsIInterfaceRequestor | Security notification callbacks passed to the secure socket provider via |
securityInfo | nsISupports | Security info object returned from the secure socket provider. This object supports |
Constants
Timeout type
This constants are used by getTransport()
and setTransport()
to specify socket timeouts
Constant | Value | Description |
TIMEOUT_CONNECT | 0 | Connecting timeout. |
TIMEOUT_READ_WRITE | 1 | Read and write timeouts. |
nsITransportEventSink status codes
Note: Although these constants look like XPCOM error codes and are passed in an nsresult variable, they are not error codes. They do overlap with existing error codes in Necko, these status codes are confined within a very limited context where no error codes may appear, so there is no ambiguity. The values of these status codes must never change.The status codes appear in near-chronological order (not in numeric order). STATUS_RESOLVING
may be skipped if the host does not need to be resolved. STATUS_WAITING_FOR
is an optional status code, which the implementation of this interface may choose not to generate.
Constant | Value | Description |
STATUS_RESOLVING | 0x804b0003 | Transport is resolving the host. Usually a DNS lookup. |
STATUS_RESOLVED | 0x804b000b | Transport has resolved the host. |
STATUS_CONNECTING_TO | 0x804b0007 | |
STATUS_CONNECTED_TO | 0x804b0004 | |
STATUS_SENDING_TO | 0x804b0005 | |
STATUS_WAITING_FOR | 0x804b000a | |
STATUS_RECEIVING_FROM | 0x804b0006 |
Connection flags
Values for the connectionFlags
attribute
Constant | Value | Description |
BYPASS_CACHE | 0 | When making a new connection BYPASS_CACHE will force the Necko DNS cache entry to be refreshed with a new call to NSPR if it is set before opening the new stream. |
ANONYMOUS_CONNECT | 1 | When this flag is set, the socket will not apply any credentials when establishing a connection. For example, an SSL connection would not send any client-certificates if this flag is set. |
DISABLE_IPV6 | 2 | When this flag is set, the socket will ignore any IPv6 addresses the host may offer and will only attempt to connect to IPv4 addresses. |
Methods
Native code only!getPeerAddr
Returns the IP address of the socket connection peer. This attribute is defined only once a connection has been established.
PRNetAddr getPeerAddr();
Parameters
None.
Return value
An PRNetAddr
containing the resolved IP address.
getSelfAddr
Returns the IP address of the initiating end. This attribute is defined only once a connection has been established.
PRNetAddr getSelfAddr();
Parameters
None.
Return value
An PRNetAddr
containing the resolved IP address.
getTimeout()
Retrieves a Socket timeout.
unsigned long getTimeout( in unsigned long aType );
Parameters
aType
- The timeout type, who's associated value should be retrieved. Can be one of the constants
TIMEOUT_CONNECT
orTIMEOUT_READ_WRITE
.
Return value
Returns the timeout in seconds for the given Type. A value of PR_UINT32_MAX
is equivalent to no timeout.
isAlive()
Test if this socket transport is (still) connected.
boolean isAlive();
Parameters
None.
Return value
Returns true
if the socket is connected. Otherwise false
.
setTimeout()
Sets a Socket timeout.
void setTimeout( in unsigned long aType, in unsigned long aValue );
Parameters
aType
- The timeout type which should be set to
aValue
. Can be one of the constantsTIMEOUT_CONNECT
orTIMEOUT_READ_WRITE
. aValue
- Defines the timeout in seconds, pass
PR_UINT32_MAX
to specify no timeout. The implementation may truncate timeout values to a smaller range of values (for example, 0 to 0xFFFF).
Remarks
This is a free-threaded interface, meaning that the methods on this interface may be called from any thread.
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论