OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/sync_socket.h" | 5 #include "base/sync_socket.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <limits.h> | 8 #include <limits.h> |
9 #include <stdio.h> | 9 #include <stdio.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 } | 56 } |
57 #endif | 57 #endif |
58 // Copy the handles out for successful return. | 58 // Copy the handles out for successful return. |
59 tmp_sockets[0]->handle_ = handles[0]; | 59 tmp_sockets[0]->handle_ = handles[0]; |
60 pair[0] = tmp_sockets[0]; | 60 pair[0] = tmp_sockets[0]; |
61 tmp_sockets[1]->handle_ = handles[1]; | 61 tmp_sockets[1]->handle_ = handles[1]; |
62 pair[1] = tmp_sockets[1]; | 62 pair[1] = tmp_sockets[1]; |
63 return true; | 63 return true; |
64 | 64 |
65 cleanup: | 65 cleanup: |
66 if (handles[0] != kInvalidHandle) | 66 if (handles[0] != kInvalidHandle) { |
67 (void) close(handles[0]); | 67 if (HANDLE_EINTR(close(handles[0])) < 0) |
68 if (handles[1] != kInvalidHandle) | 68 PLOG(ERROR) << "close"; |
69 (void) close(handles[1]); | 69 } |
| 70 if (handles[1] != kInvalidHandle) { |
| 71 if (HANDLE_EINTR(close(handles[1])) < 0) |
| 72 PLOG(ERROR) << "close"; |
| 73 } |
70 delete tmp_sockets[0]; | 74 delete tmp_sockets[0]; |
71 delete tmp_sockets[1]; | 75 delete tmp_sockets[1]; |
72 return false; | 76 return false; |
73 } | 77 } |
74 | 78 |
75 bool SyncSocket::Close() { | 79 bool SyncSocket::Close() { |
76 if (handle_ == kInvalidHandle) { | 80 if (handle_ == kInvalidHandle) { |
77 return false; | 81 return false; |
78 } | 82 } |
79 int retval = close(handle_); | 83 int retval = HANDLE_EINTR(close(handle_)); |
| 84 if (retval < 0) |
| 85 PLOG(ERROR) << "close"; |
80 handle_ = kInvalidHandle; | 86 handle_ = kInvalidHandle; |
81 return (retval == 0); | 87 return (retval == 0); |
82 } | 88 } |
83 | 89 |
84 size_t SyncSocket::Send(const void* buffer, size_t length) { | 90 size_t SyncSocket::Send(const void* buffer, size_t length) { |
85 DCHECK(length <= kMaxMessageLength); | 91 DCHECK(length <= kMaxMessageLength); |
86 const char* charbuffer = static_cast<const char*>(buffer); | 92 const char* charbuffer = static_cast<const char*>(buffer); |
87 int len = file_util::WriteFileDescriptor(handle_, charbuffer, length); | 93 int len = file_util::WriteFileDescriptor(handle_, charbuffer, length); |
88 return static_cast<size_t>(len); | 94 return static_cast<size_t>(len); |
89 } | 95 } |
(...skipping 11 matching lines...) Expand all Loading... |
101 size_t SyncSocket::Peek() { | 107 size_t SyncSocket::Peek() { |
102 int number_chars; | 108 int number_chars; |
103 if (-1 == ioctl(handle_, FIONREAD, &number_chars)) { | 109 if (-1 == ioctl(handle_, FIONREAD, &number_chars)) { |
104 // If there is an error in ioctl, signal that the channel would block. | 110 // If there is an error in ioctl, signal that the channel would block. |
105 return 0; | 111 return 0; |
106 } | 112 } |
107 return (size_t) number_chars; | 113 return (size_t) number_chars; |
108 } | 114 } |
109 | 115 |
110 } // namespace base | 116 } // namespace base |
OLD | NEW |