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

Side by Side Diff: tools/android/forwarder2/socket.cc

Issue 137923004: Revert "Revert 235213 "android: forwader2: Simplify Forwarder implementa..."" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add DCHECK() in SetPeer() Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « tools/android/forwarder2/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 "tools/android/forwarder2/socket.h" 5 #include "tools/android/forwarder2/socket.h"
6 6
7 #include <arpa/inet.h> 7 #include <arpa/inet.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <netdb.h> 9 #include <netdb.h>
10 #include <netinet/in.h> 10 #include <netinet/in.h>
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 } 280 }
281 281
282 int Socket::GetPort() { 282 int Socket::GetPort() {
283 if (!FamilyIsTCP(family_)) { 283 if (!FamilyIsTCP(family_)) {
284 LOG(ERROR) << "Can't call GetPort() on an unix domain socket."; 284 LOG(ERROR) << "Can't call GetPort() on an unix domain socket.";
285 return 0; 285 return 0;
286 } 286 }
287 return port_; 287 return port_;
288 } 288 }
289 289
290 bool Socket::IsFdInSet(const fd_set& fds) const {
291 if (IsClosed())
292 return false;
293 return FD_ISSET(socket_, &fds);
294 }
295
296 bool Socket::AddFdToSet(fd_set* fds) const {
297 if (IsClosed())
298 return false;
299 FD_SET(socket_, fds);
300 return true;
301 }
302
303 int Socket::ReadNumBytes(void* buffer, size_t num_bytes) { 290 int Socket::ReadNumBytes(void* buffer, size_t num_bytes) {
304 int bytes_read = 0; 291 int bytes_read = 0;
305 int ret = 1; 292 int ret = 1;
306 while (bytes_read < num_bytes && ret > 0) { 293 while (bytes_read < num_bytes && ret > 0) {
307 ret = Read(static_cast<char*>(buffer) + bytes_read, num_bytes - bytes_read); 294 ret = Read(static_cast<char*>(buffer) + bytes_read, num_bytes - bytes_read);
308 if (ret >= 0) 295 if (ret >= 0)
309 bytes_read += ret; 296 bytes_read += ret;
310 } 297 }
311 return bytes_read; 298 return bytes_read;
312 } 299 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 for (size_t i = 0; i < events_.size(); ++i) { 422 for (size_t i = 0; i < events_.size(); ++i) {
436 if (FD_ISSET(events_[i].fd, &read_fds)) { 423 if (FD_ISSET(events_[i].fd, &read_fds)) {
437 events_[i].was_fired = true; 424 events_[i].was_fired = true;
438 event_was_fired = true; 425 event_was_fired = true;
439 } 426 }
440 } 427 }
441 return !event_was_fired; 428 return !event_was_fired;
442 } 429 }
443 430
444 // static 431 // static
445 int Socket::GetHighestFileDescriptor(const Socket& s1, const Socket& s2) {
446 return std::max(s1.socket_, s2.socket_);
447 }
448
449 // static
450 pid_t Socket::GetUnixDomainSocketProcessOwner(const std::string& path) { 432 pid_t Socket::GetUnixDomainSocketProcessOwner(const std::string& path) {
451 Socket socket; 433 Socket socket;
452 if (!socket.ConnectUnix(path)) 434 if (!socket.ConnectUnix(path))
453 return -1; 435 return -1;
454 ucred ucred; 436 ucred ucred;
455 socklen_t len = sizeof(ucred); 437 socklen_t len = sizeof(ucred);
456 if (getsockopt(socket.socket_, SOL_SOCKET, SO_PEERCRED, &ucred, &len) == -1) { 438 if (getsockopt(socket.socket_, SOL_SOCKET, SO_PEERCRED, &ucred, &len) == -1) {
457 CHECK_NE(ENOPROTOOPT, errno); 439 CHECK_NE(ENOPROTOOPT, errno);
458 return -1; 440 return -1;
459 } 441 }
460 return ucred.pid; 442 return ucred.pid;
461 } 443 }
462 444
463 } // namespace forwarder2 445 } // namespace forwarder2
OLDNEW
« no previous file with comments | « tools/android/forwarder2/socket.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698