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

Side by Side Diff: net/udp/udp_socket_libevent.cc

Issue 22381012: Allow p2p UDP packages to set DSCP (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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
« net/udp/udp_socket_libevent.h ('K') | « net/udp/udp_socket_libevent.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/udp/udp_socket_libevent.h" 5 #include "net/udp/udp_socket_libevent.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <netdb.h> 9 #include <netdb.h>
10 #include <sys/socket.h> 10 #include <sys/socket.h>
(...skipping 23 matching lines...) Expand all
34 namespace net { 34 namespace net {
35 35
36 UDPSocketLibevent::UDPSocketLibevent( 36 UDPSocketLibevent::UDPSocketLibevent(
37 DatagramSocket::BindType bind_type, 37 DatagramSocket::BindType bind_type,
38 const RandIntCallback& rand_int_cb, 38 const RandIntCallback& rand_int_cb,
39 net::NetLog* net_log, 39 net::NetLog* net_log,
40 const net::NetLog::Source& source) 40 const net::NetLog::Source& source)
41 : socket_(kInvalidSocket), 41 : socket_(kInvalidSocket),
42 addr_family_(0), 42 addr_family_(0),
43 socket_options_(SOCKET_OPTION_MULTICAST_LOOP), 43 socket_options_(SOCKET_OPTION_MULTICAST_LOOP),
44 dscp_(0),
44 multicast_time_to_live_(1), 45 multicast_time_to_live_(1),
45 bind_type_(bind_type), 46 bind_type_(bind_type),
46 rand_int_cb_(rand_int_cb), 47 rand_int_cb_(rand_int_cb),
47 read_watcher_(this), 48 read_watcher_(this),
48 write_watcher_(this), 49 write_watcher_(this),
49 read_buf_len_(0), 50 read_buf_len_(0),
50 recv_from_address_(NULL), 51 recv_from_address_(NULL),
51 write_buf_len_(0), 52 write_buf_len_(0),
52 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_UDP_SOCKET)) { 53 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_UDP_SOCKET)) {
53 net_log_.BeginEvent(NetLog::TYPE_SOCKET_ALIVE, 54 net_log_.BeginEvent(NetLog::TYPE_SOCKET_ALIVE,
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 &ttl, sizeof(ttl)); 525 &ttl, sizeof(ttl));
525 } else { 526 } else {
526 // Signed interger. -1 to use route default. 527 // Signed interger. -1 to use route default.
527 int ttl = multicast_time_to_live_; 528 int ttl = multicast_time_to_live_;
528 rv = setsockopt(socket_, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, 529 rv = setsockopt(socket_, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
529 &ttl, sizeof(ttl)); 530 &ttl, sizeof(ttl));
530 } 531 }
531 if (rv < 0) 532 if (rv < 0)
532 return MapSystemError(errno); 533 return MapSystemError(errno);
533 } 534 }
535
536 if (dscp_) {
537 int rv;
538 int dscp_and_ecn = dscp_ << 2;
539 if (addr_family_ == AF_INET) {
540 rv = setsockopt(socket_, IPPROTO_IP, IP_TOS,
541 &dscp_and_ecn, sizeof(dscp_and_ecn));
542 } else {
543 rv = setsockopt(socket_, IPPROTO_IPV6, IPV6_TCLASS,
544 &dscp_and_ecn, sizeof(dscp_and_ecn));
545 }
546 if (rv < 0) {
547 LOG(INFO) << "Failed to set dscp, errno=" << errno;
548 }
549 }
534 return OK; 550 return OK;
535 } 551 }
536 552
537 int UDPSocketLibevent::DoBind(const IPEndPoint& address) { 553 int UDPSocketLibevent::DoBind(const IPEndPoint& address) {
538 SockaddrStorage storage; 554 SockaddrStorage storage;
539 if (!address.ToSockAddr(storage.addr, &storage.addr_len)) 555 if (!address.ToSockAddr(storage.addr, &storage.addr_len))
540 return ERR_ADDRESS_INVALID; 556 return ERR_ADDRESS_INVALID;
541 int rv = bind(socket_, storage.addr, storage.addr_len); 557 int rv = bind(socket_, storage.addr, storage.addr_len);
542 return rv < 0 ? MapSystemError(errno) : rv; 558 return rv < 0 ? MapSystemError(errno) : rv;
543 } 559 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 DCHECK(CalledOnValidThread()); 660 DCHECK(CalledOnValidThread());
645 if (is_connected()) 661 if (is_connected())
646 return ERR_SOCKET_IS_CONNECTED; 662 return ERR_SOCKET_IS_CONNECTED;
647 663
648 if (loopback) 664 if (loopback)
649 socket_options_ |= SOCKET_OPTION_MULTICAST_LOOP; 665 socket_options_ |= SOCKET_OPTION_MULTICAST_LOOP;
650 else 666 else
651 socket_options_ &= ~SOCKET_OPTION_MULTICAST_LOOP; 667 socket_options_ &= ~SOCKET_OPTION_MULTICAST_LOOP;
652 return OK; 668 return OK;
653 } 669 }
670
671 int UDPSocketLibevent::SetToS(int dscp) {
672 DCHECK_GE(dscp, 0);
673 DCHECK_LT(dscp, 64);
674 if (is_connected())
675 return ERR_SOCKET_IS_CONNECTED;
676
677 dscp_ = dscp;
678 return OK;
679 }
680
654 } // namespace net 681 } // namespace net
OLDNEW
« net/udp/udp_socket_libevent.h ('K') | « net/udp/udp_socket_libevent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698