OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef TOOLS_ANDROID_FORWARDER2_SOCKET_H_ | 5 #ifndef TOOLS_ANDROID_FORWARDER2_SOCKET_H_ |
6 #define TOOLS_ANDROID_FORWARDER2_SOCKET_H_ | 6 #define TOOLS_ANDROID_FORWARDER2_SOCKET_H_ |
7 | 7 |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <netinet/in.h> | 9 #include <netinet/in.h> |
10 #include <stddef.h> | 10 #include <stddef.h> |
(...skipping 28 matching lines...) Expand all Loading... |
39 bool IsClosed() const { return socket_ < 0; } | 39 bool IsClosed() const { return socket_ < 0; } |
40 | 40 |
41 int fd() const { return socket_; } | 41 int fd() const { return socket_; } |
42 | 42 |
43 bool Accept(Socket* new_socket); | 43 bool Accept(Socket* new_socket); |
44 | 44 |
45 // Returns the port allocated to this socket or zero on error. | 45 // Returns the port allocated to this socket or zero on error. |
46 int GetPort(); | 46 int GetPort(); |
47 | 47 |
48 // Just a wrapper around unix read() function. | 48 // Just a wrapper around unix read() function. |
49 // Reads up to buffer_size, but may read less then buffer_size. | 49 // Reads up to buffer_size, but may read less than buffer_size. |
50 // Returns the number of bytes read. | 50 // Returns the number of bytes read. |
51 int Read(void* buffer, size_t buffer_size); | 51 int Read(void* buffer, size_t buffer_size); |
52 | 52 |
53 // Non-blocking version of Read() above. This must be called after a | 53 // Non-blocking version of Read() above. This must be called after a |
54 // successful call to select(). The socket must also be in non-blocking mode | 54 // successful call to select(). The socket must also be in non-blocking mode |
55 // before calling this method. | 55 // before calling this method. |
56 int NonBlockingRead(void* buffer, size_t buffer_size); | 56 int NonBlockingRead(void* buffer, size_t buffer_size); |
57 | 57 |
58 // Wrapper around send(). | 58 // Wrapper around send(). |
59 int Write(const void* buffer, size_t count); | 59 int Write(const void* buffer, size_t count); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 // Used to listen for external events (e.g. process received a SIGTERM) while | 143 // Used to listen for external events (e.g. process received a SIGTERM) while |
144 // blocking on I/O operations. | 144 // blocking on I/O operations. |
145 std::vector<Event> events_; | 145 std::vector<Event> events_; |
146 | 146 |
147 DISALLOW_COPY_AND_ASSIGN(Socket); | 147 DISALLOW_COPY_AND_ASSIGN(Socket); |
148 }; | 148 }; |
149 | 149 |
150 } // namespace forwarder | 150 } // namespace forwarder |
151 | 151 |
152 #endif // TOOLS_ANDROID_FORWARDER2_SOCKET_H_ | 152 #endif // TOOLS_ANDROID_FORWARDER2_SOCKET_H_ |
OLD | NEW |