Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(605)

Side by Side Diff: tools/android/forwarder2/socket.h

Issue 2402793002: [Android] Add timeout to unmap reply handling. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 than 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 // Same as Read() but with a timeout.
54 int ReadWithTimeout(void* buffer, size_t buffer_size, int timeout_secs);
55
53 // Non-blocking version of Read() above. This must be called after a 56 // 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 57 // successful call to select(). The socket must also be in non-blocking mode
55 // before calling this method. 58 // before calling this method.
56 int NonBlockingRead(void* buffer, size_t buffer_size); 59 int NonBlockingRead(void* buffer, size_t buffer_size);
57 60
58 // Wrapper around send(). 61 // Wrapper around send().
59 int Write(const void* buffer, size_t count); 62 int Write(const void* buffer, size_t count);
60 63
61 // Same as NonBlockingRead() but for writing. 64 // Same as NonBlockingRead() but for writing.
62 int NonBlockingWrite(const void* buffer, size_t count); 65 int NonBlockingWrite(const void* buffer, size_t count);
63 66
64 // Calls Read() multiple times until num_bytes is written to the provided 67 // Calls Read() multiple times until num_bytes is written to the provided
65 // buffer. No bounds checking is performed. 68 // buffer. No bounds checking is performed.
66 // Returns number of bytes read, which can be different from num_bytes in case 69 // Returns number of bytes read, which can be different from num_bytes in case
67 // of errror. 70 // of errror.
68 int ReadNumBytes(void* buffer, size_t num_bytes); 71 int ReadNumBytes(void* buffer, size_t num_bytes);
69 72
73 // Same as ReadNumBytes() but with a timeout.
74 int ReadNumBytesWithTimeout(void* buffer, size_t num_bytes, int timeout_secs);
75
70 // Calls Write() multiple times until num_bytes is written. No bounds checking 76 // Calls Write() multiple times until num_bytes is written. No bounds checking
71 // is performed. Returns number of bytes written, which can be different from 77 // is performed. Returns number of bytes written, which can be different from
72 // num_bytes in case of errror. 78 // num_bytes in case of errror.
73 int WriteNumBytes(const void* buffer, size_t num_bytes); 79 int WriteNumBytes(const void* buffer, size_t num_bytes);
74 80
75 // Calls WriteNumBytes for the given std::string. Note that the null 81 // Calls WriteNumBytes for the given std::string. Note that the null
76 // terminator is not written to the socket. 82 // terminator is not written to the socket.
77 int WriteString(const std::string& buffer); 83 int WriteString(const std::string& buffer);
78 84
79 bool has_error() const { return socket_error_; } 85 bool has_error() const { return socket_error_; }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // Used to listen for external events (e.g. process received a SIGTERM) while 149 // Used to listen for external events (e.g. process received a SIGTERM) while
144 // blocking on I/O operations. 150 // blocking on I/O operations.
145 std::vector<Event> events_; 151 std::vector<Event> events_;
146 152
147 DISALLOW_COPY_AND_ASSIGN(Socket); 153 DISALLOW_COPY_AND_ASSIGN(Socket);
148 }; 154 };
149 155
150 } // namespace forwarder 156 } // namespace forwarder
151 157
152 #endif // TOOLS_ANDROID_FORWARDER2_SOCKET_H_ 158 #endif // TOOLS_ANDROID_FORWARDER2_SOCKET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698