Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: webrtc/base/physicalsocketserver.cc

Issue 2620303003: Replace ASSERT by RTC_DCHECK in all non-test code. (Closed)
Patch Set: Address final nits. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/base/opensslidentity.cc ('k') | webrtc/base/proxydetect.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 // don't want. By specifying this flag, we'll just get the error EPIPE 305 // don't want. By specifying this flag, we'll just get the error EPIPE
306 // instead and can handle the error gracefully. 306 // instead and can handle the error gracefully.
307 MSG_NOSIGNAL 307 MSG_NOSIGNAL
308 #else 308 #else
309 0 309 0
310 #endif 310 #endif
311 ); 311 );
312 UpdateLastError(); 312 UpdateLastError();
313 MaybeRemapSendError(); 313 MaybeRemapSendError();
314 // We have seen minidumps where this may be false. 314 // We have seen minidumps where this may be false.
315 ASSERT(sent <= static_cast<int>(cb)); 315 RTC_DCHECK(sent <= static_cast<int>(cb));
316 if ((sent > 0 && sent < static_cast<int>(cb)) || 316 if ((sent > 0 && sent < static_cast<int>(cb)) ||
317 (sent < 0 && IsBlockingError(GetError()))) { 317 (sent < 0 && IsBlockingError(GetError()))) {
318 enabled_events_ |= DE_WRITE; 318 enabled_events_ |= DE_WRITE;
319 } 319 }
320 return sent; 320 return sent;
321 } 321 }
322 322
323 int PhysicalSocket::SendTo(const void* buffer, 323 int PhysicalSocket::SendTo(const void* buffer,
324 size_t length, 324 size_t length,
325 const SocketAddress& addr) { 325 const SocketAddress& addr) {
326 sockaddr_storage saddr; 326 sockaddr_storage saddr;
327 size_t len = addr.ToSockAddrStorage(&saddr); 327 size_t len = addr.ToSockAddrStorage(&saddr);
328 int sent = DoSendTo( 328 int sent = DoSendTo(
329 s_, static_cast<const char *>(buffer), static_cast<int>(length), 329 s_, static_cast<const char *>(buffer), static_cast<int>(length),
330 #if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID) 330 #if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID)
331 // Suppress SIGPIPE. See above for explanation. 331 // Suppress SIGPIPE. See above for explanation.
332 MSG_NOSIGNAL, 332 MSG_NOSIGNAL,
333 #else 333 #else
334 0, 334 0,
335 #endif 335 #endif
336 reinterpret_cast<sockaddr*>(&saddr), static_cast<int>(len)); 336 reinterpret_cast<sockaddr*>(&saddr), static_cast<int>(len));
337 UpdateLastError(); 337 UpdateLastError();
338 MaybeRemapSendError(); 338 MaybeRemapSendError();
339 // We have seen minidumps where this may be false. 339 // We have seen minidumps where this may be false.
340 ASSERT(sent <= static_cast<int>(length)); 340 RTC_DCHECK(sent <= static_cast<int>(length));
341 if ((sent > 0 && sent < static_cast<int>(length)) || 341 if ((sent > 0 && sent < static_cast<int>(length)) ||
342 (sent < 0 && IsBlockingError(GetError()))) { 342 (sent < 0 && IsBlockingError(GetError()))) {
343 enabled_events_ |= DE_WRITE; 343 enabled_events_ |= DE_WRITE;
344 } 344 }
345 return sent; 345 return sent;
346 } 346 }
347 347
348 int PhysicalSocket::Recv(void* buffer, size_t length, int64_t* timestamp) { 348 int PhysicalSocket::Recv(void* buffer, size_t length, int64_t* timestamp) {
349 int received = ::recv(s_, static_cast<char*>(buffer), 349 int received = ::recv(s_, static_cast<char*>(buffer),
350 static_cast<int>(length), 0); 350 static_cast<int>(length), 0);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 #elif defined(WEBRTC_LINUX) 492 #elif defined(WEBRTC_LINUX)
493 // Gets the path MTU. 493 // Gets the path MTU.
494 int value; 494 int value;
495 socklen_t vlen = sizeof(value); 495 socklen_t vlen = sizeof(value);
496 int err = getsockopt(s_, IPPROTO_IP, IP_MTU, &value, &vlen); 496 int err = getsockopt(s_, IPPROTO_IP, IP_MTU, &value, &vlen);
497 if (err < 0) { 497 if (err < 0) {
498 UpdateLastError(); 498 UpdateLastError();
499 return err; 499 return err;
500 } 500 }
501 501
502 ASSERT((0 <= value) && (value <= 65536)); 502 RTC_DCHECK((0 <= value) && (value <= 65536));
503 *mtu = value; 503 *mtu = value;
504 return 0; 504 return 0;
505 #elif defined(__native_client__) 505 #elif defined(__native_client__)
506 // Most socket operations, including this, will fail in NaCl's sandbox. 506 // Most socket operations, including this, will fail in NaCl's sandbox.
507 error_ = EACCES; 507 error_ = EACCES;
508 return -1; 508 return -1;
509 #endif 509 #endif
510 } 510 }
511 511
512 SOCKET PhysicalSocket::DoAccept(SOCKET socket, 512 SOCKET PhysicalSocket::DoAccept(SOCKET socket,
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 : PhysicalSocket(ss, s) 618 : PhysicalSocket(ss, s)
619 #endif 619 #endif
620 { 620 {
621 } 621 }
622 622
623 SocketDispatcher::~SocketDispatcher() { 623 SocketDispatcher::~SocketDispatcher() {
624 Close(); 624 Close();
625 } 625 }
626 626
627 bool SocketDispatcher::Initialize() { 627 bool SocketDispatcher::Initialize() {
628 ASSERT(s_ != INVALID_SOCKET); 628 RTC_DCHECK(s_ != INVALID_SOCKET);
629 // Must be a non-blocking 629 // Must be a non-blocking
630 #if defined(WEBRTC_WIN) 630 #if defined(WEBRTC_WIN)
631 u_long argp = 1; 631 u_long argp = 1;
632 ioctlsocket(s_, FIONBIO, &argp); 632 ioctlsocket(s_, FIONBIO, &argp);
633 #elif defined(WEBRTC_POSIX) 633 #elif defined(WEBRTC_POSIX)
634 fcntl(s_, F_SETFL, fcntl(s_, F_GETFL, 0) | O_NONBLOCK); 634 fcntl(s_, F_SETFL, fcntl(s_, F_GETFL, 0) | O_NONBLOCK);
635 #endif 635 #endif
636 ss_->Add(this); 636 ss_->Add(this);
637 return true; 637 return true;
638 } 638 }
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 // There is just a single global instance. (Signal handlers do not get any 883 // There is just a single global instance. (Signal handlers do not get any
884 // sort of user-defined void * parameter, so they can't access anything that 884 // sort of user-defined void * parameter, so they can't access anything that
885 // isn't global.) 885 // isn't global.)
886 static PosixSignalHandler* Instance() { 886 static PosixSignalHandler* Instance() {
887 RTC_DEFINE_STATIC_LOCAL(PosixSignalHandler, instance, ()); 887 RTC_DEFINE_STATIC_LOCAL(PosixSignalHandler, instance, ());
888 return &instance; 888 return &instance;
889 } 889 }
890 890
891 // Returns true if the given signal number is set. 891 // Returns true if the given signal number is set.
892 bool IsSignalSet(int signum) const { 892 bool IsSignalSet(int signum) const {
893 ASSERT(signum < static_cast<int>(arraysize(received_signal_))); 893 RTC_DCHECK(signum < static_cast<int>(arraysize(received_signal_)));
894 if (signum < static_cast<int>(arraysize(received_signal_))) { 894 if (signum < static_cast<int>(arraysize(received_signal_))) {
895 return received_signal_[signum]; 895 return received_signal_[signum];
896 } else { 896 } else {
897 return false; 897 return false;
898 } 898 }
899 } 899 }
900 900
901 // Clears the given signal number. 901 // Clears the given signal number.
902 void ClearSignal(int signum) { 902 void ClearSignal(int signum) {
903 ASSERT(signum < static_cast<int>(arraysize(received_signal_))); 903 RTC_DCHECK(signum < static_cast<int>(arraysize(received_signal_)));
904 if (signum < static_cast<int>(arraysize(received_signal_))) { 904 if (signum < static_cast<int>(arraysize(received_signal_))) {
905 received_signal_[signum] = false; 905 received_signal_[signum] = false;
906 } 906 }
907 } 907 }
908 908
909 // Returns the file descriptor to monitor for signal events. 909 // Returns the file descriptor to monitor for signal events.
910 int GetDescriptor() const { 910 int GetDescriptor() const {
911 return afd_[0]; 911 return afd_[0];
912 } 912 }
913 913
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 } 1138 }
1139 1139
1140 PhysicalSocketServer::~PhysicalSocketServer() { 1140 PhysicalSocketServer::~PhysicalSocketServer() {
1141 #if defined(WEBRTC_WIN) 1141 #if defined(WEBRTC_WIN)
1142 WSACloseEvent(socket_ev_); 1142 WSACloseEvent(socket_ev_);
1143 #endif 1143 #endif
1144 #if defined(WEBRTC_POSIX) 1144 #if defined(WEBRTC_POSIX)
1145 signal_dispatcher_.reset(); 1145 signal_dispatcher_.reset();
1146 #endif 1146 #endif
1147 delete signal_wakeup_; 1147 delete signal_wakeup_;
1148 ASSERT(dispatchers_.empty()); 1148 RTC_DCHECK(dispatchers_.empty());
1149 } 1149 }
1150 1150
1151 void PhysicalSocketServer::WakeUp() { 1151 void PhysicalSocketServer::WakeUp() {
1152 signal_wakeup_->Signal(); 1152 signal_wakeup_->Signal();
1153 } 1153 }
1154 1154
1155 Socket* PhysicalSocketServer::CreateSocket(int type) { 1155 Socket* PhysicalSocketServer::CreateSocket(int type) {
1156 return CreateSocket(AF_INET, type); 1156 return CreateSocket(AF_INET, type);
1157 } 1157 }
1158 1158
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 1264
1265 fWait_ = true; 1265 fWait_ = true;
1266 1266
1267 while (fWait_) { 1267 while (fWait_) {
1268 int fdmax = -1; 1268 int fdmax = -1;
1269 { 1269 {
1270 CritScope cr(&crit_); 1270 CritScope cr(&crit_);
1271 for (size_t i = 0; i < dispatchers_.size(); ++i) { 1271 for (size_t i = 0; i < dispatchers_.size(); ++i) {
1272 // Query dispatchers for read and write wait state 1272 // Query dispatchers for read and write wait state
1273 Dispatcher *pdispatcher = dispatchers_[i]; 1273 Dispatcher *pdispatcher = dispatchers_[i];
1274 ASSERT(pdispatcher); 1274 RTC_DCHECK(pdispatcher);
1275 if (!process_io && (pdispatcher != signal_wakeup_)) 1275 if (!process_io && (pdispatcher != signal_wakeup_))
1276 continue; 1276 continue;
1277 int fd = pdispatcher->GetDescriptor(); 1277 int fd = pdispatcher->GetDescriptor();
1278 if (fd > fdmax) 1278 if (fd > fdmax)
1279 fdmax = fd; 1279 fdmax = fd;
1280 1280
1281 uint32_t ff = pdispatcher->GetRequestedEvents(); 1281 uint32_t ff = pdispatcher->GetRequestedEvents();
1282 if (ff & (DE_READ | DE_ACCEPT)) 1282 if (ff & (DE_READ | DE_ACCEPT))
1283 FD_SET(fd, &fdsRead); 1283 FD_SET(fd, &fdsRead);
1284 if (ff & (DE_WRITE | DE_CONNECT)) 1284 if (ff & (DE_WRITE | DE_CONNECT))
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 ptvWait->tv_sec = 0; 1365 ptvWait->tv_sec = 0;
1366 ptvWait->tv_usec = 0; 1366 ptvWait->tv_usec = 0;
1367 struct timeval tvT; 1367 struct timeval tvT;
1368 gettimeofday(&tvT, NULL); 1368 gettimeofday(&tvT, NULL);
1369 if ((tvStop.tv_sec > tvT.tv_sec) 1369 if ((tvStop.tv_sec > tvT.tv_sec)
1370 || ((tvStop.tv_sec == tvT.tv_sec) 1370 || ((tvStop.tv_sec == tvT.tv_sec)
1371 && (tvStop.tv_usec > tvT.tv_usec))) { 1371 && (tvStop.tv_usec > tvT.tv_usec))) {
1372 ptvWait->tv_sec = tvStop.tv_sec - tvT.tv_sec; 1372 ptvWait->tv_sec = tvStop.tv_sec - tvT.tv_sec;
1373 ptvWait->tv_usec = tvStop.tv_usec - tvT.tv_usec; 1373 ptvWait->tv_usec = tvStop.tv_usec - tvT.tv_usec;
1374 if (ptvWait->tv_usec < 0) { 1374 if (ptvWait->tv_usec < 0) {
1375 ASSERT(ptvWait->tv_sec > 0); 1375 RTC_DCHECK(ptvWait->tv_sec > 0);
1376 ptvWait->tv_usec += 1000000; 1376 ptvWait->tv_usec += 1000000;
1377 ptvWait->tv_sec -= 1; 1377 ptvWait->tv_sec -= 1;
1378 } 1378 }
1379 } 1379 }
1380 } 1380 }
1381 } 1381 }
1382 1382
1383 return true; 1383 return true;
1384 } 1384 }
1385 1385
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 // We just signalled close, don't poll this socket 1469 // We just signalled close, don't poll this socket
1470 } else if (s != INVALID_SOCKET) { 1470 } else if (s != INVALID_SOCKET) {
1471 WSAEventSelect(s, 1471 WSAEventSelect(s,
1472 events[0], 1472 events[0],
1473 FlagsToEvents(disp->GetRequestedEvents())); 1473 FlagsToEvents(disp->GetRequestedEvents()));
1474 } else { 1474 } else {
1475 events.push_back(disp->GetWSAEvent()); 1475 events.push_back(disp->GetWSAEvent());
1476 event_owners.push_back(disp); 1476 event_owners.push_back(disp);
1477 } 1477 }
1478 } 1478 }
1479 ASSERT(iterators_.back() == &i); 1479 RTC_DCHECK(iterators_.back() == &i);
1480 iterators_.pop_back(); 1480 iterators_.pop_back();
1481 } 1481 }
1482 1482
1483 // Which is shorter, the delay wait or the asked wait? 1483 // Which is shorter, the delay wait or the asked wait?
1484 1484
1485 int64_t cmsNext; 1485 int64_t cmsNext;
1486 if (cmsWait == kForever) { 1486 if (cmsWait == kForever) {
1487 cmsNext = cmsWait; 1487 cmsNext = cmsWait;
1488 } else { 1488 } else {
1489 cmsNext = std::max<int64_t>(0, cmsTotal - cmsElapsed); 1489 cmsNext = std::max<int64_t>(0, cmsTotal - cmsElapsed);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1572 if (wsaEvents.lNetworkEvents & FD_CLOSE) { 1572 if (wsaEvents.lNetworkEvents & FD_CLOSE) {
1573 ff |= DE_CLOSE; 1573 ff |= DE_CLOSE;
1574 errcode = wsaEvents.iErrorCode[FD_CLOSE_BIT]; 1574 errcode = wsaEvents.iErrorCode[FD_CLOSE_BIT];
1575 } 1575 }
1576 if (ff != 0) { 1576 if (ff != 0) {
1577 disp->OnPreEvent(ff); 1577 disp->OnPreEvent(ff);
1578 disp->OnEvent(ff, errcode); 1578 disp->OnEvent(ff, errcode);
1579 } 1579 }
1580 } 1580 }
1581 } 1581 }
1582 ASSERT(iterators_.back() == &end); 1582 RTC_DCHECK(iterators_.back() == &end);
1583 iterators_.pop_back(); 1583 iterators_.pop_back();
1584 ASSERT(iterators_.back() == &i); 1584 RTC_DCHECK(iterators_.back() == &i);
1585 iterators_.pop_back(); 1585 iterators_.pop_back();
1586 } 1586 }
1587 1587
1588 // Reset the network event until new activity occurs 1588 // Reset the network event until new activity occurs
1589 WSAResetEvent(socket_ev_); 1589 WSAResetEvent(socket_ev_);
1590 } 1590 }
1591 1591
1592 // Break? 1592 // Break?
1593 if (!fWait_) 1593 if (!fWait_)
1594 break; 1594 break;
1595 cmsElapsed = TimeSince(msStart); 1595 cmsElapsed = TimeSince(msStart);
1596 if ((cmsWait != kForever) && (cmsElapsed >= cmsWait)) { 1596 if ((cmsWait != kForever) && (cmsElapsed >= cmsWait)) {
1597 break; 1597 break;
1598 } 1598 }
1599 } 1599 }
1600 1600
1601 // Done 1601 // Done
1602 return true; 1602 return true;
1603 } 1603 }
1604 #endif // WEBRTC_WIN 1604 #endif // WEBRTC_WIN
1605 1605
1606 } // namespace rtc 1606 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/opensslidentity.cc ('k') | webrtc/base/proxydetect.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698