-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use re-use properly? #7
Comments
Got it working in a test by clearing the position- and length variables of diff --git a/httpc.c b/httpc.c
index bd0fcf9..c3b5506 100644
--- a/httpc.c
+++ b/httpc.c
@@ -1355,6 +1355,11 @@ static int httpc_op_heap(httpc_options_t *a, const char *url, int op, httpc_call
h->rcv_param = rcv_param;
h->snd_param = snd_param;
}
+
+ h->position = 0;
+ h->length = 0;
+ h->max = 0;
+ h->length_set = 0;
const int r = httpc_state_machine(h, url, op);
if (r != HTTPC_YIELD && r != HTTPC_REUSE)
a->state = NULL; /* make sure this is not reused */ Not sure if it's the correct approach though. Edit: I think the following will need the same re-assignment treatment, or a
|
I'll try to have a look at this once (if) I have time over the weekend, I should probably add some more unit tests to cover these new additions as well. |
I've found some more fields that would have to be moved. diff --git a/httpc.c b/httpc.c
index c7e6b79..cb103c9 100644
--- a/httpc.c
+++ b/httpc.c
@@ -1357,12 +1357,18 @@ static int httpc_op_heap(httpc_options_t *a, const char *url, int op, httpc_call
return HTTPC_ERROR;
memset(h, 0, sizeof *h);
a->state = h;
- h->os = a;
- h->rcv = rcv;
- h->snd = snd;
- h->rcv_param = rcv_param;
- h->snd_param = snd_param;
}
+
+ h->os = a;
+ h->rcv = rcv;
+ h->snd = snd;
+ h->rcv_param = rcv_param;
+ h->snd_param = snd_param;
+ h->position = 0;
+ h->length = 0;
+ h->max = 0;
+ h->length_set = 0;
+ h->state = SM_INIT;
const int r = httpc_state_machine(h, url, op);
if (r != HTTPC_YIELD && r != HTTPC_REUSE)
a->state = NULL; /* make sure this is not reused */ Two ways to reproduce when using persistent connections:
Note that this is assuming |
Yeah, that isn't going to work when the |
(sorry for the issue spam)
Do you have an example of how to do socket reuse properly? When I try it the first request seems to work fine:
Subsequent requests on the same client and socket seem to be thrown out of sync:
See provided sample file built with
gcc -o http_test -g http_test.c unix.c httpc.c -lssl
. I had to rename it to.txt
due to github.http_test.txt
The text was updated successfully, but these errors were encountered: