Read recv timestamps from socket (posix only).

This helps a lot on Android devices where the user threads can be scheduled with low priority when the app is in the background, causing spurious significantly delayed before a packet can be read from the socket. With this patch the timestamp is taken by the kernel when the packet actually arrives.

R=juberti@chromium.org
TBR=juberti@webrtc.org

BUG=webrtc:5773

Review URL: https://codereview.webrtc.org/1944683002 .

Cr-Commit-Position: refs/heads/master@{#12850}
This commit is contained in:
Stefan Holmer
2016-05-23 18:19:26 +02:00
parent 181310fb6f
commit 9131efdb30
34 changed files with 256 additions and 89 deletions

View File

@ -119,7 +119,7 @@ static int socket_read(BIO* b, char* out, int outl) {
return -1;
rtc::AsyncSocket* socket = static_cast<rtc::AsyncSocket*>(b->ptr);
BIO_clear_retry_flags(b);
int result = socket->Recv(out, outl);
int result = socket->Recv(out, outl, nullptr);
if (result > 0) {
return result;
} else if (result == 0) {
@ -524,13 +524,12 @@ OpenSSLAdapter::SendTo(const void* pv, size_t cb, const SocketAddress& addr) {
return SOCKET_ERROR;
}
int
OpenSSLAdapter::Recv(void* pv, size_t cb) {
int OpenSSLAdapter::Recv(void* pv, size_t cb, int64_t* timestamp) {
//LOG(LS_INFO) << "OpenSSLAdapter::Recv(" << cb << ")";
switch (state_) {
case SSL_NONE:
return AsyncSocketAdapter::Recv(pv, cb);
return AsyncSocketAdapter::Recv(pv, cb, timestamp);
case SSL_WAIT:
case SSL_CONNECTING:
@ -579,10 +578,12 @@ OpenSSLAdapter::Recv(void* pv, size_t cb) {
return SOCKET_ERROR;
}
int
OpenSSLAdapter::RecvFrom(void* pv, size_t cb, SocketAddress* paddr) {
int OpenSSLAdapter::RecvFrom(void* pv,
size_t cb,
SocketAddress* paddr,
int64_t* timestamp) {
if (socket_->GetState() == Socket::CS_CONNECTED) {
int ret = Recv(pv, cb);
int ret = Recv(pv, cb, timestamp);
*paddr = GetRemoteAddress();