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 goto cleanup; | 56 goto cleanup; |
57 } | 57 } |
58 #endif | 58 #endif |
59 // Copy the handles out for successful return. | 59 // Copy the handles out for successful return. |
60 tmp_sockets[0]->handle_ = handles[0]; | 60 tmp_sockets[0]->handle_ = handles[0]; |
61 pair[0] = tmp_sockets[0]; | 61 pair[0] = tmp_sockets[0]; |
62 tmp_sockets[1]->handle_ = handles[1]; | 62 tmp_sockets[1]->handle_ = handles[1]; |
63 pair[1] = tmp_sockets[1]; | 63 pair[1] = tmp_sockets[1]; |
64 return true; | 64 return true; |
65 | 65 |
66 cleanup: | 66 cleanup: |
67 if (handles[0] != kInvalidHandle) | 67 if (handles[0] != kInvalidHandle) |
68 (void) close(handles[0]); | 68 (void) close(handles[0]); |
69 if (handles[1] != kInvalidHandle) | 69 if (handles[1] != kInvalidHandle) |
70 (void) close(handles[1]); | 70 (void) close(handles[1]); |
71 delete tmp_sockets[0]; | 71 delete tmp_sockets[0]; |
72 delete tmp_sockets[1]; | 72 delete tmp_sockets[1]; |
73 return false; | 73 return false; |
74 } | 74 } |
75 | 75 |
76 bool SyncSocket::Close() { | 76 bool SyncSocket::Close() { |
(...skipping 25 matching lines...) Expand all Loading... |
102 size_t SyncSocket::Peek() { | 102 size_t SyncSocket::Peek() { |
103 int number_chars; | 103 int number_chars; |
104 if (-1 == ioctl(handle_, FIONREAD, &number_chars)) { | 104 if (-1 == ioctl(handle_, FIONREAD, &number_chars)) { |
105 // If there is an error in ioctl, signal that the channel would block. | 105 // If there is an error in ioctl, signal that the channel would block. |
106 return 0; | 106 return 0; |
107 } | 107 } |
108 return (size_t) number_chars; | 108 return (size_t) number_chars; |
109 } | 109 } |
110 | 110 |
111 } // namespace base | 111 } // namespace base |
OLD | NEW |