Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: net/socket/stream_listen_socket.cc

Issue 181063006: Gets the peer address (if available) in server requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated commit message, minor CR fix. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/socket/stream_listen_socket.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « net/socket/stream_listen_socket.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698