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> |
| 11 #include <sys/ioctl.h> |
11 #include <sys/socket.h> | 12 #include <sys/socket.h> |
12 | 13 |
13 #include "base/atomicops.h" | 14 #include "base/atomicops.h" |
14 #include "base/file_util.h" | 15 #include "base/file_util.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 | 17 |
17 | 18 |
18 namespace base { | 19 namespace base { |
19 | 20 |
20 namespace { | 21 namespace { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 size_t SyncSocket::Receive(void* buffer, size_t length) { | 92 size_t SyncSocket::Receive(void* buffer, size_t length) { |
92 DCHECK(length <= kMaxMessageLength); | 93 DCHECK(length <= kMaxMessageLength); |
93 char* charbuffer = static_cast<char*>(buffer); | 94 char* charbuffer = static_cast<char*>(buffer); |
94 if (file_util::ReadFromFD(handle_, charbuffer, length)) { | 95 if (file_util::ReadFromFD(handle_, charbuffer, length)) { |
95 return length; | 96 return length; |
96 } else { | 97 } else { |
97 return -1; | 98 return -1; |
98 } | 99 } |
99 } | 100 } |
100 | 101 |
101 // TODO(port). Some kind of select? | |
102 size_t SyncSocket::Peek() { | 102 size_t SyncSocket::Peek() { |
103 NOTIMPLEMENTED(); | 103 int number_chars; |
104 return 0; | 104 if (-1 == ioctl(handle_, FIONREAD, &number_chars)) { |
| 105 // If there is an error in ioctl, signal that the channel would block. |
| 106 return 0; |
| 107 } |
| 108 return (size_t) number_chars; |
105 } | 109 } |
106 | 110 |
107 } // namespace base | 111 } // namespace base |
OLD | NEW |