| 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 <sys/socket.h> | 10 #include <sys/socket.h> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 int GetPort(); | 43 int GetPort(); |
| 44 | 44 |
| 45 bool IsFdInSet(const fd_set& fds) const; | 45 bool IsFdInSet(const fd_set& fds) const; |
| 46 bool AddFdToSet(fd_set* fds) const; | 46 bool AddFdToSet(fd_set* fds) const; |
| 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 then 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 // Same as Read(), just a wrapper around write(). | 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 |
| 55 // before calling this method. |
| 56 int NonBlockingRead(void* buffer, size_t buffer_size); |
| 57 |
| 58 // Wrapper around send(). |
| 54 int Write(const void* buffer, size_t count); | 59 int Write(const void* buffer, size_t count); |
| 55 | 60 |
| 61 // Same as NonBlockingRead() but for writing. |
| 62 int NonBlockingWrite(const void* buffer, size_t count); |
| 63 |
| 56 // Calls Read() multiple times until num_bytes is written to the provided | 64 // Calls Read() multiple times until num_bytes is written to the provided |
| 57 // buffer. No bounds checking is performed. | 65 // buffer. No bounds checking is performed. |
| 58 // Returns number of bytes read, which can be different from num_bytes in case | 66 // Returns number of bytes read, which can be different from num_bytes in case |
| 59 // of errror. | 67 // of errror. |
| 60 int ReadNumBytes(void* buffer, size_t num_bytes); | 68 int ReadNumBytes(void* buffer, size_t num_bytes); |
| 61 | 69 |
| 62 // Calls Write() multiple times until num_bytes is written. No bounds checking | 70 // Calls Write() multiple times until num_bytes is written. No bounds checking |
| 63 // is performed. Returns number of bytes written, which can be different from | 71 // is performed. Returns number of bytes written, which can be different from |
| 64 // num_bytes in case of errror. | 72 // num_bytes in case of errror. |
| 65 int WriteNumBytes(const void* buffer, size_t num_bytes); | 73 int WriteNumBytes(const void* buffer, size_t num_bytes); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 sockaddr_in6 addr6; | 106 sockaddr_in6 addr6; |
| 99 // Unix Domain sockaddr | 107 // Unix Domain sockaddr |
| 100 sockaddr_un addr_un; | 108 sockaddr_un addr_un; |
| 101 }; | 109 }; |
| 102 | 110 |
| 103 struct Event { | 111 struct Event { |
| 104 int fd; | 112 int fd; |
| 105 bool was_fired; | 113 bool was_fired; |
| 106 }; | 114 }; |
| 107 | 115 |
| 116 bool SetNonBlocking(); |
| 117 |
| 108 // If |host| is empty, use localhost. | 118 // If |host| is empty, use localhost. |
| 109 bool InitTcpSocket(const std::string& host, int port); | 119 bool InitTcpSocket(const std::string& host, int port); |
| 110 bool InitUnixSocket(const std::string& path); | 120 bool InitUnixSocket(const std::string& path); |
| 111 bool BindAndListen(); | 121 bool BindAndListen(); |
| 112 bool Connect(); | 122 bool Connect(); |
| 113 | 123 |
| 114 bool Resolve(const std::string& host); | 124 bool Resolve(const std::string& host); |
| 115 bool InitSocketInternal(); | 125 bool InitSocketInternal(); |
| 116 void SetSocketError(); | 126 void SetSocketError(); |
| 117 | 127 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 136 // Used to listen for external events (e.g. process received a SIGTERM) while | 146 // Used to listen for external events (e.g. process received a SIGTERM) while |
| 137 // blocking on I/O operations. | 147 // blocking on I/O operations. |
| 138 std::vector<Event> events_; | 148 std::vector<Event> events_; |
| 139 | 149 |
| 140 DISALLOW_COPY_AND_ASSIGN(Socket); | 150 DISALLOW_COPY_AND_ASSIGN(Socket); |
| 141 }; | 151 }; |
| 142 | 152 |
| 143 } // namespace forwarder | 153 } // namespace forwarder |
| 144 | 154 |
| 145 #endif // TOOLS_ANDROID_FORWARDER2_SOCKET_H_ | 155 #endif // TOOLS_ANDROID_FORWARDER2_SOCKET_H_ |
| OLD | NEW |