3 namespace remote
{ namespace protocols
{
14 if (data
) delete data
;
18 bool Message::nonBlockingRecv(int fd
)
20 char* p_datalen
= (char*)&datalen
;
22 uint32_t targetRecvLen
;
24 if ( recvLen
< sizeof(datalen
))
26 // still at the datalen part
27 r
= read(fd
,p_datalen
+recvLen
,sizeof(datalen
)-recvLen
);
31 log("Recv error %i\n",e
);
32 __THROW__("Unable to read message length!");
36 if ( recvLen
< sizeof(datalen
) )
40 if ( recvLen
== sizeof(datalen
) )
42 datalen
= ntohl(datalen
);
43 if (datalen
> 512000) __THROW__("Data too long!");
44 if (data
) delete data
;
45 data
= new uint8_t[datalen
];
47 targetRecvLen
= datalen
+ sizeof(datalen
);
48 if ( recvLen
>= sizeof(datalen
) && recvLen
< targetRecvLen
)
50 r
= read(fd
,data
+recvLen
-sizeof(datalen
),targetRecvLen
-recvLen
);
54 log("Recv error %i\n",e
);
55 __THROW__ ("Unable to read message data!");
58 // printf("Read %u of %u bytes.\n",recvLen-sizeof(datalen),datalen);
60 if (recvLen
== targetRecvLen
)
69 /*void Message::recvMsg(int fd,BaseMsg& msg)
71 if (data) delete data;
72 // read length, then data
73 if (!recv(fd,datalen))
74 __THROW__ ("Unable to receive datalen!");
75 // printf("Reading %u bytes of message data\n",datalen);
76 data = new uint8_t[datalen];
77 if (recv(fd, (char*)data, datalen, MSG_WAITALL) <= 0)
78 __THROW__ ("Unable to send data!");
80 uint32_t len = datalen;
81 // let msg read the buffer
84 // printf("Done reading %u bytes of message data\n\n\n",datalen);
87 void Message::sendMsg(int fd
,BaseMsg
& msg
)
90 if (data
) delete data
;
92 datalen
= msg
.getLength();
93 data
= new uint8_t[datalen
];
95 // printf("Writing %u bytes of message data\n",datalen);
102 // write length, then data
103 if (!send(fd
,datalen
))
104 __THROW__ ("Unable to send datalen!");
105 if (::send(fd
, (char*)data
, datalen
, 0) != ((int64_t)datalen
))
106 __THROW__ ("Unable to send data!");
107 // printf("Done writing %u bytes of message data\n\n\n",datalen);
110 uint32_t Message::getLength()
115 uint8_t* Message::getData()