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

Pages: 1-4041-

[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: 1 2007-08-14 12:15 ID:0gEP3LHW

I forgot to mention... if I do something like change the 'if' to a 'while', a strange exception is thrown...marking "00000000()" and providing no source-code breakpoint.

Name: Anonymous 2007-08-14 12:42 ID:Heaven

>>2
excuse me is tmpbuffer and buffer global variables?
post all your fucking source.


if(char *end = strchr(nbuffer, '\n') + 1)

FUCKING BUGGY. end will always be true except if strchr returns UINT_MAX.
correct:

char *end;
if(end = strchr(nbuffer, '\n')) {
end++;
/* rest */
} else {
/* not found */
}

Name: Anonymous 2007-08-14 12:55 ID:CQM6hLeV

First of, let me say that i have absolutly NO experience with socket programming in C/C++

in your example, in your second if-statement, you are not making any logical comparison, you are setting (char*) end to the return value of strchr(nbuffer,'\n') plus 1.
So depending on what compiler you use, it will always be true, or always be false.

Im guessing that what you are trying to do is to determine if your buffer contains '\n' and if so set 'end' to the next adress in your buffer and then execute whats in your scope after the if.

if that is what you really want to do you could try this:
       
char *end=strchr(nbuffer,'\n')+1;
if(end!=NULL)//old line was: if(char *end = strchr(nbuffer, '\n') + 1)
{
   strncpy(tmpbuffer, nbuffer, end - nbuffer);
   //..more code inside
}

Name: Anonymous 2007-08-14 13:10 ID:Heaven

>>3 here
>>4

char *end=strchr(nbuffer,'\n')+1;
if(end!=NULL)//old line was: if(char *end = strchr(nbuffer, '\n') + 1)

god, another idiot.
OYOU'RE DOING THE SAME FUCKING THING YOU FUCKING IDIOT
TAKE A FUCKING LOOK AT MY FUCKING CODE
GODFUCKING FAMN

Name: Anonymous 2007-08-14 14:45 ID:CQM6hLeV

>>5
>>4 here
I stand corrected, missed that by adding one it's never a null pointer.
Also, you had not answerd when i wrote my reply.

Name: Anonymous 2007-08-14 15:00 ID:oKB8fI/j

>>1-6
EXPERT PROGRAMMERS

Name: 1 2007-08-14 16:58 ID:0gEP3LHW

I fixed it after all. It just took me a while and a lot of tinkering. It just took a little reorganizing, and changes of a couple offsets. It's working great now. Thanks anyway.

Name: Anonymous 2007-08-14 19:11 ID:Heaven

>>6
this fucking idiot does not fucking understand does he/

okay look idiot
f() is a function that returns either 0 or a number that we do not care about.
We want to assign the return value of f() and add 1 ONLY IF it has not returned 0.
right?
so what do we do?

x = f() + 1;
if(x == 0) ? NO.

Name: Anonymous 2011-02-03 0:35

Name: Anonymous 2011-02-17 20:15

that's cool and all, but check my doubles over there

Name: Anonymous 2011-03-31 12:13

I am the phantom autist

Name: Anonymous 2011-03-31 12:13

I am the phantom autist

Name: Anonymous 2011-03-31 12:13

I am the phantom autist

Name: Anonymous 2011-03-31 12:13

I am the phantom autist

Name: Anonymous 2011-03-31 12:13

I am the phantom autist

Name: Anonymous 2011-03-31 12:13

I am the phantom autist

Name: Anonymous 2011-03-31 12:13

I am the phantom autist

Name: Anonymous 2011-03-31 12:13

I am the phantom autist

Name: Anonymous 2011-03-31 12:13

I am the phantom autist

Name: Anonymous 2011-04-27 3:45

HI IM A PROGRAMMER IM 13 I CAN PROGRAM CALCULATOR SORRY FOR MY INGLISH IM NOT INGLISH I CREATED A RANDOM NUMBER GENERATOR HERE IT IS 0.8867877189337707

Name: Anonymous 2011-04-27 3:48

Name: Anonymous 2011-04-27 3:52

Name: Anonymous 2011-04-27 3:57

Name: Anonymous 2011-04-27 4:01

Name: Anonymous 2011-04-27 4:05

Name: Anonymous 2011-04-27 4:10

Name: Anonymous 2011-04-27 4:14

Name: Anonymous 2011-04-27 4:19

Name: Anonymous 2011-04-27 4:23

Name: Anonymous 2011-04-27 4:27

Name: Anonymous 2011-04-27 4:32

Name: Anonymous 2011-04-27 4:36

Name: Anonymous 2011-04-27 4:41

Name: Anonymous 2011-04-27 4:45

Name: Anonymous 2011-04-27 4:50

Name: Anonymous 2011-04-27 4:54

Name: Anonymous 2011-04-27 4:58

Name: Anonymous 2011-04-27 5:03

Name: Anonymous 2011-04-27 5:07

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

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