You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dr...@apache.org on 2010/03/09 06:19:54 UTC
svn commit: r920677 -
/incubator/thrift/trunk/lib/cpp/src/transport/TSocket.cpp
Author: dreiss
Date: Tue Mar 9 05:19:54 2010
New Revision: 920677
URL: http://svn.apache.org/viewvc?rev=920677&view=rev
Log:
cpp: TSocket: call a second gettimeofday only for error checking
Previously, we called gettimeofday twice for every send, which is
costly. Now, we only make the second call if send fails with EAGAIN.
Modified:
incubator/thrift/trunk/lib/cpp/src/transport/TSocket.cpp
Modified: incubator/thrift/trunk/lib/cpp/src/transport/TSocket.cpp
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/transport/TSocket.cpp?rev=920677&r1=920676&r2=920677&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/transport/TSocket.cpp (original)
+++ incubator/thrift/trunk/lib/cpp/src/transport/TSocket.cpp Tue Mar 9 05:19:54 2010
@@ -308,16 +308,17 @@ uint32_t TSocket::read(uint8_t* buf, uin
gettimeofday(&begin, NULL);
int got = recv(socket_, buf, len, 0);
int errno_copy = errno; //gettimeofday can change errno
- struct timeval end;
- gettimeofday(&end, NULL);
- uint32_t readElapsedMicros = (((end.tv_sec - begin.tv_sec) * 1000 * 1000)
- + (((uint64_t)(end.tv_usec - begin.tv_usec))));
++g_socket_syscalls;
// Check for error on read
if (got < 0) {
if (errno_copy == EAGAIN) {
// check if this is the lack of resources or timeout case
+ struct timeval end;
+ gettimeofday(&end, NULL);
+ uint32_t readElapsedMicros = (((end.tv_sec - begin.tv_sec) * 1000 * 1000)
+ + (((uint64_t)(end.tv_usec - begin.tv_usec))));
+
if (!eagainThresholdMicros || (readElapsedMicros < eagainThresholdMicros)) {
if (retries++ < maxRecvRetries_) {
usleep(50);