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 #include "base/sync_socket.h" | 5 #include "base/sync_socket.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <limits.h> | 9 #include <limits.h> |
10 #include <stddef.h> | 10 #include <stddef.h> |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 DCHECK_NE(handle_, kInvalidHandle); | 200 DCHECK_NE(handle_, kInvalidHandle); |
201 int number_chars = 0; | 201 int number_chars = 0; |
202 if (ioctl(handle_, FIONREAD, &number_chars) == -1) { | 202 if (ioctl(handle_, FIONREAD, &number_chars) == -1) { |
203 // If there is an error in ioctl, signal that the channel would block. | 203 // If there is an error in ioctl, signal that the channel would block. |
204 return 0; | 204 return 0; |
205 } | 205 } |
206 DCHECK_GE(number_chars, 0); | 206 DCHECK_GE(number_chars, 0); |
207 return number_chars; | 207 return number_chars; |
208 } | 208 } |
209 | 209 |
| 210 SyncSocket::Handle SyncSocket::Release() { |
| 211 Handle r = handle_; |
| 212 handle_ = kInvalidHandle; |
| 213 return r; |
| 214 } |
| 215 |
210 CancelableSyncSocket::CancelableSyncSocket() {} | 216 CancelableSyncSocket::CancelableSyncSocket() {} |
211 CancelableSyncSocket::CancelableSyncSocket(Handle handle) | 217 CancelableSyncSocket::CancelableSyncSocket(Handle handle) |
212 : SyncSocket(handle) { | 218 : SyncSocket(handle) { |
213 } | 219 } |
214 | 220 |
215 bool CancelableSyncSocket::Shutdown() { | 221 bool CancelableSyncSocket::Shutdown() { |
216 DCHECK_NE(handle_, kInvalidHandle); | 222 DCHECK_NE(handle_, kInvalidHandle); |
217 return HANDLE_EINTR(shutdown(handle_, SHUT_RDWR)) >= 0; | 223 return HANDLE_EINTR(shutdown(handle_, SHUT_RDWR)) >= 0; |
218 } | 224 } |
219 | 225 |
(...skipping 19 matching lines...) Expand all Loading... |
239 return len; | 245 return len; |
240 } | 246 } |
241 | 247 |
242 // static | 248 // static |
243 bool CancelableSyncSocket::CreatePair(CancelableSyncSocket* socket_a, | 249 bool CancelableSyncSocket::CreatePair(CancelableSyncSocket* socket_a, |
244 CancelableSyncSocket* socket_b) { | 250 CancelableSyncSocket* socket_b) { |
245 return SyncSocket::CreatePair(socket_a, socket_b); | 251 return SyncSocket::CreatePair(socket_a, socket_b); |
246 } | 252 } |
247 | 253 |
248 } // namespace base | 254 } // namespace base |
OLD | NEW |