summaryrefslogtreecommitdiff
path: root/grid
diff options
context:
space:
mode:
authorDwight <dmerriman@gmail.com>2008-02-25 19:13:30 -0500
committerDwight <dmerriman@gmail.com>2008-02-25 19:13:30 -0500
commit880049d39e7bbf5aa496e2e5ee673721fc44e1b4 (patch)
treed9b060f7ff717160f1a7c122db451083a1b66062 /grid
parentdce3cb2a9e6b01044af0edd7b1b5bfbfddddcc04 (diff)
downloadmongo-880049d39e7bbf5aa496e2e5ee673721fc44e1b4.tar.gz
recv()
Diffstat (limited to 'grid')
-rw-r--r--grid/message.cpp38
1 files changed, 25 insertions, 13 deletions
diff --git a/grid/message.cpp b/grid/message.cpp
index ca328453fdb..0a10667e49f 100644
--- a/grid/message.cpp
+++ b/grid/message.cpp
@@ -95,21 +95,33 @@ bool MessagingPort::connect(SockAddr& _far)
bool MessagingPort::recv(Message& m) {
mmm( cout << "* recv() sock:" << this->sock << endl; )
- int len;
+ int len = -1;
- int x = ::recv(sock, (char *) &len, 4, 0);
- if( x == 0 ) {
- cout << "MessagingPort::recv(): conn closed? " << farEnd.toString() << endl;
- m.reset();
- return false;
- }
- if( x < 0 ) {
- cout << "MessagingPort::recv(): recv() error " << errno << ' ' << farEnd.toString()<<endl;
- m.reset();
- return false;
+ char *lenbuf = (char *) &len;
+ int lft = 4;
+ while( 1 ) {
+ int x = ::recv(sock, lenbuf, lft, 0);
+ if( x == 0 ) {
+ cout << "MessagingPort::recv(): conn closed? " << farEnd.toString() << endl;
+ m.reset();
+ return false;
+ }
+ if( x < 0 ) {
+ cout << "MessagingPort::recv(): recv() error " << errno << ' ' << farEnd.toString()<<endl;
+ m.reset();
+ return false;
+ }
+ lft -= x;
+ if( lft == 0 )
+ break;
+ lenbuf += x;
+ cout << "MessagingPort::recv(): got " << x << " bytes wanted 4, lft=" << lft << endl;
+ assert( lft > 0 );
}
- assert( x == 4 );
+// assert( x == 4 );
+
+ assert( len >= 0 && len <= 16000000 );
int z = (len+1023)&0xfffffc00; assert(z>=len);
MsgData *md = (MsgData *) malloc(z);
@@ -123,7 +135,7 @@ bool MessagingPort::recv(Message& m) {
char *p = (char *) &md->id;
int left = len -4;
while( 1 ) {
- x = ::recv(sock, p, left, 0);
+ int x = ::recv(sock, p, left, 0);
if( x == 0 ) {
cout << "MessagingPort::recv(): conn closed? " << farEnd.toString() << endl;
m.reset();