Is this the proper way to iterate over a read
on a socket? I am having a hard time getting this to work properly. data.size
is an unsigned int
that is populated from the socket as well. It is correct. data.data
is an unsigned char *
.
if ( data.size > 0 ) {
data.data = (unsigned char*)malloc(data.size);
memset(&data.data, 0, data.size);
int remainingSize = data.size;
unsigned char *iter = data.data;
int count = 0;
do {
count = read(connect_fd, iter, remainingSize);
iter += count;
remainingSize -= count;
} while (count > 0 && remainingSize > 0);
}
else {
data.data = 0;
}
Thanks in advance.