Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

when an outstream nukes stuff, stop doing stuff on the associated cli…

…ent/agent/both
  • Loading branch information...
commit c7fa58b162a6ce844e45b84d21eab80ed05ba630 1 parent 38b30d5
@thejh authored
Showing with 21 additions and 17 deletions.
  1. +13 −12 src/main.c
  2. +6 −3 src/outstream.c
  3. +2 −2 src/outstream.h
View
25 src/main.c
@@ -358,10 +358,9 @@ int on_server_headers_complete(http_parser *p) {
assert(b-buf == len);
free_headers(&a->response_headers);
- outstream_send(&a->client->outstream, buf, len);
-
free(status_str);
- return 0;
+
+ return outstream_send(&a->client->outstream, buf, len);
}
// XXX HOT CALLBACK! XXX
@@ -380,9 +379,7 @@ int on_server_body(http_parser *p, const char *data, size_t size) {
assert(size != 0);
chunkify(&d, &size, 0);
- outstream_send(&a->client->outstream, d, size);
-
- return 0;
+ return outstream_send(&a->client->outstream, d, size);
}
int on_server_message_complete(http_parser *p) {
@@ -392,7 +389,9 @@ int on_server_message_complete(http_parser *p) {
char *data = malloc(strlen(final_chunk));
memcpy(data, final_chunk, strlen(final_chunk));
- outstream_send(&a->client->outstream, data, strlen(final_chunk));
+ if (outstream_send(&a->client->outstream, data, strlen(final_chunk))) {
+ return 1;
+ }
// disassociate
printd("unbinding agent\n");
@@ -505,10 +504,12 @@ int on_client_headers_complete(http_parser *p) {
hostname[hostname_end - w->url - 7] = '\0';
if (bl_check(hostname) == 1) {
- outstream_send(&w->outstream, strdup(DENY_RESPONSE), strlen(DENY_RESPONSE));
#ifdef PRINT_URLS
printbuf("%s\n", w->url, w->url_size);
#endif
+ if (outstream_send(&w->outstream, strdup(DENY_RESPONSE), strlen(DENY_RESPONSE))) {
+ return 1;
+ }
w->parser_dontpause = 1;
return 0;
}
@@ -517,10 +518,12 @@ int on_client_headers_complete(http_parser *p) {
struct http_agent *agent = get_agent(hostname, w);
if (agent == NULL) {
// invalid hostname or so
- outstream_send(&w->outstream, strdup(INVAL_RESPONSE), strlen(INVAL_RESPONSE));
#ifdef PRINT_URLS
printbuf(" %s\n", w->url, w->url_size);
#endif
+ if (outstream_send(&w->outstream, strdup(INVAL_RESPONSE), strlen(INVAL_RESPONSE))) {
+ return 1;
+ }
w->parser_dontpause = 1;
return 0;
}
@@ -581,11 +584,9 @@ int on_client_headers_complete(http_parser *p) {
*(pos++) = '\0';
assert(pos - header_buffer == header_buffer_size);
printd("HEADER READY FOR SENDING: \n<<<<<<<<<<<<<<<<<<<<\n%s\n>>>>>>>>>>>>>>>>>>>>\n", header_buffer);
- outstream_send(&agent->outstream, header_buffer, header_buffer_size - 1 /* the nullbyte is for debugging only, stupid! */);
-
free_headers(&w->request_headers);
- return 0;
+ return outstream_send(&agent->outstream, header_buffer, header_buffer_size - 1 /* the nullbyte is for debugging only, stupid! */);
}
int on_client_body(http_parser *p, const char *data, size_t length) {
View
9 src/outstream.c
@@ -75,14 +75,15 @@ void outstream_nuke(struct outstream *s) {
ev_io_stop(ev_default_loop(0), &s->watcher);
}
-void outstream_send(struct outstream *s, char *buf, size_t len) {
+// 0 means success, 1 means failure
+int outstream_send(struct outstream *s, char *buf, size_t len) {
char *free_ptr = buf;
if (s->first_buf == NULL) {
ssize_t written = write(s->watcher.fd, buf, len);
if (written == -1 && errno != EAGAIN) {
- s->error_cb(s); return;
+ s->error_cb(s); return 1;
} else if (written == 0) {
- s->error_cb(s); return;
+ s->error_cb(s); return 1;
}
if (written == len) { free(buf); return; } // yaaay, no buffer magic needed!
@@ -108,4 +109,6 @@ void outstream_send(struct outstream *s, char *buf, size_t len) {
if (s->pressure >= OUTSTREAM_HIGH && s->pressure - len < OUTSTREAM_HIGH && s->input_watcher != NULL) {
alter_ev_io_events(s->input_watcher, 0, EV_READ);
}
+
+ return 0;
}
View
4 src/outstream.h
@@ -31,8 +31,8 @@ void outstream_init(struct outstream *s, int fd, void (*error_cb)(struct outstre
// Use this to add/remove backpressure.
void outstream_input_set(struct outstream *s, struct ev_io *input_watcher);
-// Takes responsibility for free()'ing buf.
-void outstream_send(struct outstream *s, char *buf, size_t len);
+// Takes responsibility for free()'ing buf. 0 means success, 1 means failure.
+int outstream_send(struct outstream *s, char *buf, size_t len);
void outstream_nuke(struct outstream *s);
Please sign in to comment.
Something went wrong with that request. Please try again.