Bug 1845134 - Part 4: Update existing ui-icons to use the latest source from acorn...
[gecko.git] / netwerk / base / nsIUDPSocket.idl
blob41bd0ebc1764df17350f9eb522f13d55fe3f805b
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 nsINetAddr;
9 interface nsIUDPSocketListener;
10 interface nsIUDPSocketSyncListener;
11 interface nsIUDPMessage;
12 interface nsISocketTransport;
13 interface nsIOutputStream;
14 interface nsIInputStream;
15 interface nsIPrincipal;
17 %{ C++
18 #include "nsTArrayForwardDeclare.h"
19 namespace mozilla {
20 namespace net {
21 union NetAddr;
25 native NetAddr(mozilla::net::NetAddr);
26 [ptr] native NetAddrPtr(mozilla::net::NetAddr);
27 [ref] native Uint8TArrayRef(FallibleTArray<uint8_t>);
29 /**
30 * nsIUDPSocket
32 * An interface to a UDP socket that can accept incoming connections.
34 [scriptable, uuid(d423bf4e-4499-40cf-bc03-153e2bf206d1)]
35 interface nsIUDPSocket : nsISupports
37 /**
38 * init
40 * This method initializes a UDP socket.
42 * @param aPort
43 * The port of the UDP socket. Pass -1 to indicate no preference,
44 * and a port will be selected automatically.
45 * @param aLoopbackOnly
46 * If true, the UDP socket will only respond to connections on the
47 * local loopback interface. Otherwise, it will accept connections
48 * from any interface. To specify a particular network interface,
49 * use initWithAddress.
50 * @param aPrincipal
51 * The principal connected to this socket.
52 * @param aAddressReuse
53 * If true, the socket is allowed to be bound to an address that is
54 * already in use. Default is true.
56 [optional_argc] void init(in long aPort,
57 in boolean aLoopbackOnly,
58 in nsIPrincipal aPrincipal,
59 [optional] in boolean aAddressReuse);
61 [optional_argc] void init2(in AUTF8String aAddr,
62 in long aPort,
63 in nsIPrincipal aPrincipal,
64 [optional] in boolean aAddressReuse);
66 /**
67 * initWithAddress
69 * This method initializes a UDP socket, and binds it to a particular
70 * local address (and hence a particular local network interface).
72 * @param aAddr
73 * The address to which this UDP socket should be bound.
74 * @param aPrincipal
75 * The principal connected to this socket.
76 * @param aAddressReuse
77 * If true, the socket is allowed to be bound to an address that is
78 * already in use. Default is true.
80 [noscript, optional_argc] void initWithAddress([const] in NetAddrPtr aAddr,
81 in nsIPrincipal aPrincipal,
82 [optional] in boolean aAddressReuse);
84 /**
85 * close
87 * This method closes a UDP socket. This does not affect already
88 * connected client sockets (i.e., the nsISocketTransport instances
89 * created from this UDP socket). This will cause the onStopListening
90 * event to asynchronously fire with a status of NS_BINDING_ABORTED.
92 void close();
94 /**
95 * asyncListen
97 * This method puts the UDP socket in the listening state. It will
98 * asynchronously listen for and accept client connections. The listener
99 * will be notified once for each client connection that is accepted. The
100 * listener's onSocketAccepted method will be called on the same thread
101 * that called asyncListen (the calling thread must have a nsIEventTarget).
103 * The listener will be passed a reference to an already connected socket
104 * transport (nsISocketTransport). See below for more details.
106 * @param aListener
107 * The listener to be notified when client connections are accepted.
109 void asyncListen(in nsIUDPSocketListener aListener);
112 * This adds a nsIUDPSocketSyncListener listener (defined below).
113 * When data is available onPacketReceived is called and the lisener uses
114 * recvWithAddr to actually retrive data from the socket.
115 * The listener can be use only if it runs on the socket thread.
116 * If it is used off the socket thread there is a risk of triggering a bug
117 * in OS thatcan cause a crash.
119 void syncListen(in nsIUDPSocketSyncListener aListener);
122 * connect
124 * This method connects the UDP socket to a remote UDP address.
126 * @param aRemoteAddr
127 * The remote address to connect to
129 void connect([const] in NetAddrPtr aAddr);
132 * Returns the local address of this UDP socket
134 readonly attribute nsINetAddr localAddr;
137 * Returns the port of this UDP socket.
139 readonly attribute long port;
142 * Returns the address to which this UDP socket is bound. Since a
143 * UDP socket may be bound to multiple network devices, this address
144 * may not necessarily be specific to a single network device. In the
145 * case of an IP socket, the IP address field would be zerod out to
146 * indicate a UDP socket bound to all network devices. Therefore,
147 * this method cannot be used to determine the IP address of the local
148 * system. See nsIDNSService::myHostName if this is what you need.
150 [noscript] NetAddr getAddress();
153 * send
155 * Send out the datagram to specified remote host and port.
156 * DNS lookup will be triggered.
158 * @param host The remote host name.
159 * @param port The remote port.
160 * @param data The buffer containing the data to be written.
161 * @return number of bytes written. (0 or length of data)
163 unsigned long send(in AUTF8String host, in unsigned short port,
164 in Array<uint8_t> data);
167 * sendWithAddr
169 * Send out the datagram to specified remote host and port.
171 * @param addr The remote host address.
172 * @param data The buffer containing the data to be written.
173 * @return number of bytes written. (0 or length of data)
175 unsigned long sendWithAddr(in nsINetAddr addr,
176 in Array<uint8_t> data);
180 * Receive a datagram.
181 * @param addr The remote host address.
182 * @param data The buffer to store received datagram.
184 [noscript] void recvWithAddr(out NetAddr addr,
185 out Array<uint8_t> data);
188 * sendWithAddress
190 * Send out the datagram to specified remote address and port.
192 * @param addr The remote host address.
193 * @param data The buffer containing the data to be written.
194 * @return number of bytes written. (0 or length of data)
196 [noscript] unsigned long sendWithAddress([const] in NetAddrPtr addr,
197 [array, size_is(length), const] in uint8_t data,
198 in unsigned long length);
201 * sendBinaryStream
203 * Send out the datagram to specified remote address and port.
205 * @param host The remote host name.
206 * @param port The remote port.
207 * @param stream The input stream to be sent. This must be a buffered stream implementation.
209 void sendBinaryStream(in AUTF8String host, in unsigned short port,
210 in nsIInputStream stream);
213 * sendBinaryStreamWithAddress
215 * Send out the datagram to specified remote address and port.
217 * @param addr The remote host address.
218 * @param stream The input stream to be sent. This must be a buffered stream implementation.
220 void sendBinaryStreamWithAddress([const] in NetAddrPtr addr,
221 in nsIInputStream stream);
224 * joinMulticast
226 * Join the multicast group specified by |addr|. You are then able to
227 * receive future datagrams addressed to the group.
229 * @param addr
230 * The multicast group address.
231 * @param iface
232 * The local address of the interface on which to join the group. If
233 * this is not specified, the OS may join the group on all interfaces
234 * or only the primary interface.
236 void joinMulticast(in AUTF8String addr, [optional] in AUTF8String iface);
237 [noscript] void joinMulticastAddr([const] in NetAddr addr,
238 [const, optional] in NetAddrPtr iface);
241 * leaveMulticast
243 * Leave the multicast group specified by |addr|. You will no longer
244 * receive future datagrams addressed to the group.
246 * @param addr
247 * The multicast group address.
248 * @param iface
249 * The local address of the interface on which to leave the group.
250 * If this is not specified, the OS may leave the group on all
251 * interfaces or only the primary interface.
253 void leaveMulticast(in AUTF8String addr, [optional] in AUTF8String iface);
254 [noscript] void leaveMulticastAddr([const] in NetAddr addr,
255 [const, optional] in NetAddrPtr iface);
258 * multicastLoopback
260 * Whether multicast datagrams sent via this socket should be looped back to
261 * this host (assuming this host has joined the relevant group). Defaults
262 * to true.
263 * Note: This is currently write-only.
265 attribute boolean multicastLoopback;
268 * multicastInterface
270 * The interface that should be used for sending future multicast datagrams.
271 * Note: This is currently write-only.
273 attribute AUTF8String multicastInterface;
276 * multicastInterfaceAddr
278 * The interface that should be used for sending future multicast datagrams.
279 * Note: This is currently write-only.
281 [noscript] attribute NetAddr multicastInterfaceAddr;
284 * recvBufferSize
286 * The size of the receive buffer. Default depends on the OS.
288 [noscript] attribute long recvBufferSize;
291 * sendBufferSize
293 * The size of the send buffer. Default depends on the OS.
295 [noscript] attribute long sendBufferSize;
298 * dontFragment
300 * The don't fragment flag.
301 * The socket must be initialized before calling this function.
303 [noscript] attribute boolean dontFragment;
307 * nsIUDPSocketListener
309 * This interface is notified whenever a UDP socket accepts a new connection.
310 * The transport is in the connected state, and read/write streams can be opened
311 * using the normal nsITransport API. The address of the client can be found by
312 * calling the nsISocketTransport::GetAddress method or by inspecting
313 * nsISocketTransport::GetHost, which returns a string representation of the
314 * client's IP address (NOTE: this may be an IPv4 or IPv6 string literal).
316 [scriptable, uuid(2E4B5DD3-7358-4281-B81F-10C62EF39CB5)]
317 interface nsIUDPSocketListener : nsISupports
320 * onPacketReceived
322 * This method is called when a client sends an UDP packet.
324 * @param aSocket
325 * The UDP socket.
326 * @param aMessage
327 * The message.
329 void onPacketReceived(in nsIUDPSocket aSocket,
330 in nsIUDPMessage aMessage);
333 * onStopListening
335 * This method is called when the listening socket stops for some reason.
336 * The UDP socket is effectively dead after this notification.
338 * @param aSocket
339 * The UDP socket.
340 * @param aStatus
341 * The reason why the UDP socket stopped listening. If the
342 * UDP socket was manually closed, then this value will be
343 * NS_BINDING_ABORTED.
345 void onStopListening(in nsIUDPSocket aSocket, in nsresult aStatus);
349 * nsIUDPMessage
351 * This interface is used to encapsulate an incomming UDP message
353 [scriptable, builtinclass, uuid(afdc743f-9cc0-40d8-b442-695dc54bbb74)]
354 interface nsIUDPMessage : nsISupports
357 * Address of the source of the message
359 readonly attribute nsINetAddr fromAddr;
362 * Data of the message
364 readonly attribute ACString data;
367 * Stream to send a response
369 readonly attribute nsIOutputStream outputStream;
372 * Raw Data of the message
374 [implicit_jscontext] readonly attribute jsval rawData;
375 [noscript, notxpcom, nostdcall] Uint8TArrayRef getDataAsTArray();
378 [uuid(99f3d085-3d69-45da-a2c2-a6176af617cb)]
379 interface nsIUDPSocketSyncListener : nsISupports
382 * onPacketReceived
384 * This method is called when a client sends an UDP packet.
386 * @param aSocket
387 * The UDP socket.
388 * @param aMessage
389 * The message.
391 void onPacketReceived(in nsIUDPSocket aSocket);
394 * onStopListening
396 * This method is called when the listening socket stops for some reason.
397 * The UDP socket is effectively dead after this notification.
399 * @param aSocket
400 * The UDP socket.
401 * @param aStatus
402 * The reason why the UDP socket stopped listening. If the
403 * UDP socket was manually closed, then this value will be
404 * NS_BINDING_ABORTED.
406 void onStopListening(in nsIUDPSocket aSocket, in nsresult aStatus);