nodejs / http-parser

http request/response parser for c

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

assert(!messages[num_messages].message_begin_cb_called);

jiamuluo opened this issue · comments

commented

my application is running by sisngle thread ,so i defines tatic struct message messages[1];.every time i need parse http data,i will do that
num_messages = 0;
bzero(messages,sizeof(messages)); ,
messages[num_messages].message_begin_cb_called = FALSE;,
http_parser_init(parser, HTTP_BOTH);
http_parser_execute(parser, &settings, data, slDataLen);

But i always exit caused by assert(!messages[num_messages].message_begin_cb_called); in message_begin_cb,
.i dont known what happend.please give me some advice.thank you

It'd help if the code that you pasted would be compiled and run. Could you create a gist on https://gist.github.com with the full code that reproduces the issue?

commented

i am so sorry.the part of my http-parse code cannot compiled and run independently,but i would show my code here.

commented

It'd help if the code that you pasted would be compiled and run. Could you create a gist on https://gist.github.com with the full code that reproduces the issue?

i am so sorry.the part of my http-parse code cannot compiled and run independently,but i would show my code here.

The formatting messes up the source code, it is still very hard to get a grok of it.

commented

@jiamuluo could you move this to https://gist.github.com/ ?

https://gist.github.com/jiamuluo/f8bbfd12a5b8da92459123cdc55defd3.
do you mean this?this is a sample code that indicates my code how to run.But it cannot compile. i guess that message_begin_cb is called twice in one http steam.i am verifying that.

commented

The formatting messes up the source code, it is still very hard to get a grok of it.

i just take a example by test.c.

Superficially, it looks like //num_messages++; might be the culprit.

commented

num_messages

i don’t think so.i will zero num_messages when i call do_insight_http.

Well, you don't increment it so it should always stay zero regardless of what happens in do_insight_http.

commented

Well, you don't increment it so it should always stay zero regardless of what happens in do_insight_http.

but as you see,just zero num_messages and messages in do_insight_http. i have tried to define messages[2],but it looks like uesless. i will get this problem,though it is just very few times.

One TCP connection could be used for sending many HTTP requests. Are you sure that you are receiving just on request and not multiple?

commented

One TCP connection could be used for sending many HTTP requests. Are you sure that you are receiving just on request and not multiple?

i am not sure.so as i said that message_begin_cb might be called twice in one stream.i get data by libnids.so if there is new date in tcp connection,i will call do_insight_http.i cannot promise get just one request .

If you get two requests - message_begin_cb will be called twice too.

commented

One TCP connection could be used for sending many HTTP requests. Are you sure that you are receiving just on request and not multiple?
maybe i get your point.what you mean is i should defines messages as an array,so i can get mutiple request.that is right?

I'd say - yes!

commented

thanks a lot

You're welcome!