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