OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ioctl.h> |
12 #include <sys/socket.h> | 12 #include <sys/socket.h> |
13 | 13 |
14 #if defined(OS_SOLARIS) | 14 #if defined(OS_SOLARIS) |
15 #include <sys/filio.h> | 15 #include <sys/filio.h> |
16 #endif | 16 #endif |
17 | 17 |
18 #include "base/file_util.h" | 18 #include "base/file_util.h" |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
20 | 20 |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 | 23 |
24 namespace { | 24 namespace { |
25 // To avoid users sending negative message lengths to Send/Receive | 25 // To avoid users sending negative message lengths to Send/Receive |
26 // we clamp message lengths, which are size_t, to no more than INT_MAX. | 26 // we clamp message lengths, which are size_t, to no more than INT_MAX. |
27 const size_t kMaxMessageLength = static_cast<size_t>(INT_MAX); | 27 const size_t kMaxMessageLength = static_cast<size_t>(INT_MAX); |
28 | 28 |
29 static const SyncSocket::Handle kInvalidHandle = -1; | 29 } // namespace |
30 | 30 |
31 } // namespace | 31 const SyncSocket::Handle SyncSocket::kInvalidHandle = -1; |
32 | 32 |
33 bool SyncSocket::CreatePair(SyncSocket* pair[2]) { | 33 bool SyncSocket::CreatePair(SyncSocket* pair[2]) { |
34 Handle handles[2] = { kInvalidHandle, kInvalidHandle }; | 34 Handle handles[2] = { kInvalidHandle, kInvalidHandle }; |
35 SyncSocket* tmp_sockets[2] = { NULL, NULL }; | 35 SyncSocket* tmp_sockets[2] = { NULL, NULL }; |
36 #if defined(OS_MACOSX) | 36 #if defined(OS_MACOSX) |
37 int nosigpipe = 1; | 37 int nosigpipe = 1; |
38 #endif // defined(OS_MACOSX) | 38 #endif // defined(OS_MACOSX) |
39 | 39 |
40 // Create the two SyncSocket objects first to avoid ugly cleanup issues. | 40 // Create the two SyncSocket objects first to avoid ugly cleanup issues. |
41 tmp_sockets[0] = new SyncSocket(kInvalidHandle); | 41 tmp_sockets[0] = new SyncSocket(kInvalidHandle); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 size_t SyncSocket::Peek() { | 111 size_t SyncSocket::Peek() { |
112 int number_chars; | 112 int number_chars; |
113 if (-1 == ioctl(handle_, FIONREAD, &number_chars)) { | 113 if (-1 == ioctl(handle_, FIONREAD, &number_chars)) { |
114 // If there is an error in ioctl, signal that the channel would block. | 114 // If there is an error in ioctl, signal that the channel would block. |
115 return 0; | 115 return 0; |
116 } | 116 } |
117 return (size_t) number_chars; | 117 return (size_t) number_chars; |
118 } | 118 } |
119 | 119 |
120 } // namespace base | 120 } // namespace base |
OLD | NEW |