Index: mojo/services/public/interfaces/network/tcp_socket.mojom |
diff --git a/mojo/services/public/interfaces/network/tcp_socket.mojom b/mojo/services/public/interfaces/network/tcp_socket.mojom |
new file mode 100644 |
index 0000000000000000000000000000000000000000..22580caf0c9cdf22e9af32fa92c92c3dd99e0d37 |
--- /dev/null |
+++ b/mojo/services/public/interfaces/network/tcp_socket.mojom |
@@ -0,0 +1,77 @@ |
+// 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 { |
+ |
+struct TCPSocketInfo { |
+ NetAddress local_address; |
+ NetAddress remote_address; |
+}; |
+ |
+// Represents a TCP socket. A socket can represent either a connection to a |
+// remote host, or a local server socket waiting for incoming connections. |
+// |
+// For client connections: |
+// - Connect(), providing a pair of streams to use for data transfer. |
+// - Read and write from the streams as desired. |
+// - Close(). |
+// |
+// For server connections: |
+// - Bind() to allocate a port. |
+// - Listen() to start listening for incoming connections. |
+// - For as long as you want to accept incoming connections: |
+// - Accept() to wait for and initiate a connection once one is available. |
+// - Close(). |
+interface TCPSocket { |
+ // Binds this connection to a local port. The TCPSocket must not be bound, |
+ // listening, or connected. |
+ // |
+ // This function is required to initialize a server socket for using Listen(), |
+ // but is optional when using Connect() to initiate a client connection. |
+ Bind(NetAddress addr) => (NetworkError result, TCPSocketInfo? info); |
yzshen1
2014/09/30 20:26:13
Because there is no remote address at this point y
brettw
2014/09/30 20:32:13
I changed this case to be a NetAddr? but kept the
|
+ |
+ // Starts listening on this socket for incoming connection requests. The |
+ // socket must be bound and not connected. |
+ // |
+ // The backlog is a hint indicating the number of incoming connections that |
+ // can be queued up at one time waiting for Accept(). This queuing will |
+ // happen when connections are incoming faster than Accept() can be called. |
+ Listen(int32 backlog) => (NetworkError result); |
+ |
+ // Accepts a connection. The socket must be listening. |
+ // |
+ // This function is called to accept an incoming connection. The caller |
+ // provides the streams that will be used to send and receive data on the |
+ // connection. |
+ // |
+ // On success, the callback will be provided with the new socket that |
+ // represents the connection. It will already be in a connected state and the |
+ // data streams will be ready to use. |
+ Accept(handle<data_pipe_consumer> send_stream, |
+ handle<data_pipe_producer> receive_stream) => |
+ (NetworkError result, TCPSocket? socket, TCPSocketInfo? info); |
+ |
+ // Connects the socket to the given address. The socket must not be listening |
+ // or previously connected. Binding the socket beforehand is optional. |
+ Connect(NetAddress addr, |
+ handle<data_pipe_consumer> send_stream, |
+ handle<data_pipe_producer> receive_stream) => |
+ (NetworkError result, TCPSocketInfo? info); |
+ |
+ // Closes the connection or stops listening for connections, depending on |
+ // whether this socket is in server or client mode. If Close() is not called, |
+ // the connection will be implicitly closes when the TCPSocket has been |
+ // deleted. |
+ Close(); |
+ |
+ // Controls whether small writes are coalesced to make TCP segments, and |
+ // instead delivers data immediately. The default value is true (coalescing |
+ // enabled). |
+ SetCoaleseWrites(bool coalesce); |
viettrungluu
2014/09/30 20:34:41
Having a setter but no getter seems bad.
Also, no
brettw
2014/09/30 20:44:15
My plan was to use the mojo versioning to add func
|
+}; |
+ |
+} |