OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // File-level comment to appease parser. Eventually this will not be necessary. | 5 // File-level comment to appease parser. Eventually this will not be necessary. |
6 | 6 |
7 [nodoc] namespace experimental.socket { | 7 [nodoc] namespace experimental.socket { |
8 | 8 |
9 // A socket event. | 9 // A socket event. |
10 dictionary SocketEvent { | 10 dictionary SocketEvent { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 dictionary CreateInfo { | 46 dictionary CreateInfo { |
47 // The id of the newly created socket. | 47 // The id of the newly created socket. |
48 long socketId; | 48 long socketId; |
49 }; | 49 }; |
50 | 50 |
51 callback CreateCallback = void (CreateInfo createInfo); | 51 callback CreateCallback = void (CreateInfo createInfo); |
52 | 52 |
53 callback ConnectCallback = void (long result); | 53 callback ConnectCallback = void (long result); |
54 | 54 |
| 55 callback BindCallback = void (long result); |
| 56 |
55 dictionary ReadInfo { | 57 dictionary ReadInfo { |
56 // The resultCode returned from the underlying read() call. | 58 // The resultCode returned from the underlying read() call. |
57 long resultCode; | 59 long resultCode; |
58 | 60 |
59 // The data received. Warning: will probably become a blob or other | 61 // The data received. Warning: will probably become a blob or other |
60 // appropriate binary-friendly type. | 62 // appropriate binary-friendly type. |
61 // TODO(miket): [instanceOf=ArrayBuffer]object data; | 63 // TODO(miket): [instanceOf=ArrayBuffer]object data; |
62 long[] data; | 64 long[] data; |
63 }; | 65 }; |
64 | 66 |
65 callback ReadCallback = void (ReadInfo readInfo); | 67 callback ReadCallback = void (ReadInfo readInfo); |
66 | 68 |
67 dictionary WriteInfo { | 69 dictionary WriteInfo { |
68 // The number of bytes sent, or a negative error code. | 70 // The number of bytes sent, or a negative error code. |
69 long bytesWritten; | 71 long bytesWritten; |
70 }; | 72 }; |
71 | 73 |
72 callback WriteCallback = void (WriteInfo writeInfo); | 74 callback WriteCallback = void (WriteInfo writeInfo); |
73 | 75 |
| 76 dictionary RecvFromInfo { |
| 77 // The data received. Warning: will probably become a blob or other |
| 78 // appropriate binary-friendly type. |
| 79 // TODO(miket): [instanceOf=ArrayBuffer]object data; |
| 80 long[] data; |
| 81 DOMString address; |
| 82 long port; |
| 83 }; |
| 84 |
| 85 callback RecvFromCallback = void (RecvFromInfo recvFromInfo); |
| 86 |
| 87 callback SendToCallback = void (long bytesWritten); |
| 88 |
74 interface Functions { | 89 interface Functions { |
75 // Creates a socket of the specified type that will connect to the specified | 90 // Creates a socket of the specified type that will connect to the specified |
76 // remote machine. | 91 // remote machine. |
77 // |type| : The type of socket to create. Must be <code>tcp</code> or | 92 // |type| : The type of socket to create. Must be <code>tcp</code> or |
78 // <code>udp</code>. | 93 // <code>udp</code>. |
79 // |address| : The address of the remote machine. | |
80 // |port| : The port of the remote machine. | |
81 // |options| : The socket options. | 94 // |options| : The socket options. |
82 // |callback| : Called when the socket has been created. | 95 // |callback| : Called when the socket has been created. |
83 static void create(DOMString type, | 96 static void create(DOMString type, |
84 DOMString address, | |
85 long port, | |
86 optional CreateOptions options, | 97 optional CreateOptions options, |
87 CreateCallback callback); | 98 CreateCallback callback); |
88 | 99 |
89 // Destroys the socket. Each socket created should be destroyed after use. | 100 // Destroys the socket. Each socket created should be destroyed after use. |
90 // |socketId| : The socketId. | 101 // |socketId| : The socketId. |
91 static void destroy(long socketId); | 102 static void destroy(long socketId); |
92 | 103 |
93 // Connects the socket to the remote machine. For UDP sockets, | 104 // Connects the socket to the remote machine. |
94 // <code>connect</code> is a non-operation but is safe to call. | |
95 // |socketId| : The socketId. | 105 // |socketId| : The socketId. |
| 106 // |address| : The address of the remote machine. |
| 107 // |port| : The port of the remote machine. |
96 // |callback| : Called when the connection attempt is complete. | 108 // |callback| : Called when the connection attempt is complete. |
97 static void connect(long socketId, | 109 static void connect(long socketId, |
| 110 DOMString address, |
| 111 long port, |
98 ConnectCallback callback); | 112 ConnectCallback callback); |
99 | 113 |
| 114 // Binds the local address for UDP socket. Currently, it does not support |
| 115 // TCP socket. |
| 116 // |socketId| : The socketId. |
| 117 // |address| : The address of the remote machine. |
| 118 // |port| : The port of the remote machine. |
| 119 // |callback| : Called when the connection attempt is complete. |
| 120 static void bind(long socketId, |
| 121 DOMString address, |
| 122 long port, |
| 123 BindCallback callback); |
| 124 |
100 // Disconnects the socket. For UDP sockets, <code>disconnect</code> is a | 125 // Disconnects the socket. For UDP sockets, <code>disconnect</code> is a |
101 // non-operation but is safe to call. | 126 // non-operation but is safe to call. |
102 // |socketId| : The socketId. | 127 // |socketId| : The socketId. |
103 static void disconnect(long socketId); | 128 static void disconnect(long socketId); |
104 | 129 |
105 // Reads data from the given socket. | 130 // Reads data from the given socket. |
106 // |socketId| : The socketId. | 131 // |socketId| : The socketId. |
107 // |callback| : Delivers data that was available to be read without | 132 // |callback| : Delivers data that was available to be read without |
108 // blocking. | 133 // blocking. |
109 static void read(long socketId, | 134 static void read(long socketId, |
110 ReadCallback callback); | 135 ReadCallback callback); |
111 | 136 |
112 // Writes data on the given socket. | 137 // Writes data on the given socket. |
113 // |socketId| : The socketId. | 138 // |socketId| : The socketId. |
114 // |data| : The data to write. Warning: will probably become a blob or other | 139 // |data| : The data to write. Warning: will probably become a blob or other |
115 // appropriate binary-friendly type. | 140 // appropriate binary-friendly type. |
116 // |callback| : Called when the first of any of the following happens: the | 141 // |callback| : Called when the first of any of the following happens: the |
117 // write operation completes without blocking, the write operation blocked | 142 // write operation completes without blocking, the write operation blocked |
118 // before completion (in which case onEvent() will eventually be called with | 143 // before completion (in which case onEvent() will eventually be called with |
119 // a <code>writeComplete</code> event), or an error occurred. | 144 // a <code>writeComplete</code> event), or an error occurred. |
120 // TODO(miket): [instanceOf=ArrayBuffer]object data; | 145 // TODO(miket): [instanceOf=ArrayBuffer]object data; |
121 static void write(long socketId, | 146 static void write(long socketId, |
122 long[] data, | 147 long[] data, |
123 WriteCallback callback); | 148 WriteCallback callback); |
| 149 |
| 150 // Reads data from the given socket. |
| 151 // |socketId| : The socketId. |
| 152 // |callback| : Delivers data that was available to be read without |
| 153 // blocking. |
| 154 static void recvFrom(long socketId, |
| 155 RecvFromCallback callback); |
| 156 |
| 157 // Writes data on the given socket. |
| 158 // |socketId| : The socketId. |
| 159 // |data| : The data to write. Warning: will probably become a blob or other |
| 160 // appropriate binary-friendly type. |
| 161 // |address| : The address of the remote machine. |
| 162 // |port| : The port of the remote machine. |
| 163 // |callback| : Called when the first of any of the following happens: the |
| 164 // write operation completes without blocking, the write operation blocked |
| 165 // before completion (in which case onEvent() will eventually be called with |
| 166 // a <code>writeComplete</code> event), or an error occurred. |
| 167 static void sendTo(long socketId, |
| 168 long[] data, |
| 169 DOMString address, |
| 170 long port, |
| 171 SendToCallback callback); |
124 }; | 172 }; |
125 | 173 |
126 interface Events { | 174 interface Events { |
127 // Used to pass events back to the socket creator. | 175 // Used to pass events back to the socket creator. |
128 // |event| : The event indicating socket status. | 176 // |event| : The event indicating socket status. |
129 static void onEvent(SocketEvent event); | 177 static void onEvent(SocketEvent event); |
130 }; | 178 }; |
131 | 179 |
132 }; | 180 }; |
OLD | NEW |