nsISocketTransportService 编辑
netwerk/base/public/nsISocketTransportService.idl
Scriptable This interface provides a mapping between a socket type and its associated socket provider instance. One could also use the service manager directly. Inherits from: nsISupports
Last changed in Gecko 1.9 (Firefox 3)Implemented by: @mozilla.org/network/socket-transport-service;1
. To create an instance, use:
var socketTransportService = Components.classes["@mozilla.org/network/socket-transport-service;1"] .getService(Components.interfaces.nsISocketTransportService);
Method overview
void attachSocket(in PRFileDescPtr aFd, in nsASocketHandlerPtr aHandler); Native code only! |
nsISocketTransport createTransport( in Array<ACString> aSocketTypes , in AUTF8String aHost, in long aPort, in nsIProxyInfo aProxyInfo); |
void init(); Obsolete since Gecko 1.8 |
void notifyWhenCanAttachSocket(in nsIRunnable aEvent); Native code only! |
void shutdown(); Obsolete since Gecko 1.8 |
Attributes
Attribute | Type | Description |
autodialEnabled | boolean | controls whether or not the socket transport service should poke the autodialer on connection failure. Obsolete since Gecko 1.8 |
Methods
Native code only!attachSocket
Adds a new socket to the list of controlled sockets.
This will fail with the error code NS_ERROR_NOT_AVAILABLE
if the maximum number of sockets is already reached. In this case, the notifyWhenCanAttachSocket()
method should be used.
void attachSocket( in PRFileDescPtr aFd, in nsASocketHandlerPtr aHandler );
Parameters
aFd
- Open file descriptor of the socket to control.
aHandler
- Socket handler that will receive notifications when the socket is ready or detached.
createTransport()
Creates a transport for a specified host and port.
Note: This function can be called from any thread.nsISocketTransport createTransport( in Array<ACString> aSocketTypes, in AUTF8String aHost, in long aPort, in nsIProxyInfo aProxyInfo );
Parameters
aSocketTypes
- Array of socket type strings. Currently
"starttls"
,"ssl"
and"udp"
are supported. Pass an empty array[]
if the default socket type should be used. You do not need to specify the strings"socks"
or"socks4"
, use theaProxyInfo
instead. aHost
- Specifies the target hostname or IP address literal of the peer for this socket.
aPort
- Specifies the target port of the peer for this socket.
aProxyInfo
- Specifies the transport-layer proxy type to use. Set to
null
if no proxy should be used. - For more details on communicating information about proxies like SOCKS (which are transparent to upper protocols), see
nsIProxiedProtocolHandler
,nsIProtocolProxyService
or Proxies in Necko.
Return value
An nsISocketTransport
containing the SocketTransport.
init()
Obsolete since Gecko 1.8 (Firefox 1.5 / Thunderbird 1.5 / SeaMonkey 1.0)void init();
Parameters
None.
Native code only!notifyWhenCanAttachSocket
If the number of sockets reaches the limit, then consumers can be notified when the number of sockets becomes less than the limit. The notification is asynchronous, delivered via the given nsIRunnable
instance on the socket transport thread.
void notifyWhenCanAttachSocket( in nsIRunnable aEvent );
Parameters
aEvent
- Event that will receive the notification when a new socket can be attached.
shutdown()
Obsolete since Gecko 1.8 (Firefox 1.5 / Thunderbird 1.5 / SeaMonkey 1.0)void shutdown();
Parameters
None.
Example
// at first, we need a nsISocketTransportService ....
var transportService =
Components.classes["@mozilla.org/network/socket-transport-service;1"]
.getService(Components.interfaces.nsISocketTransportService);
// ... then it is time to create the transport. It will connect to ...
// ... mozilla.org:2000 with TLS support and default proxy settings
var socket = transportService.createTransport(["starttls"], 1,"mozilla.org", 2000, null);
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论