Name: Anonymous 2007-08-14 12:14 ID:0gEP3LHW
I'm trying to come up with a good way to manage this buffer. However, with my current method, they are sometimes cut short, and there is a large backlog. For example, say the buffer contains "one\ntwo\nthree\nfour\n". It will process "one\n" and stop there. Then, when I recv five\n, it will finally process two\n. So on and so forth, it creates a huge backlog that processes older packets (finally) whenever it receives a new one. I'm fairly new to socket programming, and my buffer handling isn't quite up to par, I suppose. For anyone wondering, the reason it appends the buffer is because the end of the previous buffer may have a cut off command (for instance "sev", and the next receive will have "en\n"). If any of you could help me here, it'd be greatly appreciated. Function below.
bool sockRead()
{
memset(tmpbuffer, '\0', strlen(tmpbuffer));
length = recv(ircSocket, buffer, 2048, 0);
if(length != SOCKET_ERROR)
{
char *scout = strncat(nbuffer, buffer, sizeof(nbuffer) - strlen(nbuffer) - 1);
FILE *file;
file = fopen("output.txt","a+");
fprintf(file, "\nSCOUT: %s\n", scout);
fclose(file);
if(char *end = strchr(nbuffer, '\n') + 1)
{
strncpy(tmpbuffer, nbuffer, end - nbuffer);
int x = strlen(nbuffer);
memmove(nbuffer, end, x);
nbuffer[x] = '\0';
if(msgHandler() != true)
{
return false;
}
}
return true;
}
printf("Line is dead.\n");
return false;
}
bool sockRead()
{
memset(tmpbuffer, '\0', strlen(tmpbuffer));
length = recv(ircSocket, buffer, 2048, 0);
if(length != SOCKET_ERROR)
{
char *scout = strncat(nbuffer, buffer, sizeof(nbuffer) - strlen(nbuffer) - 1);
FILE *file;
file = fopen("output.txt","a+");
fprintf(file, "\nSCOUT: %s\n", scout);
fclose(file);
if(char *end = strchr(nbuffer, '\n') + 1)
{
strncpy(tmpbuffer, nbuffer, end - nbuffer);
int x = strlen(nbuffer);
memmove(nbuffer, end, x);
nbuffer[x] = '\0';
if(msgHandler() != true)
{
return false;
}
}
return true;
}
printf("Line is dead.\n");
return false;
}