summaryrefslogtreecommitdiff
path: root/ndb
diff options
context:
space:
mode:
authorjonas@perch.ndb.mysql.com <>2006-11-06 14:50:45 +0100
committerjonas@perch.ndb.mysql.com <>2006-11-06 14:50:45 +0100
commitc8d07748c258f8ff5806a81592deb0edfd39165d (patch)
treee695310852c329e3641d501ea45aa87a4c060330 /ndb
parent4037a8d6572b51129c49756b3c427400b5d7b0cd (diff)
downloadmariadb-git-c8d07748c258f8ff5806a81592deb0edfd39165d.tar.gz
ndb - bug#24011
Diffstat (limited to 'ndb')
-rw-r--r--ndb/src/common/util/socket_io.cpp84
1 files changed, 51 insertions, 33 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)
- {
- fcntl(socket, F_SETFL, sock_flags);
return -1;
}
- for(int i=0; i< t;i++)
+ char* ptr = buf;
+ int len = buflen;
+ do
{
- if(buf[i] == '\n'){
- recv(socket, buf, i+1, 0);
- buf[i] = 0;
+ int t;
+ while((t = recv(socket, ptr, len, MSG_PEEK)) == -1 && errno == EINTR);
+
+ if(t < 1)
+ {
+ return -1;
+ }
- if(i > 0 && buf[i-1] == '\r'){
- i--;
- buf[i] = 0;
+
+ for(int i = 0; i<t; i++)
+ {
+ if(ptr[i] == '\n')
+ {
+ /**
+ * Now consume
+ */
+ for (len = 1 + i; len; )
+ {
+ while ((t = recv(socket, ptr, len, 0)) == -1 && errno == EINTR);
+ if (t < 1)
+ return -1;
+ ptr += t;
+ len -= t;
+ }
+ ptr[0]= 0;
+ return ptr - buf;
}
-
- fcntl(socket, F_SETFL, sock_flags);
- return t;
}
- }
-
- if(t == (buflen - 1)){
- recv(socket, buf, t, 0);
- buf[t] = 0;
- fcntl(socket, F_SETFL, sock_flags);
- return buflen;
- }
+
+ for (int tmp = t; tmp; )
+ {
+ while ((t = recv(socket, ptr, tmp, 0)) == -1 && errno == EINTR);
+ if (t < 1)
+ {
+ return -1;
+ }
+ ptr += t;
+ len -= t;
+ tmp -= t;
+ }
- return 0;
+ FD_ZERO(&readset);
+ FD_SET(socket, &readset);
+ timeout.tv_sec = (timeout_millis / 1000);
+ timeout.tv_usec = (timeout_millis % 1000) * 1000;
+ const int selectRes = select(socket + 1, &readset, 0, 0, &timeout);
+ if(selectRes != 1){
+ return -1;
+ }
+ } while (len > 0);
+
+ return -1;
}
extern "C"