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 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 class EventDispatcher : public Dispatcher { | 1085 class EventDispatcher : public Dispatcher { |
1086 public: | 1086 public: |
1087 EventDispatcher(PhysicalSocketServer *ss) : ss_(ss) { | 1087 EventDispatcher(PhysicalSocketServer *ss) : ss_(ss) { |
1088 hev_ = WSACreateEvent(); | 1088 hev_ = WSACreateEvent(); |
1089 if (hev_) { | 1089 if (hev_) { |
1090 ss_->Add(this); | 1090 ss_->Add(this); |
1091 } | 1091 } |
1092 } | 1092 } |
1093 | 1093 |
1094 ~EventDispatcher() { | 1094 ~EventDispatcher() { |
1095 if (hev_ != NULL) { | 1095 if (hev_ != nullptr) { |
1096 ss_->Remove(this); | 1096 ss_->Remove(this); |
1097 WSACloseEvent(hev_); | 1097 WSACloseEvent(hev_); |
1098 hev_ = NULL; | 1098 hev_ = nullptr; |
1099 } | 1099 } |
1100 } | 1100 } |
1101 | 1101 |
1102 virtual void Signal() { | 1102 virtual void Signal() { |
1103 if (hev_ != NULL) | 1103 if (hev_ != nullptr) |
1104 WSASetEvent(hev_); | 1104 WSASetEvent(hev_); |
1105 } | 1105 } |
1106 | 1106 |
1107 virtual uint32_t GetRequestedEvents() { return 0; } | 1107 virtual uint32_t GetRequestedEvents() { return 0; } |
1108 | 1108 |
1109 virtual void OnPreEvent(uint32_t ff) { WSAResetEvent(hev_); } | 1109 virtual void OnPreEvent(uint32_t ff) { WSAResetEvent(hev_); } |
1110 | 1110 |
1111 virtual void OnEvent(uint32_t ff, int err) {} | 1111 virtual void OnEvent(uint32_t ff, int err) {} |
1112 | 1112 |
1113 virtual WSAEVENT GetWSAEvent() { | 1113 virtual WSAEVENT GetWSAEvent() { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1235 if (index < **it) { | 1235 if (index < **it) { |
1236 --**it; | 1236 --**it; |
1237 } | 1237 } |
1238 } | 1238 } |
1239 } | 1239 } |
1240 | 1240 |
1241 #if defined(WEBRTC_POSIX) | 1241 #if defined(WEBRTC_POSIX) |
1242 bool PhysicalSocketServer::Wait(int cmsWait, bool process_io) { | 1242 bool PhysicalSocketServer::Wait(int cmsWait, bool process_io) { |
1243 // Calculate timing information | 1243 // Calculate timing information |
1244 | 1244 |
1245 struct timeval *ptvWait = NULL; | 1245 struct timeval* ptvWait = nullptr; |
1246 struct timeval tvWait; | 1246 struct timeval tvWait; |
1247 struct timeval tvStop; | 1247 struct timeval tvStop; |
1248 if (cmsWait != kForever) { | 1248 if (cmsWait != kForever) { |
1249 // Calculate wait timeval | 1249 // Calculate wait timeval |
1250 tvWait.tv_sec = cmsWait / 1000; | 1250 tvWait.tv_sec = cmsWait / 1000; |
1251 tvWait.tv_usec = (cmsWait % 1000) * 1000; | 1251 tvWait.tv_usec = (cmsWait % 1000) * 1000; |
1252 ptvWait = &tvWait; | 1252 ptvWait = &tvWait; |
1253 | 1253 |
1254 // Calculate when to return in a timeval | 1254 // Calculate when to return in a timeval |
1255 gettimeofday(&tvStop, NULL); | 1255 gettimeofday(&tvStop, nullptr); |
1256 tvStop.tv_sec += tvWait.tv_sec; | 1256 tvStop.tv_sec += tvWait.tv_sec; |
1257 tvStop.tv_usec += tvWait.tv_usec; | 1257 tvStop.tv_usec += tvWait.tv_usec; |
1258 if (tvStop.tv_usec >= 1000000) { | 1258 if (tvStop.tv_usec >= 1000000) { |
1259 tvStop.tv_usec -= 1000000; | 1259 tvStop.tv_usec -= 1000000; |
1260 tvStop.tv_sec += 1; | 1260 tvStop.tv_sec += 1; |
1261 } | 1261 } |
1262 } | 1262 } |
1263 | 1263 |
1264 // Zero all fd_sets. Don't need to do this inside the loop since | 1264 // Zero all fd_sets. Don't need to do this inside the loop since |
1265 // select() zeros the descriptors not signaled | 1265 // select() zeros the descriptors not signaled |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1297 FD_SET(fd, &fdsRead); | 1297 FD_SET(fd, &fdsRead); |
1298 if (ff & (DE_WRITE | DE_CONNECT)) | 1298 if (ff & (DE_WRITE | DE_CONNECT)) |
1299 FD_SET(fd, &fdsWrite); | 1299 FD_SET(fd, &fdsWrite); |
1300 } | 1300 } |
1301 } | 1301 } |
1302 | 1302 |
1303 // Wait then call handlers as appropriate | 1303 // Wait then call handlers as appropriate |
1304 // < 0 means error | 1304 // < 0 means error |
1305 // 0 means timeout | 1305 // 0 means timeout |
1306 // > 0 means count of descriptors ready | 1306 // > 0 means count of descriptors ready |
1307 int n = select(fdmax + 1, &fdsRead, &fdsWrite, NULL, ptvWait); | 1307 int n = select(fdmax + 1, &fdsRead, &fdsWrite, nullptr, ptvWait); |
1308 | 1308 |
1309 // If error, return error. | 1309 // If error, return error. |
1310 if (n < 0) { | 1310 if (n < 0) { |
1311 if (errno != EINTR) { | 1311 if (errno != EINTR) { |
1312 LOG_E(LS_ERROR, EN, errno) << "select"; | 1312 LOG_E(LS_ERROR, EN, errno) << "select"; |
1313 return false; | 1313 return false; |
1314 } | 1314 } |
1315 // Else ignore the error and keep going. If this EINTR was for one of the | 1315 // Else ignore the error and keep going. If this EINTR was for one of the |
1316 // signals managed by this PhysicalSocketServer, the | 1316 // signals managed by this PhysicalSocketServer, the |
1317 // PosixSignalDeliveryDispatcher will be in the signaled state in the next | 1317 // PosixSignalDeliveryDispatcher will be in the signaled state in the next |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1372 } | 1372 } |
1373 } | 1373 } |
1374 } | 1374 } |
1375 | 1375 |
1376 // Recalc the time remaining to wait. Doing it here means it doesn't get | 1376 // Recalc the time remaining to wait. Doing it here means it doesn't get |
1377 // calced twice the first time through the loop | 1377 // calced twice the first time through the loop |
1378 if (ptvWait) { | 1378 if (ptvWait) { |
1379 ptvWait->tv_sec = 0; | 1379 ptvWait->tv_sec = 0; |
1380 ptvWait->tv_usec = 0; | 1380 ptvWait->tv_usec = 0; |
1381 struct timeval tvT; | 1381 struct timeval tvT; |
1382 gettimeofday(&tvT, NULL); | 1382 gettimeofday(&tvT, nullptr); |
1383 if ((tvStop.tv_sec > tvT.tv_sec) | 1383 if ((tvStop.tv_sec > tvT.tv_sec) |
1384 || ((tvStop.tv_sec == tvT.tv_sec) | 1384 || ((tvStop.tv_sec == tvT.tv_sec) |
1385 && (tvStop.tv_usec > tvT.tv_usec))) { | 1385 && (tvStop.tv_usec > tvT.tv_usec))) { |
1386 ptvWait->tv_sec = tvStop.tv_sec - tvT.tv_sec; | 1386 ptvWait->tv_sec = tvStop.tv_sec - tvT.tv_sec; |
1387 ptvWait->tv_usec = tvStop.tv_usec - tvT.tv_usec; | 1387 ptvWait->tv_usec = tvStop.tv_usec - tvT.tv_usec; |
1388 if (ptvWait->tv_usec < 0) { | 1388 if (ptvWait->tv_usec < 0) { |
1389 RTC_DCHECK(ptvWait->tv_sec > 0); | 1389 RTC_DCHECK(ptvWait->tv_sec > 0); |
1390 ptvWait->tv_usec += 1000000; | 1390 ptvWait->tv_usec += 1000000; |
1391 ptvWait->tv_sec -= 1; | 1391 ptvWait->tv_sec -= 1; |
1392 } | 1392 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1440 } | 1440 } |
1441 act.sa_handler = handler; | 1441 act.sa_handler = handler; |
1442 #if !defined(__native_client__) | 1442 #if !defined(__native_client__) |
1443 // Use SA_RESTART so that our syscalls don't get EINTR, since we don't need it | 1443 // Use SA_RESTART so that our syscalls don't get EINTR, since we don't need it |
1444 // and it's a nuisance. Though some syscalls still return EINTR and there's no | 1444 // and it's a nuisance. Though some syscalls still return EINTR and there's no |
1445 // real standard for which ones. :( | 1445 // real standard for which ones. :( |
1446 act.sa_flags = SA_RESTART; | 1446 act.sa_flags = SA_RESTART; |
1447 #else | 1447 #else |
1448 act.sa_flags = 0; | 1448 act.sa_flags = 0; |
1449 #endif | 1449 #endif |
1450 if (sigaction(signum, &act, NULL) != 0) { | 1450 if (sigaction(signum, &act, nullptr) != 0) { |
1451 LOG_ERR(LS_ERROR) << "Couldn't set sigaction"; | 1451 LOG_ERR(LS_ERROR) << "Couldn't set sigaction"; |
1452 return false; | 1452 return false; |
1453 } | 1453 } |
1454 return true; | 1454 return true; |
1455 } | 1455 } |
1456 #endif // WEBRTC_POSIX | 1456 #endif // WEBRTC_POSIX |
1457 | 1457 |
1458 #if defined(WEBRTC_WIN) | 1458 #if defined(WEBRTC_WIN) |
1459 bool PhysicalSocketServer::Wait(int cmsWait, bool process_io) { | 1459 bool PhysicalSocketServer::Wait(int cmsWait, bool process_io) { |
1460 int64_t cmsTotal = cmsWait; | 1460 int64_t cmsTotal = cmsWait; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1611 break; | 1611 break; |
1612 } | 1612 } |
1613 } | 1613 } |
1614 | 1614 |
1615 // Done | 1615 // Done |
1616 return true; | 1616 return true; |
1617 } | 1617 } |
1618 #endif // WEBRTC_WIN | 1618 #endif // WEBRTC_WIN |
1619 | 1619 |
1620 } // namespace rtc | 1620 } // namespace rtc |
OLD | NEW |