Commit 6e21296a authored by yzshen's avatar yzshen Committed by Commit bot

Mojo UDP socket API definition.

BUG=402671
TEST=None

Review URL: https://codereview.chromium.org/590263002

Cr-Commit-Position: refs/heads/master@{#297286}
parent ce44fef5
...@@ -457,8 +457,10 @@ ...@@ -457,8 +457,10 @@
'type': 'static_library', 'type': 'static_library',
'sources': [ 'sources': [
'services/public/interfaces/network/cookie_store.mojom', 'services/public/interfaces/network/cookie_store.mojom',
'services/public/interfaces/network/net_address.mojom',
'services/public/interfaces/network/network_error.mojom', 'services/public/interfaces/network/network_error.mojom',
'services/public/interfaces/network/network_service.mojom', 'services/public/interfaces/network/network_service.mojom',
'services/public/interfaces/network/udp_socket.mojom',
'services/public/interfaces/network/url_loader.mojom', 'services/public/interfaces/network/url_loader.mojom',
'services/public/interfaces/network/web_socket.mojom', 'services/public/interfaces/network/web_socket.mojom',
], ],
......
...@@ -8,8 +8,10 @@ import("//mojo/public/tools/bindings/mojom.gni") ...@@ -8,8 +8,10 @@ import("//mojo/public/tools/bindings/mojom.gni")
mojom("network") { mojom("network") {
sources = [ sources = [
"cookie_store.mojom", "cookie_store.mojom",
"net_address.mojom",
"network_error.mojom", "network_error.mojom",
"network_service.mojom", "network_service.mojom",
"udp_socket.mojom",
"url_loader.mojom", "url_loader.mojom",
"web_socket.mojom", "web_socket.mojom",
] ]
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module mojo {
enum NetAddressFamily {
UNSPECIFIED,
IPV4,
IPV6
};
// All members are expressed in network byte order, i.e., the most significant
// byte is stored in the smallest address. For example, if we store 127.0.0.1 in
// |addr|, 127 should be at index 0.
struct NetAddressIPv4 {
uint16 port;
uint8[4] addr;
};
// All members are expressed in network byte order.
struct NetAddressIPv6 {
uint16 port;
uint8[16] addr;
};
struct NetAddress {
NetAddressFamily family = UNSPECIFIED;
// At most one of the following fields is non-NULL depending on the value of
// |family|.
NetAddressIPv4? ipv4;
NetAddressIPv6? ipv6;
};
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import "mojo/services/public/interfaces/network/net_address.mojom"
import "mojo/services/public/interfaces/network/network_error.mojom"
module mojo {
// UDPSocket and UDPSocketClient represent a UDP socket and its client. The
// typical flow of using the interfaces is:
// - Acquire a UDPSocket interface pointer and set a UDPSocketClient instance.
// - (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().
[Client=UDPSocketClient]
interface UDPSocket {
// Allows the socket to share the local address to which it will be bound with
// other processes. Should be called before Bind().
// (This is equivalent to SO_REUSEADDR of the POSIX socket API.)
AllowAddressReuse() => (NetworkError result);
// Binds the socket to the given address.
// |bound_addr| is non-NULL on success. It might not be the same as |addr|.
// For example, if port 0 is used in |addr|, a random port is picked and
// 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
// 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.
SetReceiveBufferSize(uint32 size) => (NetworkError result);
// Notifies that the client is ready to accept |number| of packets.
// 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);
// ...
// // OnReceived() is called.
// // OnReceived() is called.
// ...
// service->ReceiveMorePackets(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, uint8[] data);
// Sends data to the specified destination. The socket must be bound.
SendTo(NetAddress addr, uint8[] data) => (NetworkError result);
};
interface UDPSocketClient {
// |addr| and |data| are non-NULL on success.
OnReceived(NetworkError result, NetAddress? addr, uint8[]? data);
};
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment