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
);
29 Log::error("Recv error: %s", strerror(errno
));
30 __THROW__("Unable to read message length!");
34 if ( recvLen
< sizeof(datalen
) )
38 if ( recvLen
== sizeof(datalen
) )
40 datalen
= ntohl(datalen
);
41 if (datalen
> 512000) __THROW__("Data too long!");
42 if (data
) delete data
;
43 data
= new uint8_t[datalen
];
45 targetRecvLen
= datalen
+ sizeof(datalen
);
46 if ( recvLen
>= sizeof(datalen
) && recvLen
< targetRecvLen
)
48 r
= read(fd
,data
+recvLen
-sizeof(datalen
),targetRecvLen
-recvLen
);
50 Log::error("Recv error: %s", strerror(errno
));
51 __THROW__ ("Unable to read message data!");
54 // printf("Read %u of %u bytes.\n",recvLen-sizeof(datalen),datalen);
56 if (recvLen
== targetRecvLen
)
65 void Message::sendMsg(int fd
,BaseMsg
& msg
)
68 if (data
) delete data
;
70 datalen
= msg
.getLength();
71 data
= new uint8_t[datalen
];
73 // printf("Writing %u bytes of message data\n",datalen);
80 // write length, then data
81 if (!send(fd
,datalen
))
82 __THROW__ ("Unable to send datalen!");
83 if (::send(fd
, (char*)data
, datalen
, 0) != ((int64_t)datalen
))
84 __THROW__ ("Unable to send data!");
85 // printf("Done writing %u bytes of message data\n\n\n",datalen);
88 uint32_t Message::getLength()
93 uint8_t* Message::getData()