netwerk/base/public/nsIUDPSocket.idl

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial