nsISocketTransportService 编辑

netwerk/base/public/nsISocketTransportService.idlScriptable 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

AttributeTypeDescription
autodialEnabledbooleancontrols 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.

Note: This function may only be called from an event dispatch on the socket thread.
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 the aProxyInfo 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.

Note: This function may only be called from an event dispatch on the socket 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 技术交流群。

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

发布评论

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

词条统计

浏览:44 次

字数:7848

最后编辑:6年前

编辑次数:0 次

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