[PATCH] WL#3704 mgmapi timeouts: Fix infinite (0) timeout for ndb_logevent_get_next

Index: ndb-work/storage/ndb/src/mgmapi/ndb_logevent.cpp
===================================================================
parent 471469a6
...@@ -389,14 +389,18 @@ int ndb_logevent_get_next(const NdbLogEventHandle h, ...@@ -389,14 +389,18 @@ int ndb_logevent_get_next(const NdbLogEventHandle h,
struct ndb_logevent *dst, struct ndb_logevent *dst,
unsigned timeout_in_milliseconds) unsigned timeout_in_milliseconds)
{ {
if (timeout_in_milliseconds == 0)
{
int res;
while ((res = ndb_logevent_get_next(h, dst, 60000))==0);
return res;
}
SocketInputStream in(h->socket, timeout_in_milliseconds); SocketInputStream in(h->socket, timeout_in_milliseconds);
Properties p; Properties p;
char buf[256]; char buf[256];
struct timeval start_time;
gettimeofday(&start_time, 0);
/* header */ /* header */
while (1) { while (1) {
if (in.gets(buf,sizeof(buf)) == 0) if (in.gets(buf,sizeof(buf)) == 0)
...@@ -409,24 +413,15 @@ int ndb_logevent_get_next(const NdbLogEventHandle h, ...@@ -409,24 +413,15 @@ int ndb_logevent_get_next(const NdbLogEventHandle h,
// timed out // timed out
return 0; return 0;
} }
if ( strcmp("log event reply\n", buf) == 0 ) if ( strcmp("log event reply\n", buf) == 0 )
break; break;
if ( strcmp("<PING>\n", buf) ) if ( strcmp("<PING>\n", buf) )
ndbout_c("skipped: %s", buf); ndbout_c("skipped: %s", buf);
struct timeval now; if(in.timedout())
gettimeofday(&now, 0); return 0;
unsigned elapsed_ms= (now.tv_sec-start_time.tv_sec)*1000 +
((signed int)now.tv_usec-(signed int)start_time.tv_usec)/1000;
if (elapsed_ms >= timeout_in_milliseconds)
{
// timed out
return 0;
}
new (&in) SocketInputStream(h->socket, timeout_in_milliseconds-elapsed_ms);
} }
/* read name-value pairs into properties object */ /* read name-value pairs into properties object */
...@@ -437,11 +432,9 @@ int ndb_logevent_get_next(const NdbLogEventHandle h, ...@@ -437,11 +432,9 @@ int ndb_logevent_get_next(const NdbLogEventHandle h,
h->m_error= NDB_LEH_READ_ERROR; h->m_error= NDB_LEH_READ_ERROR;
return -1; return -1;
} }
if ( buf[0] == 0 ) if (in.timedout())
{
// timed out
return 0; return 0;
}
if ( buf[0] == '\n' ) if ( buf[0] == '\n' )
{ {
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment