| OLD | NEW |
| 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 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 namespace rtc { | 22 namespace rtc { |
| 23 | 23 |
| 24 /////////////////////////////////////////////////////////////////////////////// | 24 /////////////////////////////////////////////////////////////////////////////// |
| 25 // Win32Socket | 25 // Win32Socket |
| 26 /////////////////////////////////////////////////////////////////////////////// | 26 /////////////////////////////////////////////////////////////////////////////// |
| 27 | 27 |
| 28 // TODO: Move this to a common place where PhysicalSocketServer can | 28 // TODO: Move this to a common place where PhysicalSocketServer can |
| 29 // share it. | 29 // share it. |
| 30 // Standard MTUs | 30 // Standard MTUs |
| 31 static const uint16 PACKET_MAXIMUMS[] = { | 31 static const uint16_t PACKET_MAXIMUMS[] = { |
| 32 65535, // Theoretical maximum, Hyperchannel | 32 65535, // Theoretical maximum, Hyperchannel |
| 33 32000, // Nothing | 33 32000, // Nothing |
| 34 17914, // 16Mb IBM Token Ring | 34 17914, // 16Mb IBM Token Ring |
| 35 8166, // IEEE 802.4 | 35 8166, // IEEE 802.4 |
| 36 // 4464 // IEEE 802.5 (4Mb max) | 36 // 4464 // IEEE 802.5 (4Mb max) |
| 37 4352, // FDDI | 37 4352, // FDDI |
| 38 // 2048, // Wideband Network | 38 // 2048, // Wideband Network |
| 39 2002, // IEEE 802.5 (4Mb recommended) | 39 2002, // IEEE 802.5 (4Mb recommended) |
| 40 // 1536, // Expermental Ethernet Networks | 40 // 1536, // Expermental Ethernet Networks |
| 41 // 1500, // Ethernet, Point-to-Point (default) | 41 // 1500, // Ethernet, Point-to-Point (default) |
| 42 1492, // IEEE 802.3 | 42 1492, // IEEE 802.3 |
| 43 1006, // SLIP, ARPANET | 43 1006, // SLIP, ARPANET |
| 44 // 576, // X.25 Networks | 44 // 576, // X.25 Networks |
| 45 // 544, // DEC IP Portal | 45 // 544, // DEC IP Portal |
| 46 // 512, // NETBIOS | 46 // 512, // NETBIOS |
| 47 508, // IEEE 802/Source-Rt Bridge, ARCNET | 47 508, // IEEE 802/Source-Rt Bridge, ARCNET |
| 48 296, // Point-to-Point (low delay) | 48 296, // Point-to-Point (low delay) |
| 49 68, // Official minimum | 49 68, // Official minimum |
| 50 0, // End of list marker | 50 0, // End of list marker |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 static const int IP_HEADER_SIZE = 20u; | 53 static const int IP_HEADER_SIZE = 20u; |
| 54 static const int ICMP_HEADER_SIZE = 8u; | 54 static const int ICMP_HEADER_SIZE = 8u; |
| 55 static const int ICMP_PING_TIMEOUT_MILLIS = 10000u; | 55 static const int ICMP_PING_TIMEOUT_MILLIS = 10000u; |
| 56 | 56 |
| 57 // TODO: Enable for production builds also? Use FormatMessage? | 57 // TODO: Enable for production builds also? Use FormatMessage? |
| 58 #ifdef _DEBUG | 58 #ifdef _DEBUG |
| 59 LPCSTR WSAErrorToString(int error, LPCSTR *description_result) { | 59 LPCSTR WSAErrorToString(int error, LPCSTR *description_result) { |
| 60 LPCSTR string = "Unspecified"; | 60 LPCSTR string = "Unspecified"; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 136 |
| 137 ///////////////////////////////////////////////////////////////////////////// | 137 ///////////////////////////////////////////////////////////////////////////// |
| 138 // Win32Socket::EventSink | 138 // Win32Socket::EventSink |
| 139 ///////////////////////////////////////////////////////////////////////////// | 139 ///////////////////////////////////////////////////////////////////////////// |
| 140 | 140 |
| 141 #define WM_SOCKETNOTIFY (WM_USER + 50) | 141 #define WM_SOCKETNOTIFY (WM_USER + 50) |
| 142 #define WM_DNSNOTIFY (WM_USER + 51) | 142 #define WM_DNSNOTIFY (WM_USER + 51) |
| 143 | 143 |
| 144 struct Win32Socket::DnsLookup { | 144 struct Win32Socket::DnsLookup { |
| 145 HANDLE handle; | 145 HANDLE handle; |
| 146 uint16 port; | 146 uint16_t port; |
| 147 char buffer[MAXGETHOSTSTRUCT]; | 147 char buffer[MAXGETHOSTSTRUCT]; |
| 148 }; | 148 }; |
| 149 | 149 |
| 150 class Win32Socket::EventSink : public Win32Window { | 150 class Win32Socket::EventSink : public Win32Window { |
| 151 public: | 151 public: |
| 152 explicit EventSink(Win32Socket * parent) : parent_(parent) { } | 152 explicit EventSink(Win32Socket * parent) : parent_(parent) { } |
| 153 | 153 |
| 154 void Dispose(); | 154 void Dispose(); |
| 155 | 155 |
| 156 virtual bool OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, | 156 virtual bool OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 } | 505 } |
| 506 if (sink_) { | 506 if (sink_) { |
| 507 sink_->Dispose(); | 507 sink_->Dispose(); |
| 508 sink_ = NULL; | 508 sink_ = NULL; |
| 509 } | 509 } |
| 510 addr_.Clear(); | 510 addr_.Clear(); |
| 511 state_ = CS_CLOSED; | 511 state_ = CS_CLOSED; |
| 512 return err; | 512 return err; |
| 513 } | 513 } |
| 514 | 514 |
| 515 int Win32Socket::EstimateMTU(uint16* mtu) { | 515 int Win32Socket::EstimateMTU(uint16_t* mtu) { |
| 516 SocketAddress addr = GetRemoteAddress(); | 516 SocketAddress addr = GetRemoteAddress(); |
| 517 if (addr.IsAny()) { | 517 if (addr.IsAny()) { |
| 518 error_ = ENOTCONN; | 518 error_ = ENOTCONN; |
| 519 return -1; | 519 return -1; |
| 520 } | 520 } |
| 521 | 521 |
| 522 WinPing ping; | 522 WinPing ping; |
| 523 if (!ping.IsValid()) { | 523 if (!ping.IsValid()) { |
| 524 error_ = EINVAL; // can't think of a better error ID | 524 error_ = EINVAL; // can't think of a better error ID |
| 525 return -1; | 525 return -1; |
| 526 } | 526 } |
| 527 | 527 |
| 528 for (int level = 0; PACKET_MAXIMUMS[level + 1] > 0; ++level) { | 528 for (int level = 0; PACKET_MAXIMUMS[level + 1] > 0; ++level) { |
| 529 int32 size = PACKET_MAXIMUMS[level] - IP_HEADER_SIZE - ICMP_HEADER_SIZE; | 529 int32_t size = PACKET_MAXIMUMS[level] - IP_HEADER_SIZE - ICMP_HEADER_SIZE; |
| 530 WinPing::PingResult result = ping.Ping(addr.ipaddr(), size, | 530 WinPing::PingResult result = ping.Ping(addr.ipaddr(), size, |
| 531 ICMP_PING_TIMEOUT_MILLIS, 1, false); | 531 ICMP_PING_TIMEOUT_MILLIS, 1, false); |
| 532 if (result == WinPing::PING_FAIL) { | 532 if (result == WinPing::PING_FAIL) { |
| 533 error_ = EINVAL; // can't think of a better error ID | 533 error_ = EINVAL; // can't think of a better error ID |
| 534 return -1; | 534 return -1; |
| 535 } | 535 } |
| 536 if (result != WinPing::PING_TOO_LARGE) { | 536 if (result != WinPing::PING_TOO_LARGE) { |
| 537 *mtu = PACKET_MAXIMUMS[level]; | 537 *mtu = PACKET_MAXIMUMS[level]; |
| 538 return 0; | 538 return 0; |
| 539 } | 539 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 // Ignore events if we're already closed. | 620 // Ignore events if we're already closed. |
| 621 if (socket != socket_) | 621 if (socket != socket_) |
| 622 return; | 622 return; |
| 623 | 623 |
| 624 error_ = error; | 624 error_ = error; |
| 625 switch (event) { | 625 switch (event) { |
| 626 case FD_CONNECT: | 626 case FD_CONNECT: |
| 627 if (error != ERROR_SUCCESS) { | 627 if (error != ERROR_SUCCESS) { |
| 628 ReportWSAError("WSAAsync:connect notify", error, addr_); | 628 ReportWSAError("WSAAsync:connect notify", error, addr_); |
| 629 #ifdef _DEBUG | 629 #ifdef _DEBUG |
| 630 int32 duration = TimeSince(connect_time_); | 630 int32_t duration = TimeSince(connect_time_); |
| 631 LOG(LS_INFO) << "WSAAsync:connect error (" << duration | 631 LOG(LS_INFO) << "WSAAsync:connect error (" << duration |
| 632 << " ms), faking close"; | 632 << " ms), faking close"; |
| 633 #endif | 633 #endif |
| 634 state_ = CS_CLOSED; | 634 state_ = CS_CLOSED; |
| 635 // If you get an error connecting, close doesn't really do anything | 635 // If you get an error connecting, close doesn't really do anything |
| 636 // and it certainly doesn't send back any close notification, but | 636 // and it certainly doesn't send back any close notification, but |
| 637 // we really only maintain a few states, so it is easiest to get | 637 // we really only maintain a few states, so it is easiest to get |
| 638 // back into a known state by pretending that a close happened, even | 638 // back into a known state by pretending that a close happened, even |
| 639 // though the connect event never did occur. | 639 // though the connect event never did occur. |
| 640 SignalCloseEvent(this, error); | 640 SignalCloseEvent(this, error); |
| 641 } else { | 641 } else { |
| 642 #ifdef _DEBUG | 642 #ifdef _DEBUG |
| 643 int32 duration = TimeSince(connect_time_); | 643 int32_t duration = TimeSince(connect_time_); |
| 644 LOG(LS_INFO) << "WSAAsync:connect (" << duration << " ms)"; | 644 LOG(LS_INFO) << "WSAAsync:connect (" << duration << " ms)"; |
| 645 #endif | 645 #endif |
| 646 state_ = CS_CONNECTED; | 646 state_ = CS_CONNECTED; |
| 647 SignalConnectEvent(this); | 647 SignalConnectEvent(this); |
| 648 } | 648 } |
| 649 break; | 649 break; |
| 650 | 650 |
| 651 case FD_ACCEPT: | 651 case FD_ACCEPT: |
| 652 case FD_READ: | 652 case FD_READ: |
| 653 if (error != ERROR_SUCCESS) { | 653 if (error != ERROR_SUCCESS) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 672 SignalCloseEvent(this, error); | 672 SignalCloseEvent(this, error); |
| 673 } | 673 } |
| 674 break; | 674 break; |
| 675 } | 675 } |
| 676 } | 676 } |
| 677 | 677 |
| 678 void Win32Socket::OnDnsNotify(HANDLE task, int error) { | 678 void Win32Socket::OnDnsNotify(HANDLE task, int error) { |
| 679 if (!dns_ || dns_->handle != task) | 679 if (!dns_ || dns_->handle != task) |
| 680 return; | 680 return; |
| 681 | 681 |
| 682 uint32 ip = 0; | 682 uint32_t ip = 0; |
| 683 if (error == 0) { | 683 if (error == 0) { |
| 684 hostent* pHost = reinterpret_cast<hostent*>(dns_->buffer); | 684 hostent* pHost = reinterpret_cast<hostent*>(dns_->buffer); |
| 685 uint32 net_ip = *reinterpret_cast<uint32*>(pHost->h_addr_list[0]); | 685 uint32_t net_ip = *reinterpret_cast<uint32_t*>(pHost->h_addr_list[0]); |
| 686 ip = NetworkToHost32(net_ip); | 686 ip = NetworkToHost32(net_ip); |
| 687 } | 687 } |
| 688 | 688 |
| 689 LOG_F(LS_INFO) << "(" << IPAddress(ip).ToSensitiveString() | 689 LOG_F(LS_INFO) << "(" << IPAddress(ip).ToSensitiveString() |
| 690 << ", " << error << ")"; | 690 << ", " << error << ")"; |
| 691 | 691 |
| 692 if (error == 0) { | 692 if (error == 0) { |
| 693 SocketAddress address(ip, dns_->port); | 693 SocketAddress address(ip, dns_->port); |
| 694 error = DoConnect(address); | 694 error = DoConnect(address); |
| 695 } else { | 695 } else { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 | 755 |
| 756 void Win32SocketServer::SetMessageQueue(MessageQueue* queue) { | 756 void Win32SocketServer::SetMessageQueue(MessageQueue* queue) { |
| 757 message_queue_ = queue; | 757 message_queue_ = queue; |
| 758 } | 758 } |
| 759 | 759 |
| 760 bool Win32SocketServer::Wait(int cms, bool process_io) { | 760 bool Win32SocketServer::Wait(int cms, bool process_io) { |
| 761 BOOL b; | 761 BOOL b; |
| 762 if (process_io) { | 762 if (process_io) { |
| 763 // Spin the Win32 message pump at least once, and as long as requested. | 763 // Spin the Win32 message pump at least once, and as long as requested. |
| 764 // This is the Thread::ProcessMessages case. | 764 // This is the Thread::ProcessMessages case. |
| 765 uint32 start = Time(); | 765 uint32_t start = Time(); |
| 766 do { | 766 do { |
| 767 MSG msg; | 767 MSG msg; |
| 768 SetTimer(wnd_.handle(), 0, cms, NULL); | 768 SetTimer(wnd_.handle(), 0, cms, NULL); |
| 769 // Get the next available message. If we have a modeless dialog, give | 769 // Get the next available message. If we have a modeless dialog, give |
| 770 // give the message to IsDialogMessage, which will return true if it | 770 // give the message to IsDialogMessage, which will return true if it |
| 771 // was a message for the dialog that it handled internally. | 771 // was a message for the dialog that it handled internally. |
| 772 // Otherwise, dispatch as usual via Translate/DispatchMessage. | 772 // Otherwise, dispatch as usual via Translate/DispatchMessage. |
| 773 b = GetMessage(&msg, NULL, 0, 0); | 773 b = GetMessage(&msg, NULL, 0, 0); |
| 774 if (b == -1) { | 774 if (b == -1) { |
| 775 LOG_GLE(LS_ERROR) << "GetMessage failed."; | 775 LOG_GLE(LS_ERROR) << "GetMessage failed."; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 bool handled = false; | 845 bool handled = false; |
| 846 if (wm == s_wm_wakeup_id || (wm == WM_TIMER && wp == 1)) { | 846 if (wm == s_wm_wakeup_id || (wm == WM_TIMER && wp == 1)) { |
| 847 ss_->Pump(); | 847 ss_->Pump(); |
| 848 lr = 0; | 848 lr = 0; |
| 849 handled = true; | 849 handled = true; |
| 850 } | 850 } |
| 851 return handled; | 851 return handled; |
| 852 } | 852 } |
| 853 | 853 |
| 854 } // namespace rtc | 854 } // namespace rtc |
| OLD | NEW |