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

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

Issue 1873463003: Remove mojo network service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 module mojo;
6
7 import "network/public/interfaces/net_address.mojom";
8 import "network/public/interfaces/network_error.mojom";
9
10 // UDPSocket and UDPSocketReceiver represent a UDP socket and its client. The
11 // typical flow of using the interfaces is:
12 // - Acquire a UDPSocket interface pointer.
13 // - (optional) Set options which are allowed prior to Bind()/Connect().
14 // - Bind or connect the socket.
15 // - (optional) Bind the UDPSocketReceiver request returned by Bind()/Connect()
16 // - (optional) Set options which are allowed after Bind()/Connect().
17 // - Send / request to receive datagrams. Received datagrams will be delivered
18 // to the bound receiver's OnReceived() call.
19 interface UDPSocket {
20 // Allows the socket to share the local address to which it will be bound with
21 // other processes. Should be called before Bind().
22 // (This is equivalent to SO_REUSEADDR of the POSIX socket API.)
23 AllowAddressReuse() => (NetworkError result);
24
25 // Binds the socket to the given address. The socket must not be bound or
26 // connected.
27 // |bound_addr| is non-null on success. It might not be the same as |addr|.
28 // For example, if port 0 is used in |addr|, an available port is picked and
29 // returned in |bound_addr|. The caller may provide an implementation of
30 // |receiver| to receive datagrams read from the socket. |receiver| is null
31 // on failure.
32 Bind(NetAddress addr) => (NetworkError result, NetAddress? bound_addr,
33 UDPSocketReceiver&? receiver);
34
35 // Connects the socket to the remote address. The socket must not be bound or
36 // connected.
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.
40 Connect(NetAddress remote_addr) => (NetworkError result,
41 NetAddress? local_addr,
42 UDPSocketReceiver&? receiver);
43
44 // Sets the OS send buffer size (in bytes) for the socket. The socket must be
45 // bound or connected.
46 SetSendBufferSize(uint32 size) => (NetworkError result);
47
48 // Sets the OS receive buffer size (in bytes) for the socket. The socket must
49 // be bound or connected.
50 SetReceiveBufferSize(uint32 size) => (NetworkError result);
51
52 // Negotiates the maximum number of pending SendTo() requests. If
53 // |requested_size| is set to 0, this method queries the current settings.
54 //
55 // The service stores SendTo() requests in a queue while they are waiting to
56 // be executed (i.e., while they are waiting to be placed in the OS send
57 // buffer and sent out). This method negotiates how many requests (not bytes)
58 // this queue is able to store. If the queue is full, the service fails new
59 // requests directly with error code ERR_INSUFFICIENT_RESOURCES and discards
60 // those datagrams. If the client wants to avoid such failures, it needs to
61 // keep track of how many SendTo() calls are pending and make sure the number
62 // doesn't exceed the result of this method.
63 NegotiateMaxPendingSendRequests(uint32 requested_size)
64 => (uint32 actual_size);
65
66 // Notifies that the receiver is ready to accept |number| of datagrams.
67 // Correspondingly, OnReceived() of the UDPSocketReceiver interface will be
68 // called |number| times (errors also count), unless the connection is closed
69 // before that.
70 //
71 // It is allowed to call this method again before the previous request is
72 // completely satisfied. For example:
73 // service->ReceiveMore(3);
74 // ...
75 // // OnReceived() is called.
76 // // OnReceived() is called.
77 // ...
78 // service->ReceiveMore(3);
79 // // The client expects 4 more calls to OnReceived().
80 //
81 // Please note that how ReceiveMore() is used will affect performance
82 // significantly. For example:
83 // // Approach 1:
84 // service->ReceiveMore(3);
85 // // OnReceived() is called.
86 // // OnReceived() is called.
87 // // OnReceived() is called.
88 //
89 // // Approach 2:
90 // service->ReceiveMore(1);
91 // // OnReceived() is called.
92 // service->ReceiveMore(1);
93 // // OnReceived() is called.
94 // service->ReceiveMore(1);
95 // // OnReceived() is called.
96 //
97 // It is very likely that approach 1 will perform better than approach 2,
98 // because in approach 2 getting every datagram takes at least the time of a
99 // round trip to the service side.
100 ReceiveMore(uint32 datagram_number);
101
102 // Sends data to the specified destination. The socket must be bound or
103 // connected. |dest_addr| is allowed to be null if the socket is connected.
104 // On success, |result.code| is a non-negative number indicating how many
105 // bytes have been written. Otherwise, it is a network error code, including
106 // (but not limited to):
107 // - ERR_INSUFFICIENT_RESOURCES (-12): The service doesn't have sufficient
108 // resource to complete the operation. One possible cause is that the client
109 // tries to send too many datagrams in a short period of time.
110 // TODO(yzshen): Formalize Mojo networking error codes.
111 SendTo(NetAddress? dest_addr, array<uint8> data) => (NetworkError result);
112 };
113
114 interface UDPSocketReceiver {
115 // On success, |data| is non-null, |src_addr| is non-null if the socket is
116 // not connected, |result.code| is a non-negative number indicating how many
117 // bytes have been received. On failure, |result.code| is a network error
118 // code.
119 OnReceived(NetworkError result, NetAddress? src_addr, array<uint8>? data);
120 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698