Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 import "mojo/services/public/interfaces/network/net_address.mojom" | |
| 6 import "mojo/services/public/interfaces/network/network_error.mojom" | |
| 7 | |
| 8 module mojo { | |
| 9 | |
| 10 struct TCPSocketInfo { | |
| 11 NetAddress local_address; | |
| 12 NetAddress remote_address; | |
| 13 }; | |
| 14 | |
| 15 // Represents a TCP socket. A socket can represent either a connection to a | |
| 16 // remote host, or a local server socket waiting for incoming connections. | |
| 17 // | |
| 18 // For client connections: | |
| 19 // - Connect(), providing a pair of streams to use for data transfer. | |
| 20 // - Read and write from the streams as desired. | |
| 21 // - Close(). | |
| 22 // | |
| 23 // For server connections: | |
| 24 // - Bind() to allocate a port. | |
| 25 // - Listen() to start listening for incoming connections. | |
| 26 // - For as long as you want to accept incoming connections: | |
| 27 // - Accept() to wait for and initiate a connection once one is available. | |
| 28 // - Close(). | |
| 29 interface TCPSocket { | |
| 30 // Binds this connection to a local port. The TCPSocket must not be bound, | |
| 31 // listening, or connected. | |
| 32 // | |
| 33 // This function is required to initialize a server socket for using Listen(), | |
| 34 // but is optional when using Connect() to initiate a client connection. On | |
| 35 // success, built_to will indicate the local address that was bound. | |
|
Ryan Sleevi
2014/09/30 20:48:08
typo: built_to -> bound_to
| |
| 36 Bind(NetAddress addr) => (NetworkError result, NetAddress? bound_to); | |
| 37 | |
| 38 // Starts listening on this socket for incoming connection requests. The | |
| 39 // socket must be bound and not connected. | |
| 40 // | |
| 41 // The backlog is a hint indicating the number of incoming connections that | |
| 42 // can be queued up at one time waiting for Accept(). This queuing will | |
| 43 // happen when connections are incoming faster than Accept() can be called. | |
|
Ryan Sleevi
2014/09/30 21:35:28
Note that in normal socket authoring, what you wan
brettw
2014/09/30 21:50:43
I was just copying the BSD Listen() function. I'm
| |
| 44 Listen(int32 backlog) => (NetworkError result); | |
|
Ryan Sleevi
2014/09/30 20:48:08
This creates an inconsistent interface. You can cr
brettw
2014/09/30 21:06:17
This object attempts to represent a sockfd. So you
viettrungluu
2014/09/30 21:25:48
So I now understand why I hate this API.
Fundamen
Ryan Sleevi
2014/09/30 21:35:28
From looking at the past work on Pepper and Extens
brettw
2014/09/30 22:16:17
The goal is to make it straightforward to write a
Ryan Sleevi
2014/10/01 04:05:23
This function in particular is NOT a straightforwa
| |
| 45 | |
| 46 // Accepts a connection. The socket must be listening. | |
| 47 // | |
| 48 // This function is called to accept an incoming connection. The caller | |
| 49 // provides the streams that will be used to send and receive data on the | |
| 50 // connection. | |
| 51 // | |
| 52 // On success, the callback will be provided with the new socket that | |
| 53 // represents the connection. It will already be in a connected state and the | |
| 54 // data streams will be ready to use. | |
| 55 Accept(handle<data_pipe_consumer> send_stream, | |
| 56 handle<data_pipe_producer> receive_stream) => | |
| 57 (NetworkError result, TCPSocket? socket, TCPSocketInfo? info); | |
|
Ryan Sleevi
2014/09/30 20:48:07
What happens if there are no sockets pending accep
brettw
2014/09/30 21:06:17
Yes.
| |
| 58 | |
| 59 // Connects the socket to the given address. The socket must not be listening | |
| 60 // or previously connected. Binding the socket beforehand is optional. | |
| 61 Connect(NetAddress addr, | |
| 62 handle<data_pipe_consumer> send_stream, | |
| 63 handle<data_pipe_producer> receive_stream) => | |
| 64 (NetworkError result, TCPSocketInfo? info); | |
| 65 | |
| 66 // Closes the connection or stops listening for connections, depending on | |
| 67 // whether this socket is in server or client mode. If Close() is not called, | |
| 68 // the connection will be implicitly closes when the TCPSocket has been | |
| 69 // deleted. | |
| 70 Close(); | |
|
Ryan Sleevi
2014/09/30 20:48:08
You'll want to rethink how this interface behaves.
brettw
2014/09/30 21:06:16
I don't follow entirely.
Connection reuse is some
Ryan Sleevi
2014/09/30 21:35:29
Concrete proposals:
1) Make the API distinguish be
willchan no longer on Chromium
2014/09/30 22:03:14
Can you clarify more details on the asynchronous p
| |
| 71 | |
| 72 // Controls whether small writes are coalesced to make TCP segments, and | |
| 73 // instead delivers data immediately. The default value is true (coalescing | |
| 74 // enabled). | |
| 75 SetCoaleseWrites(bool coalesce); | |
|
Ryan Sleevi
2014/09/30 20:48:07
Why not call this what it is (and which most socke
brettw
2014/09/30 21:06:17
I mentioned this in the comment.
Ryan Sleevi
2014/09/30 21:35:29
Did you mean the existing comment, or an update?
brettw
2014/09/30 21:50:43
This was added in a comment in the patch that was
| |
| 76 }; | |
| 77 | |
| 78 } | |
| OLD | NEW |