Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

[C/C++] Backlog issue

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;
}

Name: Anonymous 2011-04-27 5:12

Name: Anonymous 2011-04-27 5:16

Name: Anonymous 2011-04-27 5:21

Name: Anonymous 2011-04-27 5:25

Name: Anonymous 2011-04-27 5:29

Name: Anonymous 2011-04-27 5:34

Name: Anonymous 2011-04-27 5:38

Name: Anonymous 2011-04-27 5:43

Name: Anonymous 2011-04-27 5:47

Name: Anonymous 2011-04-27 5:52

Name: Anonymous 2011-04-27 5:56

Name: Anonymous 2011-04-27 6:00

Name: Anonymous 2011-04-27 6:05

Name: Anonymous 2011-04-27 6:09

Name: Anonymous 2011-04-27 6:14

Name: Anonymous 2011-04-27 8:11

Name: Anonymous 2011-04-27 8:15

Name: Anonymous 2011-04-27 11:04

Name: Anonymous 2011-04-27 11:33

Name: Anonymous 2011-04-27 12:00

Name: Anonymous 2011-04-27 12:05

Name: Anonymous 2011-04-27 12:09

Name: Anonymous 2011-04-27 12:14

Name: Anonymous 2011-04-27 12:18

Name: Anonymous 2011-04-27 12:23

Name: Anonymous 2013-04-04 21:03

On my knees

Begging for dubs

Name: Anonymous 2013-04-05 0:55

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 "e/g/", and the next receive will have "in\n"). If any of you could help me here, it'd be greatly appreciated.

Name: Anonymous 2013-04-05 7:31

1. you should be processing that in a loop

2. you should keep track of how much is left in the buffer and recv() at that offset, so that you don't overwrite old commands

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List