summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/api/socket.idl
blob: 3cb999c6248b45c11792c763c70b385be4514f8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

namespace socket {
  enum SocketType {
    tcp,
    udp
  };

  // The socket options.
  dictionary CreateOptions {
  };

  dictionary CreateInfo {
    // The id of the newly created socket.
    long socketId;
  };

  callback CreateCallback = void (CreateInfo createInfo);

  callback ConnectCallback = void (long result);

  callback BindCallback = void (long result);

  callback ListenCallback = void (long result);

  dictionary AcceptInfo {
    long resultCode;
    // The id of the accepted socket.
    long? socketId;
  };

  callback AcceptCallback = void (AcceptInfo acceptInfo);

  dictionary ReadInfo {
    // The resultCode returned from the underlying read() call.
    long resultCode;

    ArrayBuffer data;
  };

  callback ReadCallback = void (ReadInfo readInfo);

  dictionary WriteInfo {
    // The number of bytes sent, or a negative error code.
    long bytesWritten;
  };

  callback WriteCallback = void (WriteInfo writeInfo);

  dictionary RecvFromInfo {
    // The resultCode returned from the underlying recvfrom() call.
    long resultCode;

    ArrayBuffer data;

    // The address of the remote machine.
    DOMString address;

    long port;
  };

  dictionary SocketInfo {
    // The type of the passed socket. This will be <code>tcp</code> or
    // <code>udp</code>.
    SocketType socketType;

    // Whether or not the underlying socket is connected.
    //
    // For <code>tcp</code> sockets, this will remain true even if the remote
    // peer has disconnected. Reading or writing to the socket may then result
    // in an error, hinting that this socket should be disconnected via
    // <code>disconnect()</code>.
    //
    // For <code>udp</code> sockets, this just represents whether a default
    // remote address has been specified for reading and writing packets.
    boolean connected;

    // If the underlying socket is connected, contains the IPv4/6 address of
    // the peer.
    DOMString? peerAddress;

    // If the underlying socket is connected, contains the port of the
    // connected peer.
    long? peerPort;

    // If the underlying socket is bound or connected, contains its local
    // IPv4/6 address.
    DOMString? localAddress;

    // If the underlying socket is bound or connected, contains its local port.
    long? localPort;
  };

  dictionary NetworkInterface {
    // The underlying name of the adapter. On *nix, this will typically be
    // "eth0", "lo", etc.
    DOMString name;

    // The available IPv4/6 address.
    DOMString address;
  };

  callback RecvFromCallback = void (RecvFromInfo recvFromInfo);

  callback SendToCallback = void (WriteInfo writeInfo);

  callback SetKeepAliveCallback = void (boolean result);

  callback SetNoDelayCallback = void (boolean result);

  callback GetInfoCallback = void (SocketInfo result);

  callback GetNetworkCallback = void (NetworkInterface[] result);

  interface Functions {
    // Creates a socket of the specified type that will connect to the specified
    // remote machine.
    // |type| : The type of socket to create. Must be <code>tcp</code> or
    // <code>udp</code>.
    // |options| : The socket options.
    // |callback| : Called when the socket has been created.
    static void create(SocketType type,
                       optional CreateOptions options,
                       CreateCallback callback);

    // Destroys the socket. Each socket created should be destroyed after use.
    // |socketId| : The socketId.
    static void destroy(long socketId);

    // Connects the socket to the remote machine (for a <code>tcp</code>
    // socket). For a <code>udp</code> socket, this sets the default address
    // which packets are sent to and read from for <code>read()</code>
    // and <code>write()</code> calls.
    // |socketId| : The socketId.
    // |hostname| : The hostname or IP address of the remote machine.
    // |port| : The port of the remote machine.
    // |callback| : Called when the connection attempt is complete.
    static void connect(long socketId,
                        DOMString hostname,
                        long port,
                        ConnectCallback callback);

