Chromium Code Reviews| 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 #include "webrtc/base/physicalsocketserver.h" | 10 #include "webrtc/base/physicalsocketserver.h" |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 682 | 682 |
| 683 int SocketDispatcher::next_id_ = 0; | 683 int SocketDispatcher::next_id_ = 0; |
| 684 | 684 |
| 685 #elif defined(WEBRTC_POSIX) | 685 #elif defined(WEBRTC_POSIX) |
| 686 | 686 |
| 687 int SocketDispatcher::GetDescriptor() { | 687 int SocketDispatcher::GetDescriptor() { |
| 688 return s_; | 688 return s_; |
| 689 } | 689 } |
| 690 | 690 |
| 691 bool SocketDispatcher::IsDescriptorClosed() { | 691 bool SocketDispatcher::IsDescriptorClosed() { |
| 692 if (udp_) { | |
| 693 // The MSG_PEEK trick doesn't work for UDP, since (at least in some | |
| 694 // circumstances) it requires reading an entire UDP packet, which would be | |
| 695 // bad for performance here. So, just check whether |s_| has been closed, | |
| 696 // which should be sufficient. | |
| 697 return s_ == INVALID_SOCKET; | |
| 698 } | |
| 692 // We don't have a reliable way of distinguishing end-of-stream | 699 // We don't have a reliable way of distinguishing end-of-stream |
| 693 // from readability. So test on each readable call. Is this | 700 // from readability. So test on each readable call. Is this |
| 694 // inefficient? Probably. | 701 // inefficient? Probably. |
| 695 char ch; | 702 char ch; |
| 696 ssize_t res = ::recv(s_, &ch, 1, MSG_PEEK); | 703 ssize_t res = ::recv(s_, &ch, 1, MSG_PEEK); |
| 697 if (res > 0) { | 704 if (res > 0) { |
| 698 // Data available, so not closed. | 705 // Data available, so not closed. |
| 699 return false; | 706 return false; |
| 700 } else if (res == 0) { | 707 } else if (res == 0) { |
| 701 // EOF, so closed. | 708 // EOF, so closed. |
| 702 return true; | 709 return true; |
| 703 } else { // error | 710 } else { // error |
| 704 switch (errno) { | 711 switch (errno) { |
| 705 // Returned if we've already closed s_. | 712 // Returned if we've already closed s_. |
| 706 case EBADF: | 713 case EBADF: |
| 707 // Returned during ungraceful peer shutdown. | 714 // Returned during ungraceful peer shutdown. |
| 708 case ECONNRESET: | 715 case ECONNRESET: |
| 716 // The normal blocking error. | |
| 717 case EWOULDBLOCK: | |
| 709 return true; | 718 return true; |
|
nisse-webrtc
2017/02/09 09:29:54
Return value should be true for EBADF and ECONNRES
Taylor Brandstetter
2017/02/09 10:21:43
Oops, fixed.
| |
| 710 default: | 719 default: |
| 711 // Assume that all other errors are just blocking errors, meaning the | 720 // Assume that all other errors are just blocking errors, meaning the |
| 712 // connection is still good but we just can't read from it right now. | 721 // connection is still good but we just can't read from it right now. |
| 713 // This should only happen when connecting (and at most once), because | 722 // This should only happen when connecting (and at most once), because |
| 714 // in all other cases this function is only called if the file | 723 // in all other cases this function is only called if the file |
| 715 // descriptor is already known to be in the readable state. However, | 724 // descriptor is already known to be in the readable state. However, |
| 716 // it's not necessary a problem if we spuriously interpret a | 725 // it's not necessary a problem if we spuriously interpret a |
| 717 // "connection lost"-type error as a blocking error, because typically | 726 // "connection lost"-type error as a blocking error, because typically |
| 718 // the next recv() will get EOF, so we'll still eventually notice that | 727 // the next recv() will get EOF, so we'll still eventually notice that |
| 719 // the socket is closed. | 728 // the socket is closed. |
| 720 LOG_ERR(LS_WARNING) << "Assuming benign blocking error"; | 729 LOG_ERR(LS_WARNING) << "Assuming benign blocking error"; |
| 721 return false; | 730 return false; |
|
nisse-webrtc
2017/02/09 09:29:54
And I'd suggest returning true here, to close the
Taylor Brandstetter
2017/02/09 10:21:43
Like I mentioned on the other CL, I'm wary about d
nisse-webrtc
2017/02/09 11:37:02
I think it would be good to list explicitly which
| |
| 722 } | 731 } |
| 723 } | 732 } |
| 724 } | 733 } |
| 725 | 734 |
| 726 #endif // WEBRTC_POSIX | 735 #endif // WEBRTC_POSIX |
| 727 | 736 |
| 728 uint32_t SocketDispatcher::GetRequestedEvents() { | 737 uint32_t SocketDispatcher::GetRequestedEvents() { |
| 729 return enabled_events_; | 738 return enabled_events_; |
| 730 } | 739 } |
| 731 | 740 |
| (...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1599 break; | 1608 break; |
| 1600 } | 1609 } |
| 1601 } | 1610 } |
| 1602 | 1611 |
| 1603 // Done | 1612 // Done |
| 1604 return true; | 1613 return true; |
| 1605 } | 1614 } |
| 1606 #endif // WEBRTC_WIN | 1615 #endif // WEBRTC_WIN |
| 1607 | 1616 |
| 1608 } // namespace rtc | 1617 } // namespace rtc |
| OLD | NEW |