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 "net/socket/stream_listen_socket.h" | 5 #include "net/socket/stream_listen_socket.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 // winsock2.h must be included first in order to ensure it is included before | 8 // winsock2.h must be included first in order to ensure it is included before |
9 // windows.h. | 9 // windows.h. |
10 #include <winsock2.h> | 10 #include <winsock2.h> |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 #else | 93 #else |
94 int err = errno; | 94 int err = errno; |
95 #endif | 95 #endif |
96 return MapSystemError(err); | 96 return MapSystemError(err); |
97 } | 97 } |
98 if (!address->FromSockAddr(storage.addr, storage.addr_len)) | 98 if (!address->FromSockAddr(storage.addr, storage.addr_len)) |
99 return ERR_FAILED; | 99 return ERR_FAILED; |
100 return OK; | 100 return OK; |
101 } | 101 } |
102 | 102 |
| 103 int StreamListenSocket::GetPeerAddress(IPEndPoint* address) { |
| 104 SockaddrStorage storage; |
| 105 if (getpeername(socket_, storage.addr, &storage.addr_len)) { |
| 106 #if defined(OS_WIN) |
| 107 int err = WSAGetLastError(); |
| 108 #else |
| 109 int err = errno; |
| 110 #endif |
| 111 return MapSystemError(err); |
| 112 } |
| 113 |
| 114 if (!address->FromSockAddr(storage.addr, storage.addr_len)) |
| 115 return ERR_ADDRESS_INVALID; |
| 116 |
| 117 return OK; |
| 118 } |
| 119 |
103 SocketDescriptor StreamListenSocket::AcceptSocket() { | 120 SocketDescriptor StreamListenSocket::AcceptSocket() { |
104 SocketDescriptor conn = HANDLE_EINTR(accept(socket_, NULL, NULL)); | 121 SocketDescriptor conn = HANDLE_EINTR(accept(socket_, NULL, NULL)); |
105 if (conn == kInvalidSocket) | 122 if (conn == kInvalidSocket) |
106 LOG(ERROR) << "Error accepting connection."; | 123 LOG(ERROR) << "Error accepting connection."; |
107 else | 124 else |
108 SetNonBlocking(conn); | 125 SetNonBlocking(conn); |
109 return conn; | 126 return conn; |
110 } | 127 } |
111 | 128 |
112 void StreamListenSocket::SendInternal(const char* bytes, int len) { | 129 void StreamListenSocket::SendInternal(const char* bytes, int len) { |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 void StreamListenSocket::ResumeReads() { | 315 void StreamListenSocket::ResumeReads() { |
299 DCHECK(reads_paused_); | 316 DCHECK(reads_paused_); |
300 reads_paused_ = false; | 317 reads_paused_ = false; |
301 if (has_pending_reads_) { | 318 if (has_pending_reads_) { |
302 has_pending_reads_ = false; | 319 has_pending_reads_ = false; |
303 Read(); | 320 Read(); |
304 } | 321 } |
305 } | 322 } |
306 | 323 |
307 } // namespace net | 324 } // namespace net |
OLD | NEW |