Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* vim:set ts=4 sw=4 et cindent: */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsISupports.idl"
8 interface nsIFile;
9 interface nsIServerSocketListener;
10 interface nsISocketTransport;
12 native PRNetAddr(union PRNetAddr);
13 [ptr] native PRNetAddrPtr(union PRNetAddr);
15 typedef unsigned long nsServerSocketFlag;
17 /**
18 * nsIServerSocket
19 *
20 * An interface to a server socket that can accept incoming connections.
21 */
22 [scriptable, uuid(7a9c39cb-a13f-4eef-9bdf-a74301628742)]
23 interface nsIServerSocket : nsISupports
24 {
25 /**
26 * @name Server Socket Flags
27 * These flags define various socket options.
28 * @{
29 */
30 /// The server socket will only respond to connections on the
31 /// local loopback interface. Otherwise, it will accept connections
32 /// from any interface. To specify a particular network interface,
33 /// use initWithAddress.
34 const nsServerSocketFlag LoopbackOnly = 0x00000001;
35 /// The server socket will not be closed when Gecko is set
36 /// offline.
37 const nsServerSocketFlag KeepWhenOffline = 0x00000002;
38 /** @} */
40 /**
41 * init
42 *
43 * This method initializes a server socket.
44 *
45 * @param aPort
46 * The port of the server socket. Pass -1 to indicate no preference,
47 * and a port will be selected automatically.
48 * @param aLoopbackOnly
49 * If true, the server socket will only respond to connections on the
50 * local loopback interface. Otherwise, it will accept connections
51 * from any interface. To specify a particular network interface,
52 * use initWithAddress.
53 * @param aBackLog
54 * The maximum length the queue of pending connections may grow to.
55 * This parameter may be silently limited by the operating system.
56 * Pass -1 to use the default value.
57 */
58 void init(in long aPort,
59 in boolean aLoopbackOnly,
60 in long aBackLog);
62 /**
63 * initSpecialConnection
64 *
65 * This method initializes a server socket and offers the ability to have
66 * that socket not get terminated if Gecko is set offline.
67 *
68 * @param aPort
69 * The port of the server socket. Pass -1 to indicate no preference,
70 * and a port will be selected automatically.
71 * @param aFlags
72 * Flags for the socket.
73 * @param aBackLog
74 * The maximum length the queue of pending connections may grow to.
75 * This parameter may be silently limited by the operating system.
76 * Pass -1 to use the default value.
77 */
78 void initSpecialConnection(in long aPort,
79 in nsServerSocketFlag aFlags,
80 in long aBackLog);
83 /**
84 * initWithAddress
85 *
86 * This method initializes a server socket, and binds it to a particular
87 * local address (and hence a particular local network interface).
88 *
89 * @param aAddr
90 * The address to which this server socket should be bound.
91 * @param aBackLog
92 * The maximum length the queue of pending connections may grow to.
93 * This parameter may be silently limited by the operating system.
94 * Pass -1 to use the default value.
95 */
96 [noscript] void initWithAddress([const] in PRNetAddrPtr aAddr, in long aBackLog);
98 /**
99 * initWithFilename
100 *
101 * This method initializes a Unix domain or "local" server socket. Such
102 * a socket has a name in the filesystem, like an ordinary file. To
103 * connect, a client supplies the socket's filename, and the usual
104 * permission checks on socket apply.
105 *
106 * This makes Unix domain sockets useful for communication between the
107 * programs being run by a specific user on a single machine: the
108 * operating system takes care of authentication, and the user's home
109 * directory or profile directory provide natural per-user rendezvous
110 * points.
111 *
112 * Since Unix domain sockets are always local to the machine, they are
113 * not affected by the nsIIOService's 'offline' flag.
114 *
115 * The system-level socket API may impose restrictions on the length of
116 * the filename that are stricter than those of the underlying
117 * filesystem. If the file name is too long, this returns
118 * NS_ERROR_FILE_NAME_TOO_LONG.
119 *
120 * All components of the path prefix of |aPath| must name directories;
121 * otherwise, this returns NS_ERROR_FILE_NOT_DIRECTORY.
122 *
123 * This call requires execute permission on all directories containing
124 * the one in which the socket is to be created, and write and execute
125 * permission on the directory itself. Otherwise, this returns
126 * NS_ERROR_CONNECTION_REFUSED.
127 *
128 * This call creates the socket's directory entry. There must not be
129 * any existing entry with the given name. If there is, this returns
130 * NS_ERROR_SOCKET_ADDRESS_IN_USE.
131 *
132 * On systems that don't support Unix domain sockets at all, this
133 * returns NS_ERROR_SOCKET_ADDRESS_NOT_SUPPORTED.
134 *
135 * @param aPath nsIFile
136 * The file name at which the socket should be created.
137 *
138 * @param aPermissions unsigned long
139 * Unix-style permission bits to be applied to the new socket.
140 *
141 * Note about permissions: Linux's unix(7) man page claims that some
142 * BSD-derived systems ignore permissions on UNIX-domain sockets;
143 * NetBSD's bind(2) man page agrees, but says it does check now (dated
144 * 2005). POSIX has required 'connect' to fail if write permission on
145 * the socket itself is not granted since 2003 (Issue 6). NetBSD says
146 * that the permissions on the containing directory (execute) have
147 * always applied, so creating sockets in appropriately protected
148 * directories should be secure on both old and new systems.
149 */
150 void initWithFilename(in nsIFile aPath, in unsigned long aPermissions,
151 in long aBacklog);
153 /**
154 * close
155 *
156 * This method closes a server socket. This does not affect already
157 * connected client sockets (i.e., the nsISocketTransport instances
158 * created from this server socket). This will cause the onStopListening
159 * event to asynchronously fire with a status of NS_BINDING_ABORTED.
160 */
161 void close();
163 /**
164 * asyncListen
165 *
166 * This method puts the server socket in the listening state. It will
167 * asynchronously listen for and accept client connections. The listener
168 * will be notified once for each client connection that is accepted. The
169 * listener's onSocketAccepted method will be called on the same thread
170 * that called asyncListen (the calling thread must have a nsIEventTarget).
171 *
172 * The listener will be passed a reference to an already connected socket
173 * transport (nsISocketTransport). See below for more details.
174 *
175 * @param aListener
176 * The listener to be notified when client connections are accepted.
177 */
178 void asyncListen(in nsIServerSocketListener aListener);
180 /**
181 * Returns the port of this server socket.
182 */
183 readonly attribute long port;
185 /**
186 * Returns the address to which this server socket is bound. Since a
187 * server socket may be bound to multiple network devices, this address
188 * may not necessarily be specific to a single network device. In the
189 * case of an IP socket, the IP address field would be zerod out to
190 * indicate a server socket bound to all network devices. Therefore,
191 * this method cannot be used to determine the IP address of the local
192 * system. See nsIDNSService::myHostName if this is what you need.
193 */
194 [noscript] PRNetAddr getAddress();
195 };
197 /**
198 * nsIServerSocketListener
199 *
200 * This interface is notified whenever a server socket accepts a new connection.
201 * The transport is in the connected state, and read/write streams can be opened
202 * using the normal nsITransport API. The address of the client can be found by
203 * calling the nsISocketTransport::GetAddress method or by inspecting
204 * nsISocketTransport::GetHost, which returns a string representation of the
205 * client's IP address (NOTE: this may be an IPv4 or IPv6 string literal).
206 */
207 [scriptable, uuid(836d98ec-fee2-4bde-b609-abd5e966eabd)]
208 interface nsIServerSocketListener : nsISupports
209 {
210 /**
211 * onSocketAccepted
212 *
213 * This method is called when a client connection is accepted.
214 *
215 * @param aServ
216 * The server socket.
217 * @param aTransport
218 * The connected socket transport.
219 */
220 void onSocketAccepted(in nsIServerSocket aServ,
221 in nsISocketTransport aTransport);
223 /**
224 * onStopListening
225 *
226 * This method is called when the listening socket stops for some reason.
227 * The server socket is effectively dead after this notification.
228 *
229 * @param aServ
230 * The server socket.
231 * @param aStatus
232 * The reason why the server socket stopped listening. If the
233 * server socket was manually closed, then this value will be
234 * NS_BINDING_ABORTED.
235 */
236 void onStopListening(in nsIServerSocket aServ, in nsresult aStatus);
237 };