| 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 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1044 } | 1044 } |
| 1045 | 1045 |
| 1046 private: | 1046 private: |
| 1047 typedef std::map<int, void (*)(int)> HandlerMap; | 1047 typedef std::map<int, void (*)(int)> HandlerMap; |
| 1048 | 1048 |
| 1049 HandlerMap handlers_; | 1049 HandlerMap handlers_; |
| 1050 // Our owner. | 1050 // Our owner. |
| 1051 PhysicalSocketServer *owner_; | 1051 PhysicalSocketServer *owner_; |
| 1052 }; | 1052 }; |
| 1053 | 1053 |
| 1054 class FileDispatcher: public Dispatcher, public AsyncFile { | |
| 1055 public: | |
| 1056 FileDispatcher(int fd, PhysicalSocketServer *ss) : ss_(ss), fd_(fd) { | |
| 1057 set_readable(true); | |
| 1058 | |
| 1059 ss_->Add(this); | |
| 1060 | |
| 1061 fcntl(fd_, F_SETFL, fcntl(fd_, F_GETFL, 0) | O_NONBLOCK); | |
| 1062 } | |
| 1063 | |
| 1064 ~FileDispatcher() override { | |
| 1065 ss_->Remove(this); | |
| 1066 } | |
| 1067 | |
| 1068 SocketServer* socketserver() { return ss_; } | |
| 1069 | |
| 1070 int GetDescriptor() override { return fd_; } | |
| 1071 | |
| 1072 bool IsDescriptorClosed() override { return false; } | |
| 1073 | |
| 1074 uint32_t GetRequestedEvents() override { return flags_; } | |
| 1075 | |
| 1076 void OnPreEvent(uint32_t ff) override {} | |
| 1077 | |
| 1078 void OnEvent(uint32_t ff, int err) override { | |
| 1079 if ((ff & DE_READ) != 0) | |
| 1080 SignalReadEvent(this); | |
| 1081 if ((ff & DE_WRITE) != 0) | |
| 1082 SignalWriteEvent(this); | |
| 1083 if ((ff & DE_CLOSE) != 0) | |
| 1084 SignalCloseEvent(this, err); | |
| 1085 } | |
| 1086 | |
| 1087 bool readable() override { return (flags_ & DE_READ) != 0; } | |
| 1088 | |
| 1089 void set_readable(bool value) override { | |
| 1090 flags_ = value ? (flags_ | DE_READ) : (flags_ & ~DE_READ); | |
| 1091 } | |
| 1092 | |
| 1093 bool writable() override { return (flags_ & DE_WRITE) != 0; } | |
| 1094 | |
| 1095 void set_writable(bool value) override { | |
| 1096 flags_ = value ? (flags_ | DE_WRITE) : (flags_ & ~DE_WRITE); | |
| 1097 } | |
| 1098 | |
| 1099 private: | |
| 1100 PhysicalSocketServer* ss_; | |
| 1101 int fd_; | |
| 1102 int flags_; | |
| 1103 }; | |
| 1104 | |
| 1105 AsyncFile* PhysicalSocketServer::CreateFile(int fd) { | |
| 1106 return new FileDispatcher(fd, this); | |
| 1107 } | |
| 1108 | |
| 1109 #endif // WEBRTC_POSIX | 1054 #endif // WEBRTC_POSIX |
| 1110 | 1055 |
| 1111 #if defined(WEBRTC_WIN) | 1056 #if defined(WEBRTC_WIN) |
| 1112 static uint32_t FlagsToEvents(uint32_t events) { | 1057 static uint32_t FlagsToEvents(uint32_t events) { |
| 1113 uint32_t ffFD = FD_CLOSE; | 1058 uint32_t ffFD = FD_CLOSE; |
| 1114 if (events & DE_READ) | 1059 if (events & DE_READ) |
| 1115 ffFD |= FD_READ; | 1060 ffFD |= FD_READ; |
| 1116 if (events & DE_WRITE) | 1061 if (events & DE_WRITE) |
| 1117 ffFD |= FD_WRITE; | 1062 ffFD |= FD_WRITE; |
| 1118 if (events & DE_CONNECT) | 1063 if (events & DE_CONNECT) |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1651 break; | 1596 break; |
| 1652 } | 1597 } |
| 1653 } | 1598 } |
| 1654 | 1599 |
| 1655 // Done | 1600 // Done |
| 1656 return true; | 1601 return true; |
| 1657 } | 1602 } |
| 1658 #endif // WEBRTC_WIN | 1603 #endif // WEBRTC_WIN |
| 1659 | 1604 |
| 1660 } // namespace rtc | 1605 } // namespace rtc |
| OLD | NEW |