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

Side by Side Diff: webrtc/base/physicalsocketserver.cc

Issue 1362503003: Use suffixed {uint,int}{8,16,32,64}_t types. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase + revert basictypes.h (to be landed separately just in case of a revert due to unexpected us… Created 5 years, 2 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 | « webrtc/base/physicalsocketserver.h ('k') | webrtc/base/profiler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #endif // WEBRTC_POSIX 61 #endif // WEBRTC_POSIX
62 62
63 #if defined(WEBRTC_WIN) 63 #if defined(WEBRTC_WIN)
64 typedef char* SockOptArg; 64 typedef char* SockOptArg;
65 #endif 65 #endif
66 66
67 namespace rtc { 67 namespace rtc {
68 68
69 #if defined(WEBRTC_WIN) 69 #if defined(WEBRTC_WIN)
70 // Standard MTUs, from RFC 1191 70 // Standard MTUs, from RFC 1191
71 const uint16 PACKET_MAXIMUMS[] = { 71 const uint16_t PACKET_MAXIMUMS[] = {
72 65535, // Theoretical maximum, Hyperchannel 72 65535, // Theoretical maximum, Hyperchannel
73 32000, // Nothing 73 32000, // Nothing
74 17914, // 16Mb IBM Token Ring 74 17914, // 16Mb IBM Token Ring
75 8166, // IEEE 802.4 75 8166, // IEEE 802.4
76 //4464, // IEEE 802.5 (4Mb max) 76 // 4464, // IEEE 802.5 (4Mb max)
77 4352, // FDDI 77 4352, // FDDI
78 //2048, // Wideband Network 78 // 2048, // Wideband Network
79 2002, // IEEE 802.5 (4Mb recommended) 79 2002, // IEEE 802.5 (4Mb recommended)
80 //1536, // Expermental Ethernet Networks 80 // 1536, // Expermental Ethernet Networks
81 //1500, // Ethernet, Point-to-Point (default) 81 // 1500, // Ethernet, Point-to-Point (default)
82 1492, // IEEE 802.3 82 1492, // IEEE 802.3
83 1006, // SLIP, ARPANET 83 1006, // SLIP, ARPANET
84 //576, // X.25 Networks 84 // 576, // X.25 Networks
85 //544, // DEC IP Portal 85 // 544, // DEC IP Portal
86 //512, // NETBIOS 86 // 512, // NETBIOS
87 508, // IEEE 802/Source-Rt Bridge, ARCNET 87 508, // IEEE 802/Source-Rt Bridge, ARCNET
88 296, // Point-to-Point (low delay) 88 296, // Point-to-Point (low delay)
89 68, // Official minimum 89 68, // Official minimum
90 0, // End of list marker 90 0, // End of list marker
91 }; 91 };
92 92
93 static const int IP_HEADER_SIZE = 20u; 93 static const int IP_HEADER_SIZE = 20u;
94 static const int IPV6_HEADER_SIZE = 40u; 94 static const int IPV6_HEADER_SIZE = 40u;
95 static const int ICMP_HEADER_SIZE = 8u; 95 static const int ICMP_HEADER_SIZE = 8u;
96 static const int ICMP_PING_TIMEOUT_MILLIS = 10000u; 96 static const int ICMP_PING_TIMEOUT_MILLIS = 10000u;
97 #endif 97 #endif
98 98
99 class PhysicalSocket : public AsyncSocket, public sigslot::has_slots<> { 99 class PhysicalSocket : public AsyncSocket, public sigslot::has_slots<> {
100 public: 100 public:
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 s_ = INVALID_SOCKET; 391 s_ = INVALID_SOCKET;
392 state_ = CS_CLOSED; 392 state_ = CS_CLOSED;
393 enabled_events_ = 0; 393 enabled_events_ = 0;
394 if (resolver_) { 394 if (resolver_) {
395 resolver_->Destroy(false); 395 resolver_->Destroy(false);
396 resolver_ = NULL; 396 resolver_ = NULL;
397 } 397 }
398 return err; 398 return err;
399 } 399 }
400 400
401 int EstimateMTU(uint16* mtu) override { 401 int EstimateMTU(uint16_t* mtu) override {
402 SocketAddress addr = GetRemoteAddress(); 402 SocketAddress addr = GetRemoteAddress();
403 if (addr.IsAny()) { 403 if (addr.IsAny()) {
404 SetError(ENOTCONN); 404 SetError(ENOTCONN);
405 return -1; 405 return -1;
406 } 406 }
407 407
408 #if defined(WEBRTC_WIN) 408 #if defined(WEBRTC_WIN)
409 // Gets the interface MTU (TTL=1) for the interface used to reach |addr|. 409 // Gets the interface MTU (TTL=1) for the interface used to reach |addr|.
410 WinPing ping; 410 WinPing ping;
411 if (!ping.IsValid()) { 411 if (!ping.IsValid()) {
412 SetError(EINVAL); // can't think of a better error ID 412 SetError(EINVAL); // can't think of a better error ID
413 return -1; 413 return -1;
414 } 414 }
415 int header_size = ICMP_HEADER_SIZE; 415 int header_size = ICMP_HEADER_SIZE;
416 if (addr.family() == AF_INET6) { 416 if (addr.family() == AF_INET6) {
417 header_size += IPV6_HEADER_SIZE; 417 header_size += IPV6_HEADER_SIZE;
418 } else if (addr.family() == AF_INET) { 418 } else if (addr.family() == AF_INET) {
419 header_size += IP_HEADER_SIZE; 419 header_size += IP_HEADER_SIZE;
420 } 420 }
421 421
422 for (int level = 0; PACKET_MAXIMUMS[level + 1] > 0; ++level) { 422 for (int level = 0; PACKET_MAXIMUMS[level + 1] > 0; ++level) {
423 int32 size = PACKET_MAXIMUMS[level] - header_size; 423 int32_t size = PACKET_MAXIMUMS[level] - header_size;
424 WinPing::PingResult result = ping.Ping(addr.ipaddr(), size, 424 WinPing::PingResult result = ping.Ping(addr.ipaddr(), size,
425 ICMP_PING_TIMEOUT_MILLIS, 425 ICMP_PING_TIMEOUT_MILLIS,
426 1, false); 426 1, false);
427 if (result == WinPing::PING_FAIL) { 427 if (result == WinPing::PING_FAIL) {
428 SetError(EINVAL); // can't think of a better error ID 428 SetError(EINVAL); // can't think of a better error ID
429 return -1; 429 return -1;
430 } else if (result != WinPing::PING_TOO_LARGE) { 430 } else if (result != WinPing::PING_TOO_LARGE) {
431 *mtu = PACKET_MAXIMUMS[level]; 431 *mtu = PACKET_MAXIMUMS[level];
432 return 0; 432 return 0;
433 } 433 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 return -1; // No logging is necessary as this not a OS socket option. 534 return -1; // No logging is necessary as this not a OS socket option.
535 default: 535 default:
536 ASSERT(false); 536 ASSERT(false);
537 return -1; 537 return -1;
538 } 538 }
539 return 0; 539 return 0;
540 } 540 }
541 541
542 PhysicalSocketServer* ss_; 542 PhysicalSocketServer* ss_;
543 SOCKET s_; 543 SOCKET s_;
544 uint8 enabled_events_; 544 uint8_t enabled_events_;
545 bool udp_; 545 bool udp_;
546 int error_; 546 int error_;
547 // Protects |error_| that is accessed from different threads. 547 // Protects |error_| that is accessed from different threads.
548 mutable CriticalSection crit_; 548 mutable CriticalSection crit_;
549 ConnState state_; 549 ConnState state_;
550 AsyncResolver* resolver_; 550 AsyncResolver* resolver_;
551 551
552 #ifdef _DEBUG 552 #ifdef _DEBUG
553 std::string dbg_addr_; 553 std::string dbg_addr_;
554 #endif // _DEBUG; 554 #endif // _DEBUG;
(...skipping 10 matching lines...) Expand all
565 565
566 ~EventDispatcher() override { 566 ~EventDispatcher() override {
567 ss_->Remove(this); 567 ss_->Remove(this);
568 close(afd_[0]); 568 close(afd_[0]);
569 close(afd_[1]); 569 close(afd_[1]);
570 } 570 }
571 571
572 virtual void Signal() { 572 virtual void Signal() {
573 CritScope cs(&crit_); 573 CritScope cs(&crit_);
574 if (!fSignaled_) { 574 if (!fSignaled_) {
575 const uint8 b[1] = { 0 }; 575 const uint8_t b[1] = {0};
576 if (VERIFY(1 == write(afd_[1], b, sizeof(b)))) { 576 if (VERIFY(1 == write(afd_[1], b, sizeof(b)))) {
577 fSignaled_ = true; 577 fSignaled_ = true;
578 } 578 }
579 } 579 }
580 } 580 }
581 581
582 uint32 GetRequestedEvents() override { return DE_READ; } 582 uint32_t GetRequestedEvents() override { return DE_READ; }
583 583
584 void OnPreEvent(uint32 ff) override { 584 void OnPreEvent(uint32_t ff) override {
585 // It is not possible to perfectly emulate an auto-resetting event with 585 // It is not possible to perfectly emulate an auto-resetting event with
586 // pipes. This simulates it by resetting before the event is handled. 586 // pipes. This simulates it by resetting before the event is handled.
587 587
588 CritScope cs(&crit_); 588 CritScope cs(&crit_);
589 if (fSignaled_) { 589 if (fSignaled_) {
590 uint8 b[4]; // Allow for reading more than 1 byte, but expect 1. 590 uint8_t b[4]; // Allow for reading more than 1 byte, but expect 1.
591 VERIFY(1 == read(afd_[0], b, sizeof(b))); 591 VERIFY(1 == read(afd_[0], b, sizeof(b)));
592 fSignaled_ = false; 592 fSignaled_ = false;
593 } 593 }
594 } 594 }
595 595
596 void OnEvent(uint32 ff, int err) override { ASSERT(false); } 596 void OnEvent(uint32_t ff, int err) override { ASSERT(false); }
597 597
598 int GetDescriptor() override { return afd_[0]; } 598 int GetDescriptor() override { return afd_[0]; }
599 599
600 bool IsDescriptorClosed() override { return false; } 600 bool IsDescriptorClosed() override { return false; }
601 601
602 private: 602 private:
603 PhysicalSocketServer *ss_; 603 PhysicalSocketServer *ss_;
604 int afd_[2]; 604 int afd_[2];
605 bool fSignaled_; 605 bool fSignaled_;
606 CriticalSection crit_; 606 CriticalSection crit_;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 // user-level state of the process, since the handler could be executed at any 654 // user-level state of the process, since the handler could be executed at any
655 // time on any thread. 655 // time on any thread.
656 void OnPosixSignalReceived(int signum) { 656 void OnPosixSignalReceived(int signum) {
657 if (signum >= ARRAY_SIZE(received_signal_)) { 657 if (signum >= ARRAY_SIZE(received_signal_)) {
658 // We don't have space in our array for this. 658 // We don't have space in our array for this.
659 return; 659 return;
660 } 660 }
661 // Set a flag saying we've seen this signal. 661 // Set a flag saying we've seen this signal.
662 received_signal_[signum] = true; 662 received_signal_[signum] = true;
663 // Notify application code that we got a signal. 663 // Notify application code that we got a signal.
664 const uint8 b[1] = { 0 }; 664 const uint8_t b[1] = {0};
665 if (-1 == write(afd_[1], b, sizeof(b))) { 665 if (-1 == write(afd_[1], b, sizeof(b))) {
666 // Nothing we can do here. If there's an error somehow then there's 666 // Nothing we can do here. If there's an error somehow then there's
667 // nothing we can safely do from a signal handler. 667 // nothing we can safely do from a signal handler.
668 // No, we can't even safely log it. 668 // No, we can't even safely log it.
669 // But, we still have to check the return value here. Otherwise, 669 // But, we still have to check the return value here. Otherwise,
670 // GCC 4.4.1 complains ignoring return value. Even (void) doesn't help. 670 // GCC 4.4.1 complains ignoring return value. Even (void) doesn't help.
671 return; 671 return;
672 } 672 }
673 } 673 }
674 674
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 // These are boolean flags that will be set in our signal handler and read 711 // These are boolean flags that will be set in our signal handler and read
712 // and cleared from Wait(). There is a race involved in this, but it is 712 // and cleared from Wait(). There is a race involved in this, but it is
713 // benign. The signal handler sets the flag before signaling the pipe, so 713 // benign. The signal handler sets the flag before signaling the pipe, so
714 // we'll never end up blocking in select() while a flag is still true. 714 // we'll never end up blocking in select() while a flag is still true.
715 // However, if two of the same signal arrive close to each other then it's 715 // However, if two of the same signal arrive close to each other then it's
716 // possible that the second time the handler may set the flag while it's still 716 // possible that the second time the handler may set the flag while it's still
717 // true, meaning that signal will be missed. But the first occurrence of it 717 // true, meaning that signal will be missed. But the first occurrence of it
718 // will still be handled, so this isn't a problem. 718 // will still be handled, so this isn't a problem.
719 // Volatile is not necessary here for correctness, but this data _is_ volatile 719 // Volatile is not necessary here for correctness, but this data _is_ volatile
720 // so I've marked it as such. 720 // so I've marked it as such.
721 volatile uint8 received_signal_[kNumPosixSignals]; 721 volatile uint8_t received_signal_[kNumPosixSignals];
722 }; 722 };
723 723
724 class PosixSignalDispatcher : public Dispatcher { 724 class PosixSignalDispatcher : public Dispatcher {
725 public: 725 public:
726 PosixSignalDispatcher(PhysicalSocketServer *owner) : owner_(owner) { 726 PosixSignalDispatcher(PhysicalSocketServer *owner) : owner_(owner) {
727 owner_->Add(this); 727 owner_->Add(this);
728 } 728 }
729 729
730 ~PosixSignalDispatcher() override { 730 ~PosixSignalDispatcher() override {
731 owner_->Remove(this); 731 owner_->Remove(this);
732 } 732 }
733 733
734 uint32 GetRequestedEvents() override { return DE_READ; } 734 uint32_t GetRequestedEvents() override { return DE_READ; }
735 735
736 void OnPreEvent(uint32 ff) override { 736 void OnPreEvent(uint32_t ff) override {
737 // Events might get grouped if signals come very fast, so we read out up to 737 // Events might get grouped if signals come very fast, so we read out up to
738 // 16 bytes to make sure we keep the pipe empty. 738 // 16 bytes to make sure we keep the pipe empty.
739 uint8 b[16]; 739 uint8_t b[16];
740 ssize_t ret = read(GetDescriptor(), b, sizeof(b)); 740 ssize_t ret = read(GetDescriptor(), b, sizeof(b));
741 if (ret < 0) { 741 if (ret < 0) {
742 LOG_ERR(LS_WARNING) << "Error in read()"; 742 LOG_ERR(LS_WARNING) << "Error in read()";
743 } else if (ret == 0) { 743 } else if (ret == 0) {
744 LOG(LS_WARNING) << "Should have read at least one byte"; 744 LOG(LS_WARNING) << "Should have read at least one byte";
745 } 745 }
746 } 746 }
747 747
748 void OnEvent(uint32 ff, int err) override { 748 void OnEvent(uint32_t ff, int err) override {
749 for (int signum = 0; signum < PosixSignalHandler::kNumPosixSignals; 749 for (int signum = 0; signum < PosixSignalHandler::kNumPosixSignals;
750 ++signum) { 750 ++signum) {
751 if (PosixSignalHandler::Instance()->IsSignalSet(signum)) { 751 if (PosixSignalHandler::Instance()->IsSignalSet(signum)) {
752 PosixSignalHandler::Instance()->ClearSignal(signum); 752 PosixSignalHandler::Instance()->ClearSignal(signum);
753 HandlerMap::iterator i = handlers_.find(signum); 753 HandlerMap::iterator i = handlers_.find(signum);
754 if (i == handlers_.end()) { 754 if (i == handlers_.end()) {
755 // This can happen if a signal is delivered to our process at around 755 // This can happen if a signal is delivered to our process at around
756 // the same time as we unset our handler for it. It is not an error 756 // the same time as we unset our handler for it. It is not an error
757 // condition, but it's unusual enough to be worth logging. 757 // condition, but it's unusual enough to be worth logging.
758 LOG(LS_INFO) << "Received signal with no handler: " << signum; 758 LOG(LS_INFO) << "Received signal with no handler: " << signum;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 // it's not necessary a problem if we spuriously interpret a 849 // it's not necessary a problem if we spuriously interpret a
850 // "connection lost"-type error as a blocking error, because typically 850 // "connection lost"-type error as a blocking error, because typically
851 // the next recv() will get EOF, so we'll still eventually notice that 851 // the next recv() will get EOF, so we'll still eventually notice that
852 // the socket is closed. 852 // the socket is closed.
853 LOG_ERR(LS_WARNING) << "Assuming benign blocking error"; 853 LOG_ERR(LS_WARNING) << "Assuming benign blocking error";
854 return false; 854 return false;
855 } 855 }
856 } 856 }
857 } 857 }
858 858
859 uint32 GetRequestedEvents() override { return enabled_events_; } 859 uint32_t GetRequestedEvents() override { return enabled_events_; }
860 860
861 void OnPreEvent(uint32 ff) override { 861 void OnPreEvent(uint32_t ff) override {
862 if ((ff & DE_CONNECT) != 0) 862 if ((ff & DE_CONNECT) != 0)
863 state_ = CS_CONNECTED; 863 state_ = CS_CONNECTED;
864 if ((ff & DE_CLOSE) != 0) 864 if ((ff & DE_CLOSE) != 0)
865 state_ = CS_CLOSED; 865 state_ = CS_CLOSED;
866 } 866 }
867 867
868 void OnEvent(uint32 ff, int err) override { 868 void OnEvent(uint32_t ff, int err) override {
869 // Make sure we deliver connect/accept first. Otherwise, consumers may see 869 // Make sure we deliver connect/accept first. Otherwise, consumers may see
870 // something like a READ followed by a CONNECT, which would be odd. 870 // something like a READ followed by a CONNECT, which would be odd.
871 if ((ff & DE_CONNECT) != 0) { 871 if ((ff & DE_CONNECT) != 0) {
872 enabled_events_ &= ~DE_CONNECT; 872 enabled_events_ &= ~DE_CONNECT;
873 SignalConnectEvent(this); 873 SignalConnectEvent(this);
874 } 874 }
875 if ((ff & DE_ACCEPT) != 0) { 875 if ((ff & DE_ACCEPT) != 0) {
876 enabled_events_ &= ~DE_ACCEPT; 876 enabled_events_ &= ~DE_ACCEPT;
877 SignalReadEvent(this); 877 SignalReadEvent(this);
878 } 878 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 ~FileDispatcher() override { 913 ~FileDispatcher() override {
914 ss_->Remove(this); 914 ss_->Remove(this);
915 } 915 }
916 916
917 SocketServer* socketserver() { return ss_; } 917 SocketServer* socketserver() { return ss_; }
918 918
919 int GetDescriptor() override { return fd_; } 919 int GetDescriptor() override { return fd_; }
920 920
921 bool IsDescriptorClosed() override { return false; } 921 bool IsDescriptorClosed() override { return false; }
922 922
923 uint32 GetRequestedEvents() override { return flags_; } 923 uint32_t GetRequestedEvents() override { return flags_; }
924 924
925 void OnPreEvent(uint32 ff) override {} 925 void OnPreEvent(uint32_t ff) override {}
926 926
927 void OnEvent(uint32 ff, int err) override { 927 void OnEvent(uint32_t ff, int err) override {
928 if ((ff & DE_READ) != 0) 928 if ((ff & DE_READ) != 0)
929 SignalReadEvent(this); 929 SignalReadEvent(this);
930 if ((ff & DE_WRITE) != 0) 930 if ((ff & DE_WRITE) != 0)
931 SignalWriteEvent(this); 931 SignalWriteEvent(this);
932 if ((ff & DE_CLOSE) != 0) 932 if ((ff & DE_CLOSE) != 0)
933 SignalCloseEvent(this, err); 933 SignalCloseEvent(this, err);
934 } 934 }
935 935
936 bool readable() override { return (flags_ & DE_READ) != 0; } 936 bool readable() override { return (flags_ & DE_READ) != 0; }
937 937
(...skipping 13 matching lines...) Expand all
951 int flags_; 951 int flags_;
952 }; 952 };
953 953
954 AsyncFile* PhysicalSocketServer::CreateFile(int fd) { 954 AsyncFile* PhysicalSocketServer::CreateFile(int fd) {
955 return new FileDispatcher(fd, this); 955 return new FileDispatcher(fd, this);
956 } 956 }
957 957
958 #endif // WEBRTC_POSIX 958 #endif // WEBRTC_POSIX
959 959
960 #if defined(WEBRTC_WIN) 960 #if defined(WEBRTC_WIN)
961 static uint32 FlagsToEvents(uint32 events) { 961 static uint32_t FlagsToEvents(uint32_t events) {
962 uint32 ffFD = FD_CLOSE; 962 uint32_t ffFD = FD_CLOSE;
963 if (events & DE_READ) 963 if (events & DE_READ)
964 ffFD |= FD_READ; 964 ffFD |= FD_READ;
965 if (events & DE_WRITE) 965 if (events & DE_WRITE)
966 ffFD |= FD_WRITE; 966 ffFD |= FD_WRITE;
967 if (events & DE_CONNECT) 967 if (events & DE_CONNECT)
968 ffFD |= FD_CONNECT; 968 ffFD |= FD_CONNECT;
969 if (events & DE_ACCEPT) 969 if (events & DE_ACCEPT)
970 ffFD |= FD_ACCEPT; 970 ffFD |= FD_ACCEPT;
971 return ffFD; 971 return ffFD;
972 } 972 }
(...skipping 13 matching lines...) Expand all
986 WSACloseEvent(hev_); 986 WSACloseEvent(hev_);
987 hev_ = NULL; 987 hev_ = NULL;
988 } 988 }
989 } 989 }
990 990
991 virtual void Signal() { 991 virtual void Signal() {
992 if (hev_ != NULL) 992 if (hev_ != NULL)
993 WSASetEvent(hev_); 993 WSASetEvent(hev_);
994 } 994 }
995 995
996 virtual uint32 GetRequestedEvents() { 996 virtual uint32_t GetRequestedEvents() { return 0; }
997 return 0;
998 }
999 997
1000 virtual void OnPreEvent(uint32 ff) { 998 virtual void OnPreEvent(uint32_t ff) { WSAResetEvent(hev_); }
1001 WSAResetEvent(hev_);
1002 }
1003 999
1004 virtual void OnEvent(uint32 ff, int err) { 1000 virtual void OnEvent(uint32_t ff, int err) {}
1005 }
1006 1001
1007 virtual WSAEVENT GetWSAEvent() { 1002 virtual WSAEVENT GetWSAEvent() {
1008 return hev_; 1003 return hev_;
1009 } 1004 }
1010 1005
1011 virtual SOCKET GetSocket() { 1006 virtual SOCKET GetSocket() {
1012 return INVALID_SOCKET; 1007 return INVALID_SOCKET;
1013 } 1008 }
1014 1009
1015 virtual bool CheckSignalClose() { return false; } 1010 virtual bool CheckSignalClose() { return false; }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 virtual int Close() { 1065 virtual int Close() {
1071 if (s_ == INVALID_SOCKET) 1066 if (s_ == INVALID_SOCKET)
1072 return 0; 1067 return 0;
1073 1068
1074 id_ = 0; 1069 id_ = 0;
1075 signal_close_ = false; 1070 signal_close_ = false;
1076 ss_->Remove(this); 1071 ss_->Remove(this);
1077 return PhysicalSocket::Close(); 1072 return PhysicalSocket::Close();
1078 } 1073 }
1079 1074
1080 virtual uint32 GetRequestedEvents() { 1075 virtual uint32_t GetRequestedEvents() { return enabled_events_; }
1081 return enabled_events_;
1082 }
1083 1076
1084 virtual void OnPreEvent(uint32 ff) { 1077 virtual void OnPreEvent(uint32_t ff) {
1085 if ((ff & DE_CONNECT) != 0) 1078 if ((ff & DE_CONNECT) != 0)
1086 state_ = CS_CONNECTED; 1079 state_ = CS_CONNECTED;
1087 // We set CS_CLOSED from CheckSignalClose. 1080 // We set CS_CLOSED from CheckSignalClose.
1088 } 1081 }
1089 1082
1090 virtual void OnEvent(uint32 ff, int err) { 1083 virtual void OnEvent(uint32_t ff, int err) {
1091 int cache_id = id_; 1084 int cache_id = id_;
1092 // Make sure we deliver connect/accept first. Otherwise, consumers may see 1085 // Make sure we deliver connect/accept first. Otherwise, consumers may see
1093 // something like a READ followed by a CONNECT, which would be odd. 1086 // something like a READ followed by a CONNECT, which would be odd.
1094 if (((ff & DE_CONNECT) != 0) && (id_ == cache_id)) { 1087 if (((ff & DE_CONNECT) != 0) && (id_ == cache_id)) {
1095 if (ff != DE_CONNECT) 1088 if (ff != DE_CONNECT)
1096 LOG(LS_VERBOSE) << "Signalled with DE_CONNECT: " << ff; 1089 LOG(LS_VERBOSE) << "Signalled with DE_CONNECT: " << ff;
1097 enabled_events_ &= ~DE_CONNECT; 1090 enabled_events_ &= ~DE_CONNECT;
1098 #ifdef _DEBUG 1091 #ifdef _DEBUG
1099 dbg_addr_ = "Connected @ "; 1092 dbg_addr_ = "Connected @ ";
1100 dbg_addr_.append(GetRemoteAddress().ToString()); 1093 dbg_addr_.append(GetRemoteAddress().ToString());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 #endif // WEBRTC_WIN 1140 #endif // WEBRTC_WIN
1148 1141
1149 // Sets the value of a boolean value to false when signaled. 1142 // Sets the value of a boolean value to false when signaled.
1150 class Signaler : public EventDispatcher { 1143 class Signaler : public EventDispatcher {
1151 public: 1144 public:
1152 Signaler(PhysicalSocketServer* ss, bool* pf) 1145 Signaler(PhysicalSocketServer* ss, bool* pf)
1153 : EventDispatcher(ss), pf_(pf) { 1146 : EventDispatcher(ss), pf_(pf) {
1154 } 1147 }
1155 ~Signaler() override { } 1148 ~Signaler() override { }
1156 1149
1157 void OnEvent(uint32 ff, int err) override { 1150 void OnEvent(uint32_t ff, int err) override {
1158 if (pf_) 1151 if (pf_)
1159 *pf_ = false; 1152 *pf_ = false;
1160 } 1153 }
1161 1154
1162 private: 1155 private:
1163 bool *pf_; 1156 bool *pf_;
1164 }; 1157 };
1165 1158
1166 PhysicalSocketServer::PhysicalSocketServer() 1159 PhysicalSocketServer::PhysicalSocketServer()
1167 : fWait_(false) { 1160 : fWait_(false) {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 for (size_t i = 0; i < dispatchers_.size(); ++i) { 1298 for (size_t i = 0; i < dispatchers_.size(); ++i) {
1306 // Query dispatchers for read and write wait state 1299 // Query dispatchers for read and write wait state
1307 Dispatcher *pdispatcher = dispatchers_[i]; 1300 Dispatcher *pdispatcher = dispatchers_[i];
1308 ASSERT(pdispatcher); 1301 ASSERT(pdispatcher);
1309 if (!process_io && (pdispatcher != signal_wakeup_)) 1302 if (!process_io && (pdispatcher != signal_wakeup_))
1310 continue; 1303 continue;
1311 int fd = pdispatcher->GetDescriptor(); 1304 int fd = pdispatcher->GetDescriptor();
1312 if (fd > fdmax) 1305 if (fd > fdmax)
1313 fdmax = fd; 1306 fdmax = fd;
1314 1307
1315 uint32 ff = pdispatcher->GetRequestedEvents(); 1308 uint32_t ff = pdispatcher->GetRequestedEvents();
1316 if (ff & (DE_READ | DE_ACCEPT)) 1309 if (ff & (DE_READ | DE_ACCEPT))
1317 FD_SET(fd, &fdsRead); 1310 FD_SET(fd, &fdsRead);
1318 if (ff & (DE_WRITE | DE_CONNECT)) 1311 if (ff & (DE_WRITE | DE_CONNECT))
1319 FD_SET(fd, &fdsWrite); 1312 FD_SET(fd, &fdsWrite);
1320 } 1313 }
1321 } 1314 }
1322 1315
1323 // Wait then call handlers as appropriate 1316 // Wait then call handlers as appropriate
1324 // < 0 means error 1317 // < 0 means error
1325 // 0 means timeout 1318 // 0 means timeout
(...skipping 12 matching lines...) Expand all
1338 // iteration. 1331 // iteration.
1339 } else if (n == 0) { 1332 } else if (n == 0) {
1340 // If timeout, return success 1333 // If timeout, return success
1341 return true; 1334 return true;
1342 } else { 1335 } else {
1343 // We have signaled descriptors 1336 // We have signaled descriptors
1344 CritScope cr(&crit_); 1337 CritScope cr(&crit_);
1345 for (size_t i = 0; i < dispatchers_.size(); ++i) { 1338 for (size_t i = 0; i < dispatchers_.size(); ++i) {
1346 Dispatcher *pdispatcher = dispatchers_[i]; 1339 Dispatcher *pdispatcher = dispatchers_[i];
1347 int fd = pdispatcher->GetDescriptor(); 1340 int fd = pdispatcher->GetDescriptor();
1348 uint32 ff = 0; 1341 uint32_t ff = 0;
1349 int errcode = 0; 1342 int errcode = 0;
1350 1343
1351 // Reap any error code, which can be signaled through reads or writes. 1344 // Reap any error code, which can be signaled through reads or writes.
1352 // TODO: Should we set errcode if getsockopt fails? 1345 // TODO: Should we set errcode if getsockopt fails?
1353 if (FD_ISSET(fd, &fdsRead) || FD_ISSET(fd, &fdsWrite)) { 1346 if (FD_ISSET(fd, &fdsRead) || FD_ISSET(fd, &fdsWrite)) {
1354 socklen_t len = sizeof(errcode); 1347 socklen_t len = sizeof(errcode);
1355 ::getsockopt(fd, SOL_SOCKET, SO_ERROR, &errcode, &len); 1348 ::getsockopt(fd, SOL_SOCKET, SO_ERROR, &errcode, &len);
1356 } 1349 }
1357 1350
1358 // Check readable descriptors. If we're waiting on an accept, signal 1351 // Check readable descriptors. If we're waiting on an accept, signal
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 return false; 1465 return false;
1473 } 1466 }
1474 return true; 1467 return true;
1475 } 1468 }
1476 #endif // WEBRTC_POSIX 1469 #endif // WEBRTC_POSIX
1477 1470
1478 #if defined(WEBRTC_WIN) 1471 #if defined(WEBRTC_WIN)
1479 bool PhysicalSocketServer::Wait(int cmsWait, bool process_io) { 1472 bool PhysicalSocketServer::Wait(int cmsWait, bool process_io) {
1480 int cmsTotal = cmsWait; 1473 int cmsTotal = cmsWait;
1481 int cmsElapsed = 0; 1474 int cmsElapsed = 0;
1482 uint32 msStart = Time(); 1475 uint32_t msStart = Time();
1483 1476
1484 fWait_ = true; 1477 fWait_ = true;
1485 while (fWait_) { 1478 while (fWait_) {
1486 std::vector<WSAEVENT> events; 1479 std::vector<WSAEVENT> events;
1487 std::vector<Dispatcher *> event_owners; 1480 std::vector<Dispatcher *> event_owners;
1488 1481
1489 events.push_back(socket_ev_); 1482 events.push_back(socket_ev_);
1490 1483
1491 { 1484 {
1492 CritScope cr(&crit_); 1485 CritScope cr(&crit_);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1583 LOG(WARNING) << "PhysicalSocketServer got FD_ACCEPT_BIT error " 1576 LOG(WARNING) << "PhysicalSocketServer got FD_ACCEPT_BIT error "
1584 << wsaEvents.iErrorCode[FD_ACCEPT_BIT]; 1577 << wsaEvents.iErrorCode[FD_ACCEPT_BIT];
1585 } 1578 }
1586 if ((wsaEvents.lNetworkEvents & FD_CLOSE) && 1579 if ((wsaEvents.lNetworkEvents & FD_CLOSE) &&
1587 wsaEvents.iErrorCode[FD_CLOSE_BIT] != 0) { 1580 wsaEvents.iErrorCode[FD_CLOSE_BIT] != 0) {
1588 LOG(WARNING) << "PhysicalSocketServer got FD_CLOSE_BIT error " 1581 LOG(WARNING) << "PhysicalSocketServer got FD_CLOSE_BIT error "
1589 << wsaEvents.iErrorCode[FD_CLOSE_BIT]; 1582 << wsaEvents.iErrorCode[FD_CLOSE_BIT];
1590 } 1583 }
1591 } 1584 }
1592 #endif 1585 #endif
1593 uint32 ff = 0; 1586 uint32_t ff = 0;
1594 int errcode = 0; 1587 int errcode = 0;
1595 if (wsaEvents.lNetworkEvents & FD_READ) 1588 if (wsaEvents.lNetworkEvents & FD_READ)
1596 ff |= DE_READ; 1589 ff |= DE_READ;
1597 if (wsaEvents.lNetworkEvents & FD_WRITE) 1590 if (wsaEvents.lNetworkEvents & FD_WRITE)
1598 ff |= DE_WRITE; 1591 ff |= DE_WRITE;
1599 if (wsaEvents.lNetworkEvents & FD_CONNECT) { 1592 if (wsaEvents.lNetworkEvents & FD_CONNECT) {
1600 if (wsaEvents.iErrorCode[FD_CONNECT_BIT] == 0) { 1593 if (wsaEvents.iErrorCode[FD_CONNECT_BIT] == 0) {
1601 ff |= DE_CONNECT; 1594 ff |= DE_CONNECT;
1602 } else { 1595 } else {
1603 ff |= DE_CLOSE; 1596 ff |= DE_CLOSE;
(...skipping 30 matching lines...) Expand all
1634 break; 1627 break;
1635 } 1628 }
1636 } 1629 }
1637 1630
1638 // Done 1631 // Done
1639 return true; 1632 return true;
1640 } 1633 }
1641 #endif // WEBRTC_WIN 1634 #endif // WEBRTC_WIN
1642 1635
1643 } // namespace rtc 1636 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/physicalsocketserver.h ('k') | webrtc/base/profiler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698