Originally Posted by
brewbuck
I doubt it. Processors are fast. Networks are slow.
There is no way around the fact that you have to queue up the data while you wait for the line terminators. The code is more complicated but I think your performance worries are unfounded. You aren't considering doing it "wrong" to actually be an option, are you?
That's the problem. I don't know what "wrong" is. I'm not a very strong C coder, which is why I'm starting this project. What I've thought of doing is similar to this:
Code:
char *buffer = NULL;
char tmp[128] = "";
int buffersize = 128;
int n = 0;
buffer = malloc(buffersize * sizeof(char));
buffer[0] = 0;
while ((n = recv(s, tmp, 128, 0)) > 0) {
tmp[n] = 0;
if ((strlen(tmp) + strlen(buffer)) >= buffersize) {
buffersize = buffersize * 2;
buffer = realloc(buffer, buffersize * sizeof(char));
}
strcat(buffer, tmp);
if (buffer[strlen(buffer) - 1] == '\n') {
ParseData(buffer);
buffersize = 128;
free(buffer);
buffer = malloc(buffersize * sizeof(char));
buffer[0] = 0;
}
}