OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 module mojo; | 5 module mojo; |
6 | 6 |
7 import "network/public/interfaces/net_address.mojom"; | 7 import "network/public/interfaces/net_address.mojom"; |
8 import "network/public/interfaces/network_error.mojom"; | 8 import "network/public/interfaces/network_error.mojom"; |
9 | 9 |
10 // UDPSocket and UDPSocketClient represent a UDP socket and its client. The | 10 // UDPSocket and UDPSocketReceiver represent a UDP socket and its client. The |
11 // typical flow of using the interfaces is: | 11 // typical flow of using the interfaces is: |
12 // - Acquire a UDPSocket interface pointer and set a UDPSocketClient instance. | 12 // - Acquire a UDPSocket interface pointer. |
13 // - (optional) Set options which are allowed prior to Bind()/Connect(). | 13 // - (optional) Set options which are allowed prior to Bind()/Connect(). |
14 // - Bind or connect the socket. | 14 // - Bind or connect the socket. |
| 15 // - (optional) Bind the UDPSocketReceiver request returned by Bind()/Connect() |
15 // - (optional) Set options which are allowed after Bind()/Connect(). | 16 // - (optional) Set options which are allowed after Bind()/Connect(). |
16 // - Send / request to receive datagrams. Received datagrams will be delivered | 17 // - Send / request to receive datagrams. Received datagrams will be delivered |
17 // to UDPSocketClient.OnReceived(). | 18 // to the bound receiver's OnReceived() call. |
18 | |
19 // TODO(yzshen): Get rid of [Client] annotation. | |
20 [Client=UDPSocketClient] | |
21 interface UDPSocket { | 19 interface UDPSocket { |
22 // Allows the socket to share the local address to which it will be bound with | 20 // Allows the socket to share the local address to which it will be bound with |
23 // other processes. Should be called before Bind(). | 21 // other processes. Should be called before Bind(). |
24 // (This is equivalent to SO_REUSEADDR of the POSIX socket API.) | 22 // (This is equivalent to SO_REUSEADDR of the POSIX socket API.) |
25 AllowAddressReuse() => (NetworkError result); | 23 AllowAddressReuse() => (NetworkError result); |
26 | 24 |
27 // Binds the socket to the given address. The socket must not be bound or | 25 // Binds the socket to the given address. The socket must not be bound or |
28 // connected. | 26 // connected. |
29 // |bound_addr| is non-null on success. It might not be the same as |addr|. | 27 // |bound_addr| is non-null on success. It might not be the same as |addr|. |
30 // For example, if port 0 is used in |addr|, an available port is picked and | 28 // For example, if port 0 is used in |addr|, an available port is picked and |
31 // returned in |bound_addr|. | 29 // returned in |bound_addr|. The caller may provide an implementation of |
32 Bind(NetAddress addr) => (NetworkError result, NetAddress? bound_addr); | 30 // |receiver| to receive datagrams read from the socket. |receiver| is null |
33 | 31 // on failure. |
| 32 Bind(NetAddress addr) => (NetworkError result, NetAddress? bound_addr, |
| 33 UDPSocketReceiver&? receiver); |
34 | 34 |
35 // Connects the socket to the remote address. The socket must not be bound or | 35 // Connects the socket to the remote address. The socket must not be bound or |
36 // connected. | 36 // connected. |
37 // |local_addr| is non-null on success. | 37 // |local_addr| is non-null on success. |
| 38 // The caller may provide an implementation of |receiver| to receive datagrams |
| 39 // read from the socket. |receiver| is null on failure. |
38 Connect(NetAddress remote_addr) => (NetworkError result, | 40 Connect(NetAddress remote_addr) => (NetworkError result, |
39 NetAddress? local_addr); | 41 NetAddress? local_addr, |
| 42 UDPSocketReceiver&? receiver); |
40 | 43 |
41 // Sets the OS send buffer size (in bytes) for the socket. The socket must be | 44 // Sets the OS send buffer size (in bytes) for the socket. The socket must be |
42 // bound or connected. | 45 // bound or connected. |
43 SetSendBufferSize(uint32 size) => (NetworkError result); | 46 SetSendBufferSize(uint32 size) => (NetworkError result); |
44 | 47 |
45 // Sets the OS receive buffer size (in bytes) for the socket. The socket must | 48 // Sets the OS receive buffer size (in bytes) for the socket. The socket must |
46 // be bound or connected. | 49 // be bound or connected. |
47 SetReceiveBufferSize(uint32 size) => (NetworkError result); | 50 SetReceiveBufferSize(uint32 size) => (NetworkError result); |
48 | 51 |
49 // Negotiates the maximum number of pending SendTo() requests. If | 52 // Negotiates the maximum number of pending SendTo() requests. If |
50 // |requested_size| is set to 0, this method queries the current settings. | 53 // |requested_size| is set to 0, this method queries the current settings. |
51 // | 54 // |
52 // The service stores SendTo() requests in a queue while they are waiting to | 55 // The service stores SendTo() requests in a queue while they are waiting to |
53 // be executed (i.e., while they are waiting to be placed in the OS send | 56 // be executed (i.e., while they are waiting to be placed in the OS send |
54 // buffer and sent out). This method negotiates how many requests (not bytes) | 57 // buffer and sent out). This method negotiates how many requests (not bytes) |
55 // this queue is able to store. If the queue is full, the service fails new | 58 // this queue is able to store. If the queue is full, the service fails new |
56 // requests directly with error code ERR_INSUFFICIENT_RESOURCES and discards | 59 // requests directly with error code ERR_INSUFFICIENT_RESOURCES and discards |
57 // those datagrams. If the client wants to avoid such failures, it needs to | 60 // those datagrams. If the client wants to avoid such failures, it needs to |
58 // keep track of how many SendTo() calls are pending and make sure the number | 61 // keep track of how many SendTo() calls are pending and make sure the number |
59 // doesn't exceed the result of this method. | 62 // doesn't exceed the result of this method. |
60 NegotiateMaxPendingSendRequests(uint32 requested_size) | 63 NegotiateMaxPendingSendRequests(uint32 requested_size) |
61 => (uint32 actual_size); | 64 => (uint32 actual_size); |
62 | 65 |
63 // Notifies that the client is ready to accept |number| of datagrams. | 66 // Notifies that the receiver is ready to accept |number| of datagrams. |
64 // Correspondingly, OnReceived() of the UDPSocketClient interface will be | 67 // Correspondingly, OnReceived() of the UDPSocketReceiver interface will be |
65 // called |number| times (errors also count), unless the connection is closed | 68 // called |number| times (errors also count), unless the connection is closed |
66 // before that. | 69 // before that. |
67 // | 70 // |
68 // It is allowed to call this method again before the previous request is | 71 // It is allowed to call this method again before the previous request is |
69 // completely satisfied. For example: | 72 // completely satisfied. For example: |
70 // service->ReceiveMore(3); | 73 // service->ReceiveMore(3); |
71 // ... | 74 // ... |
72 // // OnReceived() is called. | 75 // // OnReceived() is called. |
73 // // OnReceived() is called. | 76 // // OnReceived() is called. |
74 // ... | 77 // ... |
(...skipping 26 matching lines...) Expand all Loading... |
101 // On success, |result.code| is a non-negative number indicating how many | 104 // On success, |result.code| is a non-negative number indicating how many |
102 // bytes have been written. Otherwise, it is a network error code, including | 105 // bytes have been written. Otherwise, it is a network error code, including |
103 // (but not limited to): | 106 // (but not limited to): |
104 // - ERR_INSUFFICIENT_RESOURCES (-12): The service doesn't have sufficient | 107 // - ERR_INSUFFICIENT_RESOURCES (-12): The service doesn't have sufficient |
105 // resource to complete the operation. One possible cause is that the client | 108 // resource to complete the operation. One possible cause is that the client |
106 // tries to send too many datagrams in a short period of time. | 109 // tries to send too many datagrams in a short period of time. |
107 // TODO(yzshen): Formalize Mojo networking error codes. | 110 // TODO(yzshen): Formalize Mojo networking error codes. |
108 SendTo(NetAddress? dest_addr, array<uint8> data) => (NetworkError result); | 111 SendTo(NetAddress? dest_addr, array<uint8> data) => (NetworkError result); |
109 }; | 112 }; |
110 | 113 |
111 interface UDPSocketClient { | 114 interface UDPSocketReceiver { |
112 // On success, |data| is non-null, |src_addr| is non-null if the socket is | 115 // On success, |data| is non-null, |src_addr| is non-null if the socket is |
113 // not connected, |result.code| is a non-negative number indicating how many | 116 // not connected, |result.code| is a non-negative number indicating how many |
114 // bytes have been received. On failure, |result.code| is a network error | 117 // bytes have been received. On failure, |result.code| is a network error |
115 // code. | 118 // code. |
116 OnReceived(NetworkError result, NetAddress? src_addr, array<uint8>? data); | 119 OnReceived(NetworkError result, NetAddress? src_addr, array<uint8>? data); |
117 }; | 120 }; |
OLD | NEW |