netwerk/base/public/nsIUDPSocket.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 nsINetAddr;
michael@0 9 interface nsIUDPSocketListener;
michael@0 10 interface nsIUDPMessage;
michael@0 11 interface nsISocketTransport;
michael@0 12 interface nsIOutputStream;
michael@0 13
michael@0 14 %{ C++
michael@0 15 #include "nsTArrayForwardDeclare.h"
michael@0 16 namespace mozilla {
michael@0 17 namespace net {
michael@0 18 union NetAddr;
michael@0 19 }
michael@0 20 }
michael@0 21 %}
michael@0 22 native NetAddr(mozilla::net::NetAddr);
michael@0 23 [ptr] native NetAddrPtr(mozilla::net::NetAddr);
michael@0 24 [ref] native Uint8TArrayRef(FallibleTArray<uint8_t>);
michael@0 25
michael@0 26 /**
michael@0 27 * nsIUDPSocket
michael@0 28 *
michael@0 29 * An interface to a UDP socket that can accept incoming connections.
michael@0 30 */
michael@0 31 [scriptable, uuid(6EFE692D-F0B0-4A9E-9E63-837C7452446D)]
michael@0 32 interface nsIUDPSocket : nsISupports
michael@0 33 {
michael@0 34 /**
michael@0 35 * init
michael@0 36 *
michael@0 37 * This method initializes a UDP socket.
michael@0 38 *
michael@0 39 * @param aPort
michael@0 40 * The port of the UDP socket. Pass -1 to indicate no preference,
michael@0 41 * and a port will be selected automatically.
michael@0 42 * @param aLoopbackOnly
michael@0 43 * If true, the UDP socket will only respond to connections on the
michael@0 44 * local loopback interface. Otherwise, it will accept connections
michael@0 45 * from any interface. To specify a particular network interface,
michael@0 46 * use initWithAddress.
michael@0 47 */
michael@0 48 void init(in long aPort, in boolean aLoopbackOnly);
michael@0 49
michael@0 50 /**
michael@0 51 * initWithAddress
michael@0 52 *
michael@0 53 * This method initializes a UDP socket, and binds it to a particular
michael@0 54 * local address (and hence a particular local network interface).
michael@0 55 *
michael@0 56 * @param aAddr
michael@0 57 * The address to which this UDP socket should be bound.
michael@0 58 */
michael@0 59 [noscript] void initWithAddress([const] in NetAddrPtr aAddr);
michael@0 60
michael@0 61 /**
michael@0 62 * close
michael@0 63 *
michael@0 64 * This method closes a UDP socket. This does not affect already
michael@0 65 * connected client sockets (i.e., the nsISocketTransport instances
michael@0 66 * created from this UDP socket). This will cause the onStopListening
michael@0 67 * event to asynchronously fire with a status of NS_BINDING_ABORTED.
michael@0 68 */
michael@0 69 void close();
michael@0 70
michael@0 71 /**
michael@0 72 * asyncListen
michael@0 73 *
michael@0 74 * This method puts the UDP socket in the listening state. It will
michael@0 75 * asynchronously listen for and accept client connections. The listener
michael@0 76 * will be notified once for each client connection that is accepted. The
michael@0 77 * listener's onSocketAccepted method will be called on the same thread
michael@0 78 * that called asyncListen (the calling thread must have a nsIEventTarget).
michael@0 79 *
michael@0 80 * The listener will be passed a reference to an already connected socket
michael@0 81 * transport (nsISocketTransport). See below for more details.
michael@0 82 *
michael@0 83 * @param aListener
michael@0 84 * The listener to be notified when client connections are accepted.
michael@0 85 */
michael@0 86 void asyncListen(in nsIUDPSocketListener aListener);
michael@0 87
michael@0 88 /**
michael@0 89 * Returns the port of this UDP socket.
michael@0 90 */
michael@0 91 readonly attribute long port;
michael@0 92
michael@0 93 /**
michael@0 94 * Returns the address to which this UDP socket is bound. Since a
michael@0 95 * UDP socket may be bound to multiple network devices, this address
michael@0 96 * may not necessarily be specific to a single network device. In the
michael@0 97 * case of an IP socket, the IP address field would be zerod out to
michael@0 98 * indicate a UDP socket bound to all network devices. Therefore,
michael@0 99 * this method cannot be used to determine the IP address of the local
michael@0 100 * system. See nsIDNSService::myHostName if this is what you need.
michael@0 101 */
michael@0 102 [noscript] NetAddr getAddress();
michael@0 103
michael@0 104 /**
michael@0 105 * send
michael@0 106 *
michael@0 107 * Send out the datagram to specified remote host and port.
michael@0 108 * DNS lookup will be triggered.
michael@0 109 *
michael@0 110 * @param host The remote host name.
michael@0 111 * @param port The remote port.
michael@0 112 * @param data The buffer containing the data to be written.
michael@0 113 * @param dataLength The maximum number of bytes to be written.
michael@0 114 * @return number of bytes written. (0 or dataLength)
michael@0 115 */
michael@0 116 unsigned long send(in AUTF8String host, in unsigned short port,
michael@0 117 [const, array, size_is(dataLength)]in uint8_t data,
michael@0 118 in unsigned long dataLength);
michael@0 119
michael@0 120 /**
michael@0 121 * sendWithAddr
michael@0 122 *
michael@0 123 * Send out the datagram to specified remote host and port.
michael@0 124 *
michael@0 125 * @param addr The remote host address.
michael@0 126 * @param data The buffer containing the data to be written.
michael@0 127 * @param dataLength The maximum number of bytes to be written.
michael@0 128 * @return number of bytes written. (0 or dataLength)
michael@0 129 */
michael@0 130 unsigned long sendWithAddr(in nsINetAddr addr,
michael@0 131 [const, array, size_is(dataLength)]in uint8_t data,
michael@0 132 in unsigned long dataLength);
michael@0 133
michael@0 134 /**
michael@0 135 * sendWithAddress
michael@0 136 *
michael@0 137 * Send out the datagram to specified remote address and port.
michael@0 138 *
michael@0 139 * @param addr The remote host address.
michael@0 140 * @param data The buffer containing the data to be written.
michael@0 141 * @param dataLength The maximum number of bytes to be written.
michael@0 142 * @return number of bytes written. (0 or dataLength)
michael@0 143 */
michael@0 144 [noscript] unsigned long sendWithAddress([const] in NetAddrPtr addr,
michael@0 145 [const, array, size_is(dataLength)]in uint8_t data,
michael@0 146 in unsigned long dataLength);
michael@0 147 };
michael@0 148
michael@0 149 /**
michael@0 150 * nsIUDPSocketListener
michael@0 151 *
michael@0 152 * This interface is notified whenever a UDP socket accepts a new connection.
michael@0 153 * The transport is in the connected state, and read/write streams can be opened
michael@0 154 * using the normal nsITransport API. The address of the client can be found by
michael@0 155 * calling the nsISocketTransport::GetAddress method or by inspecting
michael@0 156 * nsISocketTransport::GetHost, which returns a string representation of the
michael@0 157 * client's IP address (NOTE: this may be an IPv4 or IPv6 string literal).
michael@0 158 */
michael@0 159 [scriptable, uuid(2E4B5DD3-7358-4281-B81F-10C62EF39CB5)]
michael@0 160 interface nsIUDPSocketListener : nsISupports
michael@0 161 {
michael@0 162 /**
michael@0 163 * onPacketReceived
michael@0 164 *
michael@0 165 * This method is called when a client sends an UDP packet.
michael@0 166 *
michael@0 167 * @param aSocket
michael@0 168 * The UDP socket.
michael@0 169 * @param aMessage
michael@0 170 * The message.
michael@0 171 */
michael@0 172 void onPacketReceived(in nsIUDPSocket aSocket,
michael@0 173 in nsIUDPMessage aMessage);
michael@0 174
michael@0 175 /**
michael@0 176 * onStopListening
michael@0 177 *
michael@0 178 * This method is called when the listening socket stops for some reason.
michael@0 179 * The UDP socket is effectively dead after this notification.
michael@0 180 *
michael@0 181 * @param aSocket
michael@0 182 * The UDP socket.
michael@0 183 * @param aStatus
michael@0 184 * The reason why the UDP socket stopped listening. If the
michael@0 185 * UDP socket was manually closed, then this value will be
michael@0 186 * NS_BINDING_ABORTED.
michael@0 187 */
michael@0 188 void onStopListening(in nsIUDPSocket aSocket, in nsresult aStatus);
michael@0 189 };
michael@0 190
michael@0 191 /**
michael@0 192 * nsIUDPMessage
michael@0 193 *
michael@0 194 * This interface is used to encapsulate an incomming UDP message
michael@0 195 */
michael@0 196 [scriptable, uuid(afdc743f-9cc0-40d8-b442-695dc54bbb74)]
michael@0 197 interface nsIUDPMessage : nsISupports
michael@0 198 {
michael@0 199 /**
michael@0 200 * Address of the source of the message
michael@0 201 */
michael@0 202 readonly attribute nsINetAddr fromAddr;
michael@0 203
michael@0 204 /**
michael@0 205 * Data of the message
michael@0 206 */
michael@0 207 readonly attribute ACString data;
michael@0 208
michael@0 209 /**
michael@0 210 * Stream to send a response
michael@0 211 */
michael@0 212 readonly attribute nsIOutputStream outputStream;
michael@0 213
michael@0 214 /**
michael@0 215 * Raw Data of the message
michael@0 216 */
michael@0 217 [implicit_jscontext] readonly attribute jsval rawData;
michael@0 218 [noscript, notxpcom, nostdcall] Uint8TArrayRef getDataAsTArray();
michael@0 219 };

mercurial