Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(516)

Side by Side Diff: mojo/services/public/interfaces/network/udp_socket.mojom

Issue 612403003: Mojo UDP socket API definition review. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/services/public/interfaces/network/net_address.mojom ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import "mojo/services/public/interfaces/network/net_address.mojom" 5 import "mojo/services/public/interfaces/network/net_address.mojom"
6 import "mojo/services/public/interfaces/network/network_error.mojom" 6 import "mojo/services/public/interfaces/network/network_error.mojom"
7 7
8 module mojo { 8 module mojo {
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(). 13 // - (optional) Set options which are allowed prior to Bind().
14 // - Bind the socket. 14 // - Bind the socket.
15 // - (optional) Set options which are allowed after Bind(). 15 // - (optional) Set options which are allowed after Bind().
16 // - Send / request to receive packets. Received packets will be delivered to 16 // - Send / request to receive packets. Received packets will be delivered to
17 // UDPSocketClient.OnReceived(). 17 // UDPSocketClient.OnReceived().
18
18 [Client=UDPSocketClient] 19 [Client=UDPSocketClient]
19 interface UDPSocket { 20 interface UDPSocket {
20 // Allows the socket to share the local address to which it will be bound with 21 // Allows the socket to share the local address to which it will be bound with
21 // other processes. Should be called before Bind(). 22 // other processes. Should be called before Bind().
22 // (This is equivalent to SO_REUSEADDR of the POSIX socket API.) 23 // (This is equivalent to SO_REUSEADDR of the POSIX socket API.)
23 AllowAddressReuse() => (NetworkError result); 24 AllowAddressReuse() => (NetworkError result);
24 25
25 // Binds the socket to the given address. 26 // Binds the socket to the given address.
26 // |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|.
27 // For example, if port 0 is used in |addr|, a random port is picked and 28 // For example, if port 0 is used in |addr|, a random port is picked and
28 // returned in |bound_addr|. 29 // returned in |bound_addr|.
29 Bind(NetAddress addr) => (NetworkError result, NetAddress? bound_addr); 30 Bind(NetAddress addr) => (NetworkError result, NetAddress? bound_addr);
30 31
31 // Sets the send buffer size (in bytes) for the socket. The socket must be 32 // Sets the OS send buffer size (in bytes) for the socket. The socket must be
32 // bound. 33 // bound.
33 //
34 // Note: This is only treated as a hint. Even if it succeeds, the service
35 // doesn't guarantee it will conform to the size.
36 SetSendBufferSize(uint32 size) => (NetworkError result); 34 SetSendBufferSize(uint32 size) => (NetworkError result);
37 35
38 // Sets the receive buffer size (in bytes) for the socket. The socket must be 36 // Sets the OS receive buffer size (in bytes) for the socket. The socket must
39 // bound. 37 // be bound.
38 SetReceiveBufferSize(uint32 size) => (NetworkError result);
39
40 // Negotiates the maximum number of pending SendTo() requests. If
41 // |requested_size| is set to 0, this method queries the current settings.
40 // 42 //
41 // Note: This is only treated as a hint. Even if it succeeds, the service 43 // The service stores SendTo() requests in a queue while they are waiting to
42 // doesn't guarantee it will conform to the size. 44 // be executed (i.e., while they are waiting to be placed in the OS send
43 SetReceiveBufferSize(uint32 size) => (NetworkError result); 45 // buffer and send out). This method negotiates how many requests (not bytes)
Ryan Sleevi 2014/10/05 23:24:05 s/send out/sent out/
yzshen1 2014/10/06 05:17:01 Thanks!
46 // this queue is able to store. If the queue is full, the service fails new
47 // requests directly with error code ERR_INSUFFICIENT_RESOURCES and discard
Ryan Sleevi 2014/10/05 23:24:05 s/discard/discards/
yzshen1 2014/10/06 05:17:01 Done.
48 // those packets. If the client wants to avoid such failure, it needs to keep
Ryan Sleevi 2014/10/05 23:24:06 s/failure/failures/
yzshen1 2014/10/06 05:17:00 Thanks! (Sorry, I should have been more careful.)
49 // track of how many SendTo() calls are pending and make sure the number
50 // doesn't exceed the result of this method.
51 NegotiateMaxPendingSendRequests(uint32 requested_size)
52 => (uint32 actual_size);
44 53
45 // Notifies that the client is ready to accept |number| of packets. 54 // Notifies that the client is ready to accept |number| of packets.
46 // Correspondingly, OnReceived() of the UDPSocketClient interface will be 55 // Correspondingly, OnReceived() of the UDPSocketClient interface will be
47 // called |number| times (errors also count), unless the connection is closed 56 // called |number| times (errors also count), unless the connection is closed
48 // before that. The socket must be bound. 57 // before that. The socket must be bound.
49 // 58 //
50 // It is allowed to call this method again before the previous request is 59 // It is allowed to call this method again before the previous request is
51 // completely satisfied. For example: 60 // completely satisfied. For example:
52 // service->ReceiveMorePackets(3); 61 // service->ReceiveMorePackets(3);
53 // ... 62 // ...
54 // // OnReceived() is called. 63 // // OnReceived() is called.
55 // // OnReceived() is called. 64 // // OnReceived() is called.
56 // ... 65 // ...
57 // service->ReceiveMorePackets(3); 66 // service->ReceiveMorePackets(3);
58 // // The client expects 4 more calls to OnReceived(). 67 // // The client expects 4 more calls to OnReceived().
68 //
69 // Please note that how ReceiveMorePackets() is used will affect performance
70 // significantly. For example:
71 // // Approach 1:
72 // service->ReceiveMorePackets(3);
73 // // OnReceived() is called.
74 // // OnReceived() is called.
75 // // OnReceived() is called.
76 //
77 // // Approach 2:
78 // service->ReceiveMorePackets(1);
79 // // OnReceived() is called.
80 // service->ReceiveMorePackets(1);
81 // // OnReceived() is called.
82 // service->ReceiveMorePackets(1);
83 // // OnReceived() is called.
84 //
85 // It is very likely that approach 1 will perform better than approach 2,
86 // because in approach 2 getting every packet takes at least the time of a
87 // round trip to the service side.
59 ReceiveMorePackets(uint32 number); 88 ReceiveMorePackets(uint32 number);
60 89
61 // Sends data to the specified destination. The socket must be bound. 90 // Sends data to the specified destination. The socket must be bound.
62 // The method doesn't report the result of the operation. 91 // On success, |result.code| is a non-negative number indicating how many
63 SendToAndForget(NetAddress addr, uint8[] data); 92 // bytes have been written. Otherwise, it is a network error code, including
64 93 // (but not limited to):
65 // Sends data to the specified destination. The socket must be bound. 94 // - ERR_INSUFFICIENT_RESOURCES (-12): The service doesn't have sufficient
Ryan Sleevi 2014/10/05 23:24:06 I'm not thrilled with documenting the value as -12
yzshen1 2014/10/06 05:17:01 I agree. I have talked with others about this. We
66 SendTo(NetAddress addr, uint8[] data) => (NetworkError result); 95 // resource to complete the operation. One possible cause is that the client
96 // tries to send too many packets in a short period of time.
97 SendTo(NetAddress dest_addr, uint8[] data) => (NetworkError result);
67 }; 98 };
68 99
69 interface UDPSocketClient { 100 interface UDPSocketClient {
70 // |addr| and |data| are non-NULL on success. 101 // On success, |src_addr| and |data| are non-NULL, |result.code| is a
71 OnReceived(NetworkError result, NetAddress? addr, uint8[]? data); 102 // non-negative number indicating how many bytes have been received.
103 OnReceived(NetworkError result, NetAddress? src_addr, uint8[]? data);
72 }; 104 };
73 105
74 } 106 }
OLDNEW
« no previous file with comments | « mojo/services/public/interfaces/network/net_address.mojom ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698