OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 // File-level comment to appease parser. Eventually this will not be necessary. | |
6 | |
7 namespace experimental.socket { | |
8 enum SocketType { | |
9 tcp, | |
10 udp | |
11 }; | |
12 | |
13 // The socket options. | |
14 dictionary CreateOptions { | |
15 // The schema generator does not support dictionaries without any fields. | |
16 // Ignore this field. | |
17 [nodoc] long? dummyValue; | |
18 }; | |
19 | |
20 dictionary CreateInfo { | |
21 // The id of the newly created socket. | |
22 long socketId; | |
23 }; | |
24 | |
25 callback CreateCallback = void (CreateInfo createInfo); | |
26 | |
27 callback ConnectCallback = void (long result); | |
28 | |
29 callback BindCallback = void (long result); | |
30 | |
31 dictionary ReadInfo { | |
32 // The resultCode returned from the underlying read() call. | |
33 long resultCode; | |
34 | |
35 ArrayBuffer data; | |
36 }; | |
37 | |
38 callback ReadCallback = void (ReadInfo readInfo); | |
39 | |
40 dictionary WriteInfo { | |
41 // The number of bytes sent, or a negative error code. | |
42 long bytesWritten; | |
43 }; | |
44 | |
45 callback WriteCallback = void (WriteInfo writeInfo); | |
46 | |
47 dictionary RecvFromInfo { | |
48 // The resultCode returned from the underlying recvfrom() call. | |
49 long resultCode; | |
50 | |
51 ArrayBuffer data; | |
52 | |
53 // The address of the remote machine. | |
54 DOMString address; | |
55 | |
56 long port; | |
57 }; | |
58 | |
59 callback RecvFromCallback = void (RecvFromInfo recvFromInfo); | |
60 | |
61 callback SendToCallback = void (WriteInfo writeInfo); | |
62 | |
63 callback SetKeepAliveCallback = void (boolean result); | |
64 | |
65 callback SetNoDelayCallback = void (boolean result); | |
66 | |
67 interface Functions { | |
68 // Creates a socket of the specified type that will connect to the specified | |
69 // remote machine. | |
70 // |type| : The type of socket to create. Must be <code>tcp</code> or | |
71 // <code>udp</code>. | |
72 // |options| : The socket options. | |
73 // |callback| : Called when the socket has been created. | |
74 static void create(SocketType type, | |
75 optional CreateOptions options, | |
76 CreateCallback callback); | |
77 | |
78 // Destroys the socket. Each socket created should be destroyed after use. | |
79 // |socketId| : The socketId. | |
80 static void destroy(long socketId); | |
81 | |
82 // Connects the socket to the remote machine. | |
83 // |socketId| : The socketId. | |
84 // |hostname| : The hostname or IP address of the remote machine. | |
85 // |port| : The port of the remote machine. | |
86 // |callback| : Called when the connection attempt is complete. | |
87 static void connect(long socketId, | |
88 DOMString hostname, | |
89 long port, | |
90 ConnectCallback callback); | |
91 | |
92 // Binds the local address for socket. Currently, it does not support | |
93 // TCP socket. | |
94 // |socketId| : The socketId. | |
95 // |address| : The address of the local machine. | |
96 // |port| : The port of the local machine. | |
97 // |callback| : Called when the bind attempt is complete. | |
98 static void bind(long socketId, | |
99 DOMString address, | |
100 long port, | |
101 BindCallback callback); | |
102 | |
103 // Disconnects the socket. For UDP sockets, <code>disconnect</code> is a | |
104 // non-operation but is safe to call. | |
105 // |socketId| : The socketId. | |
106 static void disconnect(long socketId); | |
107 | |
108 // Reads data from the given connected socket. | |
109 // |socketId| : The socketId. | |
110 // |bufferSize| : The read buffer size. | |
111 // |callback| : Delivers data that was available to be read without | |
112 // blocking. | |
113 static void read(long socketId, | |
114 optional long bufferSize, | |
115 ReadCallback callback); | |
116 | |
117 // Writes data on the given connected socket. | |
118 // |socketId| : The socketId. | |
119 // |data| : The data to write. | |
120 // |callback| : Called when the write operation completes without blocking | |
121 // or an error occurs. | |
122 static void write(long socketId, | |
123 ArrayBuffer data, | |
124 WriteCallback callback); | |
125 | |
126 // Receives data from the given UDP socket. | |
127 // |socketId| : The socketId. | |
128 // |bufferSize| : The receive buffer size. | |
129 // |callback| : Returns result of the recvFrom operation. | |
130 static void recvFrom(long socketId, | |
131 optional long bufferSize, | |
132 RecvFromCallback callback); | |
133 | |
134 // Sends data on the given UDP socket to the given address and port. | |
135 // |socketId| : The socketId. | |
136 // |data| : The data to write. | |
137 // |address| : The address of the remote machine. | |
138 // |port| : The port of the remote machine. | |
139 // |callback| : Called when the send operation completes without blocking | |
140 // or an error occurs. | |
141 static void sendTo(long socketId, | |
142 ArrayBuffer data, | |
143 DOMString address, | |
144 long port, | |
145 SendToCallback callback); | |
146 | |
147 // Enable/disable keep-alive functionality for a TCP connection. | |
148 // |socketId| : The socketId. | |
149 // |enable| : If true, enable keep-alive functionality. | |
150 // |delay| : Set the delay seconds between the last data packet received | |
151 // and the first keepalive probe. Default is 0. | |
152 // |callback| : Called when the setKeepAlive attempt is complete. | |
153 static void setKeepAlive(long socketId, | |
154 boolean enable, | |
155 optional long delay, | |
156 SetKeepAliveCallback callback); | |
157 | |
158 // Enable/disable Nagle algorithm. | |
159 // |socketId| : The socketId. | |
160 // |noDelay| : If true, disable Nagle algorithm. | |
161 // |callback| : Called when the setNoDelay attempt is complete. | |
162 static void setNoDelay(long socketId, | |
163 boolean noDelay, | |
164 SetNoDelayCallback callback); | |
165 }; | |
166 | |
167 }; | |
OLD | NEW |