OLD | NEW |
(Empty) | |
| 1 [nodoc] namespace experimental.socket { |
| 2 |
| 3 // A socket event. |
| 4 dictionary SocketEvent { |
| 5 // A connectComplete event reports the result of a connect that blocked. A |
| 6 // writeComplete event reports the result of a write that blocked. A |
| 7 // dataRead event reports bytes that have arrived following a read call that |
| 8 // blocked. |
| 9 DOMString type; |
| 10 |
| 11 // The result code, if the event type is writeComplete. The result code |
| 12 // description matches that of <code>writeInfo.bytesWritten</code>. |
| 13 long? resultCode; |
| 14 |
| 15 // The data read, if the event type is dataRead. |
| 16 DOMString? data; |
| 17 |
| 18 // Whether this is the final event that this socket will send. |
| 19 [nodoc] boolean isFinalEvent; |
| 20 |
| 21 // An ID unique to the calling function's context so that events can get |
| 22 // routed back to the correct callback. |
| 23 [nodoc] long? srcId; |
| 24 }; |
| 25 |
| 26 callback OnEventCallback = void (SocketEvent event); |
| 27 |
| 28 // The socket options. |
| 29 dictionary CreateOptions { |
| 30 // This function is called with events that occur during the lifetime of the |
| 31 // socket. |
| 32 OnEventCallback? onEvent; |
| 33 }; |
| 34 |
| 35 dictionary CreateCallbackSocketInfo { |
| 36 // The id of the newly created socket. |
| 37 long socketId; |
| 38 }; |
| 39 |
| 40 callback CreateCallback = void (CreateCallbackSocketInfo socketInfo); |
| 41 |
| 42 callback ConnectCallback = void (long result); |
| 43 |
| 44 dictionary ReadCallbackReadInfo { |
| 45 // The data received. Warning: will probably become a blob or other |
| 46 // appropriate binary-friendly type. |
| 47 DOMString message; |
| 48 }; |
| 49 |
| 50 callback ReadCallback = void (ReadCallbackReadInfo readInfo); |
| 51 |
| 52 dictionary WriteCallbackWriteInfo { |
| 53 // The number of bytes sent, or a negative error code. |
| 54 long bytesWritten; |
| 55 }; |
| 56 |
| 57 callback WriteCallback = void (WriteCallbackWriteInfo writeInfo); |
| 58 |
| 59 interface Functions { |
| 60 // Creates a socket of the specified type that will connect to the specified |
| 61 // remote machine. |
| 62 // |type| : The type of socket to create. Must be <code>tcp</code> or |
| 63 // <code>udp</code>. |
| 64 // |address| : The address of the remote machine. |
| 65 // |port| : The port of the remote machine. |
| 66 // |options| : The socket options. |
| 67 // |callback| : Called when the socket has been created. |
| 68 static void create(DOMString type, |
| 69 DOMString address, |
| 70 long port, |
| 71 optional CreateOptions options, |
| 72 CreateCallback callBack); |
| 73 |
| 74 // Destroys the socket. Each socket created should be destroyed after use. |
| 75 // |socketId| : The socketId. |
| 76 static void destroy(long socketId); |
| 77 |
| 78 // Connects the socket to the remote machine. For UDP sockets, |
| 79 // <code>connect</code> is a non-operation but is safe to call. |
| 80 // |socketId| : The socketId. |
| 81 // |callback| : Called when the connection attempt is complete. |
| 82 static void connect(long socketId, |
| 83 ConnectCallback callBack); |
| 84 |
| 85 // Disconnects the socket. For UDP sockets, <code>disconnect</code> is a |
| 86 // non-operation but is safe to call. |
| 87 // |socketId| : The socketId. |
| 88 static void disconnect(long socketId); |
| 89 |
| 90 // Reads data from the given socket. |
| 91 // |socketId| : The socketId. |
| 92 // |callback| : Delivers data that was available to be read without |
| 93 // blocking. |
| 94 static void read(long socketId, |
| 95 ReadCallback callBack); |
| 96 |
| 97 // Writes data on the given socket. |
| 98 // |socketId| : The socketId. |
| 99 // |data| : The data to write. Warning: will probably become a blob or other |
| 100 // appropriate binary-friendly type. |
| 101 // |callback| : Called when the first of any of the following happens: the |
| 102 // write operation completes without blocking, the write operation blocked |
| 103 // before completion (in which case onEvent() will eventually be called with |
| 104 // a <code>writeComplete</code> event), or an error occurred. |
| 105 static void write(long socketId, |
| 106 DOMString data, |
| 107 WriteCallback callBack); |
| 108 }; |
| 109 |
| 110 interface Events { |
| 111 // Used to pass events back to the socket creator. |
| 112 // |event| : The event indicating socket status. |
| 113 static void onEvent(SocketEvent event); |
| 114 }; |
| 115 |
| 116 }; |
OLD | NEW |