OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 // winsock2.h must be included first in order to ensure it is included before | 8 // winsock2.h must be included first in order to ensure it is included before |
9 // windows.h. | 9 // windows.h. |
10 #include <winsock2.h> | 10 #include <winsock2.h> |
11 #elif defined(OS_POSIX) | 11 #elif defined(OS_POSIX) |
12 #include <errno.h> | 12 #include <errno.h> |
13 #include <sys/socket.h> | 13 #include <sys/socket.h> |
14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
16 #include "third_party/libevent/event.h" | 16 #include "third_party/libevent/event.h" |
17 #include "base/message_pump_libevent.h" | 17 #include "base/message_pump_libevent.h" |
18 #endif | 18 #endif |
19 | 19 |
| 20 #include "base/eintr_wrappers.h" |
20 #include "net/base/telnet_server.h" | 21 #include "net/base/telnet_server.h" |
21 | 22 |
22 #if defined(OS_POSIX) | 23 #if defined(OS_POSIX) |
23 // Used same name as in Windows to avoid #ifdef where refrenced | 24 // Used same name as in Windows to avoid #ifdef where refrenced |
24 #define SOCKET int | 25 #define SOCKET int |
25 const int INVALID_SOCKET = -1; | 26 const int INVALID_SOCKET = -1; |
26 const int SOCKET_ERROR = -1; | 27 const int SOCKET_ERROR = -1; |
27 struct event; // From libevent | 28 struct event; // From libevent |
28 #endif | 29 #endif |
29 | 30 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 input_state_ = NOT_IN_IAC_OR_ESC_SEQUENCE; | 244 input_state_ = NOT_IN_IAC_OR_ESC_SEQUENCE; |
244 } | 245 } |
245 break; | 246 break; |
246 } | 247 } |
247 } | 248 } |
248 | 249 |
249 void TelnetServer::Read() { | 250 void TelnetServer::Read() { |
250 char buf[kReadBufSize + 1]; | 251 char buf[kReadBufSize + 1]; |
251 int len; | 252 int len; |
252 do { | 253 do { |
253 len = recv(socket_, buf, kReadBufSize, 0); | 254 len = HANDLE_EINTR(recv(socket_, buf, kReadBufSize, 0)); |
254 | 255 |
255 #if defined(OS_WIN) | 256 #if defined(OS_WIN) |
256 if (len == SOCKET_ERROR) { | 257 if (len == SOCKET_ERROR) { |
257 int err = WSAGetLastError(); | 258 int err = WSAGetLastError(); |
258 if (err == WSAEWOULDBLOCK) | 259 if (err == WSAEWOULDBLOCK) |
259 break; | 260 break; |
260 #else | 261 #else |
261 if (len == SOCKET_ERROR) { | 262 if (len == SOCKET_ERROR) { |
262 if (errno == EWOULDBLOCK || errno == EAGAIN) | 263 if (errno == EWOULDBLOCK || errno == EAGAIN) |
263 break; | 264 break; |
264 #endif | 265 #endif |
265 } else if (len == 0) { | 266 } else if (len == 0) { |
266 Close(); | 267 Close(); |
267 } else { | 268 } else { |
268 const char *data = buf; | 269 const char *data = buf; |
269 for (int i = 0; i < len; ++i) { | 270 for (int i = 0; i < len; ++i) { |
270 unsigned char c = static_cast<unsigned char>(*data); | 271 unsigned char c = static_cast<unsigned char>(*data); |
271 StateMachineStep(c); | 272 StateMachineStep(c); |
272 data++; | 273 data++; |
273 } | 274 } |
274 } | 275 } |
275 } while (len == kReadBufSize); | 276 } while (len == kReadBufSize); |
276 } | 277 } |
OLD | NEW |