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

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

Issue 1944683002: Read recv timestamps from socket (posix only). (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 4 years, 7 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/physicalsocketserver.h ('k') | webrtc/base/physicalsocketserver_unittest.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"
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
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);
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
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 if (timestamp) {
363 *timestamp = GetSocketRecvTimestamp(s_);
364 }
341 UpdateLastError(); 365 UpdateLastError();
342 int error = GetError(); 366 int error = GetError();
343 bool success = (received >= 0) || IsBlockingError(error); 367 bool success = (received >= 0) || IsBlockingError(error);
344 if (udp_ || success) { 368 if (udp_ || success) {
345 enabled_events_ |= DE_READ; 369 enabled_events_ |= DE_READ;
346 } 370 }
347 if (!success) { 371 if (!success) {
348 LOG_F(LS_VERBOSE) << "Error = " << error; 372 LOG_F(LS_VERBOSE) << "Error = " << error;
349 } 373 }
350 return received; 374 return received;
351 } 375 }
352 376
353 int PhysicalSocket::RecvFrom(void* buffer, 377 int PhysicalSocket::RecvFrom(void* buffer,
354 size_t length, 378 size_t length,
355 SocketAddress* out_addr) { 379 SocketAddress* out_addr,
380 int64_t* timestamp) {
356 sockaddr_storage addr_storage; 381 sockaddr_storage addr_storage;
357 socklen_t addr_len = sizeof(addr_storage); 382 socklen_t addr_len = sizeof(addr_storage);
358 sockaddr* addr = reinterpret_cast<sockaddr*>(&addr_storage); 383 sockaddr* addr = reinterpret_cast<sockaddr*>(&addr_storage);
359 int received = ::recvfrom(s_, static_cast<char*>(buffer), 384 int received = ::recvfrom(s_, static_cast<char*>(buffer),
360 static_cast<int>(length), 0, addr, &addr_len); 385 static_cast<int>(length), 0, addr, &addr_len);
386 if (timestamp) {
387 *timestamp = GetSocketRecvTimestamp(s_);
388 }
361 UpdateLastError(); 389 UpdateLastError();
362 if ((received >= 0) && (out_addr != nullptr)) 390 if ((received >= 0) && (out_addr != nullptr))
363 SocketAddressFromSockAddrStorage(addr_storage, out_addr); 391 SocketAddressFromSockAddrStorage(addr_storage, out_addr);
364 int error = GetError(); 392 int error = GetError();
365 bool success = (received >= 0) || IsBlockingError(error); 393 bool success = (received >= 0) || IsBlockingError(error);
366 if (udp_ || success) { 394 if (udp_ || success) {
367 enabled_events_ |= DE_READ; 395 enabled_events_ |= DE_READ;
368 } 396 }
369 if (!success) { 397 if (!success) {
370 LOG_F(LS_VERBOSE) << "Error = " << error; 398 LOG_F(LS_VERBOSE) << "Error = " << error;
(...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 break; 1655 break;
1628 } 1656 }
1629 } 1657 }
1630 1658
1631 // Done 1659 // Done
1632 return true; 1660 return true;
1633 } 1661 }
1634 #endif // WEBRTC_WIN 1662 #endif // WEBRTC_WIN
1635 1663
1636 } // namespace rtc 1664 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/physicalsocketserver.h ('k') | webrtc/base/physicalsocketserver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698