    // Binds the local address for socket. Currently, it does not support
    // TCP socket.
    // |socketId| : The socketId.
    // |address| : The address of the local machine.
    // |port| : The port of the local machine.
    // |callback| : Called when the bind attempt is complete.
    static void bind(long socketId,
                     DOMString address,
                     long port,
                     BindCallback callback);

    // Disconnects the socket. For UDP sockets, <code>disconnect</code> is a
    // non-operation but is safe to call.
    // |socketId| : The socketId.
    static void disconnect(long socketId);

    // Reads data from the given connected socket.
    // |socketId| : The socketId.
    // |bufferSize| : The read buffer size.
    // |callback| : Delivers data that was available to be read without
    // blocking.
    static void read(long socketId,
                     optional long bufferSize,
                     ReadCallback callback);

    // Writes data on the given connected socket.
    // |socketId| : The socketId.
    // |data| : The data to write.
    // |callback| : Called when the write operation completes without blocking
    // or an error occurs.
    static void write(long socketId,
                      ArrayBuffer data,
                      WriteCallback callback);

    // Receives data from the given UDP socket.
    // |socketId| : The socketId.
    // |bufferSize| : The receive buffer size.
    // |callback| : Returns result of the recvFrom operation.
    static void recvFrom(long socketId,
                         optional long bufferSize,
                         RecvFromCallback callback);

    // Sends data on the given UDP socket to the given address and port.
    // |socketId| : The socketId.
    // |data| : The data to write.
    // |address| : The address of the remote machine.
    // |port| : The port of the remote machine.
    // |callback| : Called when the send operation completes without blocking
    // or an error occurs.
    static void sendTo(long socketId,
                       ArrayBuffer data,
                       DOMString address,
                       long port,
                       SendToCallback callback);

    // This method applies to TCP sockets only.
    // Listens for connections on the specified port and address. This
    // effectively makes this a server socket, and client socket
    // functions (connect, read, write) can no longer be used on this socket.
    // |socketId| : The socketId.
    // |address| : The address of the local machine.
    // |port| : The port of the local machine.
    // |backlog| : Length of the socket's listen queue.
    static void listen(long socketId,
                       DOMString address,
                       long port,
                       optional long backlog,
                       ListenCallback callback);

    // This method applies to TCP sockets only.
    // Registers a callback function to be called when a connection is
    // accepted on this listening server socket. Listen must be called first.
    // If there is already an active accept callback, this callback will be
    // invoked immediately with an error as the resultCode.
    // |socketId| : The socketId.
    // |callback| : The callback is invoked when a new socket is accepted.
    static void accept(long socketId,
                       AcceptCallback callback);

    // Enables or disables the keep-alive functionality for a TCP connection.
    // |socketId| : The socketId.
    // |enable| : If true, enable keep-alive functionality.
    // |delay| : Set the delay seconds between the last data packet received
    // and the first keepalive probe. Default is 0.
    // |callback| : Called when the setKeepAlive attempt is complete.
    static void setKeepAlive(long socketId,
                             boolean enable,
                             optional long delay,
                             SetKeepAliveCallback callback);

    // Sets or clears <code>TCP_NODELAY</code> for a TCP connection. Nagle's
    // algorithm will be disabled when <code>TCP_NODELAY</code> is set.
    // |socketId| : The socketId.
    // |noDelay| : If true, disables Nagle's algorithm.
    // |callback| : Called when the setNoDelay attempt is complete.
    static void setNoDelay(long socketId,
                           boolean noDelay,
                           SetNoDelayCallback callback);

    // Retrieves the state of the given socket.
    // |socketId| : The socketId.
    // |callback| : Called when the state is available.
    static void getInfo(long socketId,
                        GetInfoCallback callback);

    // Retrieves information about local adapters on this system.
    // |callback| : Called when local adapter information is available.
    static void getNetworkList(GetNetworkCallback callback);
  };

};