netwerk/base/public/nsIServerSocket.idl

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial