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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/services/public/interfaces/network/net_address.mojom ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/services/public/interfaces/network/udp_socket.mojom
diff --git a/mojo/services/public/interfaces/network/udp_socket.mojom b/mojo/services/public/interfaces/network/udp_socket.mojom
index b5b848d9c764723f1a9cdcf19761178e95bf8872..526a454069ef91dfbedf260dd0d9884a08f2e463 100644
--- a/mojo/services/public/interfaces/network/udp_socket.mojom
+++ b/mojo/services/public/interfaces/network/udp_socket.mojom
@@ -13,8 +13,9 @@ module mojo {
// - (optional) Set options which are allowed prior to Bind().
// - Bind the socket.
// - (optional) Set options which are allowed after Bind().
-// - Send / request to receive packets. Received packets will be delivered to
-// UDPSocketClient.OnReceived().
+// - Send / request to receive datagrams. Received datagrams will be delivered
+// to UDPSocketClient.OnReceived().
+
[Client=UDPSocketClient]
interface UDPSocket {
// Allows the socket to share the local address to which it will be bound with
@@ -28,47 +29,80 @@ interface UDPSocket {
// returned in |bound_addr|.
Bind(NetAddress addr) => (NetworkError result, NetAddress? bound_addr);
- // Sets the send buffer size (in bytes) for the socket. The socket must be
+ // Sets the OS send buffer size (in bytes) for the socket. The socket must be
// bound.
- //
- // Note: This is only treated as a hint. Even if it succeeds, the service
- // doesn't guarantee it will conform to the size.
SetSendBufferSize(uint32 size) => (NetworkError result);
- // Sets the receive buffer size (in bytes) for the socket. The socket must be
- // bound.
- //
- // Note: This is only treated as a hint. Even if it succeeds, the service
- // doesn't guarantee it will conform to the size.
+ // Sets the OS receive buffer size (in bytes) for the socket. The socket must
+ // be bound.
SetReceiveBufferSize(uint32 size) => (NetworkError result);
- // Notifies that the client is ready to accept |number| of packets.
+ // Negotiates the maximum number of pending SendTo() requests. If
+ // |requested_size| is set to 0, this method queries the current settings.
+ //
+ // The service stores SendTo() requests in a queue while they are waiting to
+ // be executed (i.e., while they are waiting to be placed in the OS send
+ // buffer and sent out). This method negotiates how many requests (not bytes)
+ // this queue is able to store. If the queue is full, the service fails new
+ // requests directly with error code ERR_INSUFFICIENT_RESOURCES and discards
+ // those datagrams. If the client wants to avoid such failures, it needs to
+ // keep track of how many SendTo() calls are pending and make sure the number
+ // doesn't exceed the result of this method.
+ NegotiateMaxPendingSendRequests(uint32 requested_size)
+ => (uint32 actual_size);
+
+ // Notifies that the client is ready to accept |number| of datagrams.
// Correspondingly, OnReceived() of the UDPSocketClient interface will be
// called |number| times (errors also count), unless the connection is closed
// before that. The socket must be bound.
//
// It is allowed to call this method again before the previous request is
// completely satisfied. For example:
- // service->ReceiveMorePackets(3);
+ // service->ReceiveMore(3);
// ...
// // OnReceived() is called.
// // OnReceived() is called.
// ...
- // service->ReceiveMorePackets(3);
+ // service->ReceiveMore(3);
// // The client expects 4 more calls to OnReceived().
- ReceiveMorePackets(uint32 number);
-
- // Sends data to the specified destination. The socket must be bound.
- // The method doesn't report the result of the operation.
- SendToAndForget(NetAddress addr, array<uint8> data);
+ //
+ // Please note that how ReceiveMore() is used will affect performance
+ // significantly. For example:
+ // // Approach 1:
+ // service->ReceiveMore(3);
+ // // OnReceived() is called.
+ // // OnReceived() is called.
+ // // OnReceived() is called.
+ //
+ // // Approach 2:
+ // service->ReceiveMore(1);
+ // // OnReceived() is called.
+ // service->ReceiveMore(1);
+ // // OnReceived() is called.
+ // service->ReceiveMore(1);
+ // // OnReceived() is called.
+ //
+ // It is very likely that approach 1 will perform better than approach 2,
+ // because in approach 2 getting every datagram takes at least the time of a
+ // round trip to the service side.
+ ReceiveMore(uint32 datagram_number);
// Sends data to the specified destination. The socket must be bound.
- SendTo(NetAddress addr, array<uint8> data) => (NetworkError result);
+ // On success, |result.code| is a non-negative number indicating how many
+ // bytes have been written. Otherwise, it is a network error code, including
+ // (but not limited to):
+ // - ERR_INSUFFICIENT_RESOURCES (-12): The service doesn't have sufficient
+ // resource to complete the operation. One possible cause is that the client
+ // tries to send too many datagrams in a short period of time.
+ // TODO(yzshen): Formalize Mojo networking error codes.
+ SendTo(NetAddress dest_addr, array<uint8> data) => (NetworkError result);
};
interface UDPSocketClient {
- // |addr| and |data| are non-NULL on success.
- OnReceived(NetworkError result, NetAddress? addr, array<uint8>? data);
+ // On success, |src_addr| and |data| are non-NULL, and |result.code| is a
+ // non-negative number indicating how many bytes have been received. On
+ // failure, |result.code| is a network error code.
+ OnReceived(NetworkError result, NetAddress? src_addr, array<uint8>? data);
};
}
« 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