summaryrefslogtreecommitdiff
path: root/ndb
diff options
context:
space:
mode:
authorunknown <mskold/marty@mysql.com/linux.site>2006-11-14 10:06:11 +0100
committerunknown <mskold/marty@mysql.com/linux.site>2006-11-14 10:06:11 +0100
commit6dc05dde2bf8e139fb105e5fdf285bb8d46cd123 (patch)
treedc7c5b515bd62a53fb365786d265f58ca0a179d5 /ndb
parent383fbde53239a9d4fd4e444a0b6d8942305f74f5 (diff)
parent01e550d05b9e217c478694e231e5ea086392778e (diff)
downloadmariadb-git-6dc05dde2bf8e139fb105e5fdf285bb8d46cd123.tar.gz
Merge mskold@bk-internal.mysql.com:/home/bk/mysql-5.0
into mysql.com:/windows/Linux_space/MySQL/mysql-5.0-ndb sql/ha_ndbcluster.cc: Auto merged
Diffstat (limited to 'ndb')
-rw-r--r--ndb/src/common/util/socket_io.cpp82
1 files changed, 50 insertions, 32 deletions
diff --git a/ndb/src/common/util/socket_io.cpp b/ndb/src/common/util/socket_io.cpp
index ba2794e4374..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;
}
- 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;
- }
+ int t;
+ while((t = recv(socket, ptr, len, MSG_PEEK)) == -1 && errno == EINTR);
+
+ if(t < 1)
+ {
+ return -1;
+ }
- for(int i=0; i< t;i++)
- {
- if(buf[i] == '\n'){
- int r= recv(socket, buf, i+1, 0);
- buf[i+1]= 0;
- if(r < 1) {
- fcntl(socket, F_SETFL, sock_flags);
- return -1;
+
+ 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;
}
-
- if(i > 0 && buf[i-1] == '\r'){
- buf[i-1] = '\n';
- buf[i]= '\0';
+ }
+
+ for (int tmp = t; tmp; )
+ {
+ while ((t = recv(socket, ptr, tmp, 0)) == -1 && errno == EINTR);
+ if (t < 1)
+ {
+ return -1;
}
-
- fcntl(socket, F_SETFL, sock_flags);
- return r;
+ ptr += t;
+ len -= t;
+ tmp -= t;
}
- }
- int r= recv(socket, buf, t, 0);
- if(r>=0)
- buf[r] = 0;
- fcntl(socket, F_SETFL, sock_flags);
- return r;
+ 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"