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" |
| 11 | 11 |
| 12 #if defined(_MSC_VER) && _MSC_VER < 1300 | 12 #if defined(_MSC_VER) && _MSC_VER < 1300 |
| 13 #pragma warning(disable:4786) | 13 #pragma warning(disable:4786) |
| 14 #endif | 14 #endif |
| 15 | 15 |
| 16 #include <assert.h> | 16 #include <assert.h> |
| 17 | 17 |
| 18 #ifdef MEMORY_SANITIZER | 18 #ifdef MEMORY_SANITIZER |
| 19 #include <sanitizer/msan_interface.h> | 19 #include <sanitizer/msan_interface.h> |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 #if defined(WEBRTC_POSIX) | 22 #if defined(WEBRTC_POSIX) |
| 23 #include <string.h> | 23 #include <string.h> |
| 24 #include <errno.h> | 24 #include <errno.h> |
| 25 #include <fcntl.h> | 25 #include <fcntl.h> |
| 26 #include <sys/ioctl.h> | |
| 26 #include <sys/time.h> | 27 #include <sys/time.h> |
| 27 #include <sys/select.h> | 28 #include <sys/select.h> |
| 28 #include <unistd.h> | 29 #include <unistd.h> |
| 29 #include <signal.h> | 30 #include <signal.h> |
| 30 #endif | 31 #endif |
| 31 | 32 |
| 32 #if defined(WEBRTC_WIN) | 33 #if defined(WEBRTC_WIN) |
| 33 #define WIN32_LEAN_AND_MEAN | 34 #define WIN32_LEAN_AND_MEAN |
| 34 #include <windows.h> | 35 #include <windows.h> |
| 35 #include <winsock2.h> | 36 #include <winsock2.h> |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 48 #include "webrtc/base/networkmonitor.h" | 49 #include "webrtc/base/networkmonitor.h" |
| 49 #include "webrtc/base/nullsocketserver.h" | 50 #include "webrtc/base/nullsocketserver.h" |
| 50 #include "webrtc/base/timeutils.h" | 51 #include "webrtc/base/timeutils.h" |
| 51 #include "webrtc/base/winping.h" | 52 #include "webrtc/base/winping.h" |
| 52 #include "webrtc/base/win32socketinit.h" | 53 #include "webrtc/base/win32socketinit.h" |
| 53 | 54 |
| 54 #if defined(WEBRTC_POSIX) | 55 #if defined(WEBRTC_POSIX) |
| 55 #include <netinet/tcp.h> // for TCP_NODELAY | 56 #include <netinet/tcp.h> // for TCP_NODELAY |
| 56 #define IP_MTU 14 // Until this is integrated from linux/in.h to netinet/in.h | 57 #define IP_MTU 14 // Until this is integrated from linux/in.h to netinet/in.h |
| 57 typedef void* SockOptArg; | 58 typedef void* SockOptArg; |
| 59 | |
| 58 #endif // WEBRTC_POSIX | 60 #endif // WEBRTC_POSIX |
| 59 | 61 |
| 62 #if defined(WEBRTC_POSIX) && !defined(WEBRTC_MAC) | |
| 63 int64_t GetSocketRecvTimestamp(int socket) { | |
| 64 struct timeval tv_ioctl; | |
| 65 int ret = ioctl(socket, SIOCGSTAMP, &tv_ioctl); | |
|
juberti2
2016/05/11 05:03:34
Do you need to set a socket option for this to wor
stefan-webrtc
2016/05/11 08:41:14
No. There are two ways of getting the timestamp fr
| |
| 66 if (ret != 0) | |
| 67 return -1; | |
| 68 int64_t timestamp = | |
| 69 rtc::kNumMicrosecsPerSec * static_cast<int64_t>(tv_ioctl.tv_sec) + | |
| 70 static_cast<int64_t>(tv_ioctl.tv_usec); | |
| 71 return timestamp; | |
| 72 } | |
| 73 | |
| 74 #else | |
| 75 | |
| 76 int64_t GetSocketRecvTimestamp(int socket) { | |
| 77 return -1; | |
| 78 } | |
| 79 #endif | |
| 80 | |
| 60 #if defined(WEBRTC_WIN) | 81 #if defined(WEBRTC_WIN) |
| 61 typedef char* SockOptArg; | 82 typedef char* SockOptArg; |
| 62 #endif | 83 #endif |
| 63 | 84 |
| 64 namespace rtc { | 85 namespace rtc { |
| 65 | 86 |
| 66 std::unique_ptr<SocketServer> SocketServer::CreateDefault() { | 87 std::unique_ptr<SocketServer> SocketServer::CreateDefault() { |
| 67 #if defined(__native_client__) | 88 #if defined(__native_client__) |
| 68 return std::unique_ptr<SocketServer>(new rtc::NullSocketServer); | 89 return std::unique_ptr<SocketServer>(new rtc::NullSocketServer); |
| 69 #else | 90 #else |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 MaybeRemapSendError(); | 338 MaybeRemapSendError(); |
| 318 // We have seen minidumps where this may be false. | 339 // We have seen minidumps where this may be false. |
| 319 ASSERT(sent <= static_cast<int>(length)); | 340 ASSERT(sent <= static_cast<int>(length)); |
| 320 if ((sent > 0 && sent < static_cast<int>(length)) || | 341 if ((sent > 0 && sent < static_cast<int>(length)) || |
| 321 (sent < 0 && IsBlockingError(GetError()))) { | 342 (sent < 0 && IsBlockingError(GetError()))) { |
| 322 enabled_events_ |= DE_WRITE; | 343 enabled_events_ |= DE_WRITE; |
| 323 } | 344 } |
| 324 return sent; | 345 return sent; |
| 325 } | 346 } |
| 326 | 347 |
| 327 int PhysicalSocket::Recv(void* buffer, size_t length) { | 348 int PhysicalSocket::Recv(void* buffer, size_t length, int64_t* timestamp) { |
| 328 int received = ::recv(s_, static_cast<char*>(buffer), | 349 int received = ::recv(s_, static_cast<char*>(buffer), |
| 329 static_cast<int>(length), 0); | 350 static_cast<int>(length), 0); |
| 330 if ((received == 0) && (length != 0)) { | 351 if ((received == 0) && (length != 0)) { |
| 331 // Note: on graceful shutdown, recv can return 0. In this case, we | 352 // Note: on graceful shutdown, recv can return 0. In this case, we |
| 332 // pretend it is blocking, and then signal close, so that simplifying | 353 // pretend it is blocking, and then signal close, so that simplifying |
| 333 // assumptions can be made about Recv. | 354 // assumptions can be made about Recv. |
| 334 LOG(LS_WARNING) << "EOF from socket; deferring close event"; | 355 LOG(LS_WARNING) << "EOF from socket; deferring close event"; |
| 335 // Must turn this back on so that the select() loop will notice the close | 356 // Must turn this back on so that the select() loop will notice the close |
| 336 // event. | 357 // event. |
| 337 enabled_events_ |= DE_READ; | 358 enabled_events_ |= DE_READ; |
| 338 SetError(EWOULDBLOCK); | 359 SetError(EWOULDBLOCK); |
| 339 return SOCKET_ERROR; | 360 return SOCKET_ERROR; |
| 340 } | 361 } |
| 362 *timestamp = GetSocketRecvTimestamp(s_); | |
|
juberti2
2016/05/11 05:03:34
Allow NULL to be passed so that clients who don't
stefan-webrtc
2016/05/11 08:41:14
Done.
| |
| 341 UpdateLastError(); | 363 UpdateLastError(); |
| 342 int error = GetError(); | 364 int error = GetError(); |
| 343 bool success = (received >= 0) || IsBlockingError(error); | 365 bool success = (received >= 0) || IsBlockingError(error); |
| 344 if (udp_ || success) { | 366 if (udp_ || success) { |
| 345 enabled_events_ |= DE_READ; | 367 enabled_events_ |= DE_READ; |
| 346 } | 368 } |
| 347 if (!success) { | 369 if (!success) { |
| 348 LOG_F(LS_VERBOSE) << "Error = " << error; | 370 LOG_F(LS_VERBOSE) << "Error = " << error; |
| 349 } | 371 } |
| 350 return received; | 372 return received; |
| 351 } | 373 } |
| 352 | 374 |
| 353 int PhysicalSocket::RecvFrom(void* buffer, | 375 int PhysicalSocket::RecvFrom(void* buffer, |
| 354 size_t length, | 376 size_t length, |
| 355 SocketAddress* out_addr) { | 377 SocketAddress* out_addr, |
| 378 int64_t* timestamp) { | |
| 356 sockaddr_storage addr_storage; | 379 sockaddr_storage addr_storage; |
| 357 socklen_t addr_len = sizeof(addr_storage); | 380 socklen_t addr_len = sizeof(addr_storage); |
| 358 sockaddr* addr = reinterpret_cast<sockaddr*>(&addr_storage); | 381 sockaddr* addr = reinterpret_cast<sockaddr*>(&addr_storage); |
| 359 int received = ::recvfrom(s_, static_cast<char*>(buffer), | 382 int received = ::recvfrom(s_, static_cast<char*>(buffer), |
| 360 static_cast<int>(length), 0, addr, &addr_len); | 383 static_cast<int>(length), 0, addr, &addr_len); |
| 384 *timestamp = GetSocketRecvTimestamp(s_); | |
| 361 UpdateLastError(); | 385 UpdateLastError(); |
| 362 if ((received >= 0) && (out_addr != nullptr)) | 386 if ((received >= 0) && (out_addr != nullptr)) |
| 363 SocketAddressFromSockAddrStorage(addr_storage, out_addr); | 387 SocketAddressFromSockAddrStorage(addr_storage, out_addr); |
| 364 int error = GetError(); | 388 int error = GetError(); |
| 365 bool success = (received >= 0) || IsBlockingError(error); | 389 bool success = (received >= 0) || IsBlockingError(error); |
| 366 if (udp_ || success) { | 390 if (udp_ || success) { |
| 367 enabled_events_ |= DE_READ; | 391 enabled_events_ |= DE_READ; |
| 368 } | 392 } |
| 369 if (!success) { | 393 if (!success) { |
| 370 LOG_F(LS_VERBOSE) << "Error = " << error; | 394 LOG_F(LS_VERBOSE) << "Error = " << error; |
| (...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1627 break; | 1651 break; |
| 1628 } | 1652 } |
| 1629 } | 1653 } |
| 1630 | 1654 |
| 1631 // Done | 1655 // Done |
| 1632 return true; | 1656 return true; |
| 1633 } | 1657 } |
| 1634 #endif // WEBRTC_WIN | 1658 #endif // WEBRTC_WIN |
| 1635 | 1659 |
| 1636 } // namespace rtc | 1660 } // namespace rtc |
| OLD | NEW |