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 | |
viettrungluu
2014/09/30 19:22:15
Why is it important to combine these two cases int
| |
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 // - For as long as you want to accept incoming connections: | |
26 // 1. Listen() to wait for an incoming connection. | |
yzshen1
2014/09/30 18:21:39
This is different from what Pepper does. Is it int
brettw
2014/09/30 19:17:48
You're right, I misunderstood what Pepper/BSD did.
| |
27 // 2. Accept() to 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. | |
35 Bind(NetAddress addr) => (NetworkError result); | |
yzshen1
2014/09/30 18:21:40
For server socket, it seems we don't have a way to
brettw
2014/09/30 19:17:47
Added info.
| |
36 | |
37 // Starts listening on this socket for incoming connection requests. The | |
38 // socket must be bound and not connected. | |
39 // | |
40 // When an incoming connection is detected, the callback will report success | |
41 // and you can call Accept() to accept the connection. If a program then | |
42 // wants to listen for more than one incoming connection, it would typically | |
43 // call Listen() again to wait for more connections. | |
44 // | |
45 // The backlog is a hint indicating the number of incoming connections that | |
46 // can be queued up at one time waiting for Accept(). This queuing will | |
47 // happen when connections are incoming faster than Accept() can be called. | |
48 Listen(int32 backlog) => (NetworkError result); | |
49 | |
50 // Accepts a connection. The socket must be listening. | |
51 // | |
52 // This function is called to accept an incoming connection after Listen() | |
53 // indicates that one is available. The caller provides the streams that will | |
54 // be used to send and receive data on the connection. | |
55 // | |
56 // On success, the callback will be provided with the new socket that | |
57 // represents the connection. It will already be in a connected state and the | |
58 // data streams will be ready to use. | |
59 Accept(handle<data_pipe_consumer> send_stream, | |
60 handle<data_pipe_producer> receive_stream) => | |
61 (NetworkError result, TCPSocket socket, TCPSocketInfo info); | |
yzshen1
2014/09/30 18:21:39
You might want to append '?' to the type TCPSocket
brettw
2014/09/30 19:17:48
Good idea, I added this everywhere.
| |
62 | |
63 // Connects the socket to the given address. The socket must not be listening | |
64 // or previously connected. Binding the socket beforehand is optional. | |
65 Connect(NetAddress addr, | |
66 handle<data_pipe_consumer> send_stream, | |
67 handle<data_pipe_producer> receive_stream) => | |
68 (NetworkError result, TCPSocketInfo info); | |
69 | |
70 // Closes the connection. If Close() is not called, the connection will be | |
yzshen1
2014/09/30 18:21:39
Maybe we could revise the comment to also cover th
brettw
2014/09/30 19:17:48
Done
| |
71 // implicitly closes when the TCPSocket has been deleted. | |
72 Close(); | |
73 | |
74 // Controls whether small writes are coalesced to make TCP segments, and | |
75 // instead delivers data immediately. The default value is true (coalescing | |
76 // enabled). | |
77 SetCoaleseWrites(bool coalesce); | |
78 }; | |
79 | |
80 } | |
OLD | NEW |