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

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: Diff upload failed 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
« net/server/http_server.cc ('K') | « 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 return MapSystemError(errno);
Ryan Sleevi 2014/03/11 01:32:43 |errno| won't be set on Win - it would be WSAGetLa
gunsch 2014/03/17 16:57:15 Done.
107 } else if (!address->FromSockAddr(storage.addr, storage.addr_len)) {
108 return ERR_FAILED;
Ryan Sleevi 2014/03/11 01:32:43 ERR_ADDRESS_INVALID
gunsch 2014/03/17 16:57:15 Hm, why ERR_ADDRESS_INVALID? In GetLocalAddress ab
Ryan Sleevi 2014/03/17 19:47:22 Matches the TCPClientSocket. I suspect the UDPCli
109 } else {
110 return OK;
Ryan Sleevi 2014/03/11 01:32:43 don't use else after return statements if (getpee
gunsch 2014/03/17 16:57:15 Done.
111 }
112 }
113
103 SocketDescriptor StreamListenSocket::AcceptSocket() { 114 SocketDescriptor StreamListenSocket::AcceptSocket() {
104 SocketDescriptor conn = HANDLE_EINTR(accept(socket_, NULL, NULL)); 115 SocketDescriptor conn = HANDLE_EINTR(accept(socket_, NULL, NULL));
105 if (conn == kInvalidSocket) 116 if (conn == kInvalidSocket)
106 LOG(ERROR) << "Error accepting connection."; 117 LOG(ERROR) << "Error accepting connection.";
107 else 118 else
108 SetNonBlocking(conn); 119 SetNonBlocking(conn);
109 return conn; 120 return conn;
110 } 121 }
111 122
112 void StreamListenSocket::SendInternal(const char* bytes, int len) { 123 void StreamListenSocket::SendInternal(const char* bytes, int len) {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 void StreamListenSocket::ResumeReads() { 309 void StreamListenSocket::ResumeReads() {
299 DCHECK(reads_paused_); 310 DCHECK(reads_paused_);
300 reads_paused_ = false; 311 reads_paused_ = false;
301 if (has_pending_reads_) { 312 if (has_pending_reads_) {
302 has_pending_reads_ = false; 313 has_pending_reads_ = false;
303 Read(); 314 Read();
304 } 315 }
305 } 316 }
306 317
307 } // namespace net 318 } // namespace net
OLDNEW
« net/server/http_server.cc ('K') | « net/socket/stream_listen_socket.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698