| 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: |
| 709 return true; | 716 return true; |
| 717 // The normal blocking error; don't log anything. |
| 718 case EWOULDBLOCK: |
| 719 // Interrupted system call. |
| 720 case EINTR: |
| 721 return false; |
| 710 default: | 722 default: |
| 711 // Assume that all other errors are just blocking errors, meaning the | 723 // 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. | 724 // 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 | 725 // This should only happen when connecting (and at most once), because |
| 714 // in all other cases this function is only called if the file | 726 // in all other cases this function is only called if the file |
| 715 // descriptor is already known to be in the readable state. However, | 727 // descriptor is already known to be in the readable state. However, |
| 716 // it's not necessary a problem if we spuriously interpret a | 728 // it's not necessary a problem if we spuriously interpret a |
| 717 // "connection lost"-type error as a blocking error, because typically | 729 // "connection lost"-type error as a blocking error, because typically |
| 718 // the next recv() will get EOF, so we'll still eventually notice that | 730 // the next recv() will get EOF, so we'll still eventually notice that |
| 719 // the socket is closed. | 731 // the socket is closed. |
| (...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1599 break; | 1611 break; |
| 1600 } | 1612 } |
| 1601 } | 1613 } |
| 1602 | 1614 |
| 1603 // Done | 1615 // Done |
| 1604 return true; | 1616 return true; |
| 1605 } | 1617 } |
| 1606 #endif // WEBRTC_WIN | 1618 #endif // WEBRTC_WIN |
| 1607 | 1619 |
| 1608 } // namespace rtc | 1620 } // namespace rtc |
| OLD | NEW |