| 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 UDPSocketClient 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 and set a UDPSocketClient instance. |
| 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) Set options which are allowed after Bind()/Connect(). | 15 // - (optional) Set options which are allowed after Bind()/Connect(). |
| 16 // - Send / request to receive datagrams. Received datagrams will be delivered | 16 // - Send / request to receive datagrams. Received datagrams will be delivered |
| 17 // to UDPSocketClient.OnReceived(). | 17 // to UDPSocketClient.OnReceived(). |
| 18 | 18 |
| 19 // TODO(yzshen): Get rid of [Client] annotation. | 19 // TODO(yzshen): Get rid of [Client] annotation. |
| 20 [Client=UDPSocketClient] | 20 [Client=UDPSocketClient] |
| 21 interface UDPSocket { | 21 interface UDPSocket { |
| 22 // Allows the socket to share the local address to which it will be bound with | 22 // Allows the socket to share the local address to which it will be bound with |
| 23 // other processes. Should be called before Bind()/Connect(). | 23 // other processes. Should be called before Bind(). |
| 24 // (This is equivalent to SO_REUSEADDR of the POSIX socket API.) | 24 // (This is equivalent to SO_REUSEADDR of the POSIX socket API.) |
| 25 AllowAddressReuse() => (NetworkError result); | 25 AllowAddressReuse() => (NetworkError result); |
| 26 | 26 |
| 27 // Binds the socket to the given address. The socket must not be bound or | 27 // Binds the socket to the given address. The socket must not be bound or |
| 28 // connected. | 28 // connected. |
| 29 // |bound_addr| is non-NULL on success. It might not be the same as |addr|. | 29 // |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 | 30 // For example, if port 0 is used in |addr|, an available port is picked and |
| 31 // returned in |bound_addr|. | 31 // returned in |bound_addr|. |
| 32 Bind(NetAddress addr) => (NetworkError result, NetAddress? bound_addr); | 32 Bind(NetAddress addr) => (NetworkError result, NetAddress? bound_addr); |
| 33 | 33 |
| 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 Connect(NetAddress remote_addr) => (NetworkError result, | 38 Connect(NetAddress remote_addr) => (NetworkError result, |
| 39 NetAddress? local_addr); | 39 NetAddress? local_addr); |
| 40 | 40 |
| 41 // Sets the OS send buffer size (in bytes) for the socket. The socket must be | 41 // Sets the OS send buffer size (in bytes) for the socket. The socket must be |
| 42 // bound or connected. | 42 // bound or connected. |
| 43 SetSendBufferSize(uint32 size) => (NetworkError result); | 43 SetSendBufferSize(uint32 size) => (NetworkError result); |
| 44 | 44 |
| 45 // Sets the OS receive buffer size (in bytes) for the socket. The socket must | 45 // Sets the OS receive buffer size (in bytes) for the socket. The socket must |
| 46 // be bound or connected. | 46 // be bound or connected. |
| 47 SetReceiveBufferSize(uint32 size) => (NetworkError result); | 47 SetReceiveBufferSize(uint32 size) => (NetworkError result); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 // // OnReceived() is called. | 90 // // OnReceived() is called. |
| 91 // service->ReceiveMore(1); | 91 // service->ReceiveMore(1); |
| 92 // // OnReceived() is called. | 92 // // OnReceived() is called. |
| 93 // | 93 // |
| 94 // It is very likely that approach 1 will perform better than approach 2, | 94 // It is very likely that approach 1 will perform better than approach 2, |
| 95 // because in approach 2 getting every datagram takes at least the time of a | 95 // because in approach 2 getting every datagram takes at least the time of a |
| 96 // round trip to the service side. | 96 // round trip to the service side. |
| 97 ReceiveMore(uint32 datagram_number); | 97 ReceiveMore(uint32 datagram_number); |
| 98 | 98 |
| 99 // Sends data to the specified destination. The socket must be bound or | 99 // Sends data to the specified destination. The socket must be bound or |
| 100 // connected. |dest_addr| is allowed to be NULL if the socket is connected. | 100 // connected. |dest_addr| is allowed to be null if the socket is connected. |
| 101 // On success, |result.code| is a non-negative number indicating how many | 101 // 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 | 102 // bytes have been written. Otherwise, it is a network error code, including |
| 103 // (but not limited to): | 103 // (but not limited to): |
| 104 // - ERR_INSUFFICIENT_RESOURCES (-12): The service doesn't have sufficient | 104 // - ERR_INSUFFICIENT_RESOURCES (-12): The service doesn't have sufficient |
| 105 // resource to complete the operation. One possible cause is that the client | 105 // 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. | 106 // tries to send too many datagrams in a short period of time. |
| 107 // TODO(yzshen): Formalize Mojo networking error codes. | 107 // TODO(yzshen): Formalize Mojo networking error codes. |
| 108 SendTo(NetAddress? dest_addr, array<uint8> data) => (NetworkError result); | 108 SendTo(NetAddress? dest_addr, array<uint8> data) => (NetworkError result); |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 interface UDPSocketClient { | 111 interface UDPSocketClient { |
| 112 // On success, |data| is non-NULL, |src_addr| is non-NULL if the socket is | 112 // 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 | 113 // 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 | 114 // bytes have been received. On failure, |result.code| is a network error |
| 115 // code. | 115 // code. |
| 116 OnReceived(NetworkError result, NetAddress? src_addr, array<uint8>? data); | 116 OnReceived(NetworkError result, NetAddress? src_addr, array<uint8>? data); |
| 117 }; | 117 }; |
| OLD | NEW |