static struct iovec *iovecs = NULL;
static GlPacket packet;
static char *in_buffer = NULL;
-static unsigned in_length;
+static unsigned in_fill = 0;
+static unsigned in_offset = 0;
static void next_vec(GlPacket *pkt)
{
if(!in_buffer)
in_buffer = (char *)malloc(1024);
- ret = read(fd, in_buffer+in_length, 1024-in_length);
- if(ret>0)
+ if(in_offset)
{
- GlPacket *pkt;
- unsigned pkt_length;
+ memmove(in_buffer, in_buffer+in_offset, in_fill-in_offset);
+ in_fill -= in_offset;
+ in_offset = 0;
+ }
- in_length += ret;
+ ret = read(fd, in_buffer+in_fill, 1024-in_fill);
+ if(ret>0)
+ in_fill += ret;
+ }
- pkt_length = in_length;
- pkt = packet_receive_str(in_buffer, &pkt_length);
- if(pkt)
- {
- in_length -= pkt_length;
- memmove(in_buffer, in_buffer+pkt_length, in_length);
- }
+ if(ret>0 || in_fill>in_offset)
+ {
+ GlPacket *pkt;
+ unsigned pkt_length;
- return pkt;
- }
+ pkt_length = in_fill;
+ pkt = packet_receive_str(in_buffer+in_offset, &pkt_length);
+ if(pkt)
+ in_offset += pkt_length;
+
+ return pkt;
}
return NULL;