From 1ef8fe5a16ff5b9dc54c5849a81e7c32784c089d Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 6 Nov 2006 14:50:45 +0100 Subject: [PATCH] ndb - bug#24011 ndb/src/common/util/socket_io.cpp: Fix problem with cut sockmessages --- ndb/src/common/util/socket_io.cpp | 86 +++++++++++++++++++------------ 1 file changed, 52 insertions(+), 34 deletions(-) diff --git a/ndb/src/common/util/socket_io.cpp b/ndb/src/common/util/socket_io.cpp index 58636e6663d..96efbac57d7 100644 --- a/ndb/src/common/util/socket_io.cpp +++ b/ndb/src/common/util/socket_io.cpp @@ -53,10 +53,6 @@ readln_socket(NDB_SOCKET_TYPE socket, int timeout_millis, if(buflen <= 1) return 0; - int sock_flags= fcntl(socket, F_GETFL); - if(fcntl(socket, F_SETFL, sock_flags | O_NONBLOCK) == -1) - return -1; - fd_set readset; FD_ZERO(&readset); FD_SET(socket, &readset); @@ -71,43 +67,65 @@ readln_socket(NDB_SOCKET_TYPE socket, int timeout_millis, } if(selectRes == -1){ - fcntl(socket, F_SETFL, sock_flags); return -1; } - buf[0] = 0; - const int t = recv(socket, buf, buflen, MSG_PEEK); - - if(t < 1) + char* ptr = buf; + int len = buflen; + do { - fcntl(socket, F_SETFL, sock_flags); - return -1; - } - - for(int i=0; i< t;i++) - { - if(buf[i] == '\n'){ - recv(socket, buf, i+1, 0); - buf[i] = 0; - - if(i > 0 && buf[i-1] == '\r'){ - i--; - buf[i] = 0; - } - - fcntl(socket, F_SETFL, sock_flags); - return t; + int t; + while((t = recv(socket, ptr, len, MSG_PEEK)) == -1 && errno == EINTR); + + if(t < 1) + { + return -1; } - } - if(t == (buflen - 1)){ - recv(socket, buf, t, 0); - buf[t] = 0; - fcntl(socket, F_SETFL, sock_flags); - return buflen; - } + + for(int i = 0; i 0); + + return -1; } extern "C"