, , - , , -, , . , - :
pkt_type = tcp_getbyte(my_stream, timeout);
pkt_length = tcp_getbyte(my_stream, timeout);
pkt_length |= tcp_getbyte(my_stream, timeout) << 8;
if (pkt_length < MAX_PACKET_LENGTH)
{
for (i=0; i<pkt_length; i++)
buffer[i] = tcp_getbyte(my_stream, timeout);
}
if (!my_stream->error)
{
/* Do something with packet */
}
If one attempt to get a byte timeout, subsequent attempts will fail unconditionally, returning zero. There is no need to check each operation for failure; if something goes wrong, the system will behave as if tcp_getbyte () had thrown an exception, just not so fast.
source
share