Lines Matching refs:evcon
177 struct evhttp_connection *evcon);
179 struct evhttp_connection *evcon);
181 struct evhttp_connection *evcon);
182 static void evhttp_request_dispatch(struct evhttp_connection* evcon);
183 static void evhttp_read_firstline(struct evhttp_connection *evcon,
185 static void evhttp_read_header(struct evhttp_connection *evcon,
361 evhttp_write_buffer(struct evhttp_connection *evcon, in evhttp_write_buffer() argument
367 evcon->cb = cb; in evhttp_write_buffer()
368 evcon->cb_arg = arg; in evhttp_write_buffer()
373 bufferevent_setcb(evcon->bufev, in evhttp_write_buffer()
377 evcon); in evhttp_write_buffer()
379 bufferevent_enable(evcon->bufev, EV_WRITE); in evhttp_write_buffer()
383 evhttp_send_continue_done(struct evhttp_connection *evcon, void *arg) in evhttp_send_continue_done() argument
385 bufferevent_disable(evcon->bufev, EV_WRITE); in evhttp_send_continue_done()
389 evhttp_send_continue(struct evhttp_connection *evcon, in evhttp_send_continue() argument
392 bufferevent_enable(evcon->bufev, EV_WRITE); in evhttp_send_continue()
393 evbuffer_add_printf(bufferevent_get_output(evcon->bufev), in evhttp_send_continue()
396 evcon->cb = evhttp_send_continue_done; in evhttp_send_continue()
397 evcon->cb_arg = NULL; in evhttp_send_continue()
398 bufferevent_setcb(evcon->bufev, in evhttp_send_continue()
402 evcon); in evhttp_send_continue()
407 evhttp_connected(struct evhttp_connection *evcon) in evhttp_connected() argument
409 switch (evcon->state) { in evhttp_connected()
429 evhttp_make_header_request(struct evhttp_connection *evcon, in evhttp_make_header_request() argument
441 evbuffer_add_printf(bufferevent_get_output(evcon->bufev), in evhttp_make_header_request()
519 evhttp_make_header_response(struct evhttp_connection *evcon, in evhttp_make_header_response() argument
523 evbuffer_add_printf(bufferevent_get_output(evcon->bufev), in evhttp_make_header_response()
557 && evcon->http_server->default_content_type) { in evhttp_make_header_response()
560 evcon->http_server->default_content_type); in evhttp_make_header_response()
594 evhttp_make_header(struct evhttp_connection *evcon, struct evhttp_request *req) in evhttp_make_header() argument
597 struct evbuffer *output = bufferevent_get_output(evcon->bufev); in evhttp_make_header()
604 evhttp_make_header_request(evcon, req); in evhttp_make_header()
606 evhttp_make_header_response(evcon, req); in evhttp_make_header()
626 evhttp_connection_set_max_headers_size(struct evhttp_connection *evcon, in evhttp_connection_set_max_headers_size() argument
630 evcon->max_headers_size = EV_SIZE_MAX; in evhttp_connection_set_max_headers_size()
632 evcon->max_headers_size = new_max_headers_size; in evhttp_connection_set_max_headers_size()
635 evhttp_connection_set_max_body_size(struct evhttp_connection* evcon, in evhttp_connection_set_max_body_size() argument
639 evcon->max_body_size = EV_UINT64_MAX; in evhttp_connection_set_max_body_size()
641 evcon->max_body_size = new_max_body_size; in evhttp_connection_set_max_body_size()
669 TAILQ_REMOVE(&req->evcon->requests, req, next); in evhttp_connection_incoming_fail()
673 req->evcon = NULL; in evhttp_connection_incoming_fail()
711 evhttp_request_free_(struct evhttp_connection *evcon, struct evhttp_request *req) in evhttp_request_free_() argument
713 TAILQ_REMOVE(&evcon->requests, req, next); in evhttp_request_free_()
722 evhttp_connection_fail_(struct evhttp_connection *evcon, in evhttp_connection_fail_() argument
726 struct evhttp_request* req = TAILQ_FIRST(&evcon->requests); in evhttp_connection_fail_()
733 bufferevent_disable(evcon->bufev, EV_READ|EV_WRITE); in evhttp_connection_fail_()
735 if (evcon->flags & EVHTTP_CON_INCOMING) { in evhttp_connection_fail_()
745 evhttp_connection_free(evcon); in evhttp_connection_fail_()
765 evhttp_request_free_(evcon, req); in evhttp_connection_fail_()
768 evhttp_connection_reset_(evcon); in evhttp_connection_fail_()
771 if (TAILQ_FIRST(&evcon->requests) != NULL) in evhttp_connection_fail_()
772 evhttp_connection_connect_(evcon); in evhttp_connection_fail_()
792 struct evhttp_connection *evcon = arg; in evhttp_write_cb() local
795 if (evcon->cb != NULL) in evhttp_write_cb()
796 (*evcon->cb)(evcon, evcon->cb_arg); in evhttp_write_cb()
807 evhttp_connection_done(struct evhttp_connection *evcon) in evhttp_connection_done() argument
809 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); in evhttp_connection_done()
810 int con_outgoing = evcon->flags & EVHTTP_CON_OUTGOING; in evhttp_connection_done()
816 TAILQ_REMOVE(&evcon->requests, req, next); in evhttp_connection_done()
817 req->evcon = NULL; in evhttp_connection_done()
819 evcon->state = EVCON_IDLE; in evhttp_connection_done()
823 evhttp_connection_reset_(evcon); in evhttp_connection_done()
825 if (TAILQ_FIRST(&evcon->requests) != NULL) { in evhttp_connection_done()
830 if (!evhttp_connected(evcon)) in evhttp_connection_done()
831 evhttp_connection_connect_(evcon); in evhttp_connection_done()
833 evhttp_request_dispatch(evcon); in evhttp_connection_done()
839 evhttp_connection_start_detectclose(evcon); in evhttp_connection_done()
840 } else if ((evcon->flags & EVHTTP_CON_AUTOFREE)) { in evhttp_connection_done()
852 evcon->state = EVCON_WRITING; in evhttp_connection_done()
869 if (free_evcon && TAILQ_FIRST(&evcon->requests) == NULL) { in evhttp_connection_done()
870 evhttp_connection_free(evcon); in evhttp_connection_done()
936 if (req->body_size + (size_t)ntoread > req->evcon->max_body_size) { in evhttp_handle_chunked_read()
980 evhttp_read_trailer(struct evhttp_connection *evcon, struct evhttp_request *req) in evhttp_read_trailer() argument
982 struct evbuffer *buf = bufferevent_get_input(evcon->bufev); in evhttp_read_trailer()
987 evhttp_connection_fail_(evcon, EVREQ_HTTP_DATA_TOO_LONG); in evhttp_read_trailer()
990 bufferevent_disable(evcon->bufev, EV_READ); in evhttp_read_trailer()
991 evhttp_connection_done(evcon); in evhttp_read_trailer()
1001 evhttp_lingering_close(struct evhttp_connection *evcon, in evhttp_lingering_close() argument
1004 struct evbuffer *buf = bufferevent_get_input(evcon->bufev); in evhttp_lingering_close()
1017 evhttp_connection_fail_(evcon, EVREQ_HTTP_DATA_TOO_LONG); in evhttp_lingering_close()
1020 evhttp_lingering_fail(struct evhttp_connection *evcon, in evhttp_lingering_fail() argument
1023 if (evcon->flags & EVHTTP_CON_LINGERING_CLOSE) in evhttp_lingering_fail()
1024 evhttp_lingering_close(evcon, req); in evhttp_lingering_fail()
1026 evhttp_connection_fail_(evcon, EVREQ_HTTP_DATA_TOO_LONG); in evhttp_lingering_fail()
1030 evhttp_read_body(struct evhttp_connection *evcon, struct evhttp_request *req) in evhttp_read_body() argument
1032 struct evbuffer *buf = bufferevent_get_input(evcon->bufev); in evhttp_read_body()
1038 evcon->state = EVCON_READING_TRAILER; in evhttp_read_body()
1039 evhttp_read_trailer(evcon, req); in evhttp_read_body()
1044 evhttp_connection_fail_(evcon, in evhttp_read_body()
1058 evhttp_connection_fail_(evcon, EVREQ_HTTP_INVALID_HEADER); in evhttp_read_body()
1077 if (req->body_size > req->evcon->max_body_size || in evhttp_read_body()
1079 (size_t)req->ntoread > req->evcon->max_body_size)) { in evhttp_read_body()
1083 evhttp_lingering_fail(evcon, req); in evhttp_read_body()
1100 bufferevent_disable(evcon->bufev, EV_READ); in evhttp_read_body()
1102 evhttp_connection_done(evcon); in evhttp_read_body()
1107 #define get_deferred_queue(evcon) \ argument
1108 ((evcon)->base)
1117 struct evhttp_connection *evcon = arg; in evhttp_read_cb() local
1118 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); in evhttp_read_cb()
1121 event_deferred_cb_cancel_(get_deferred_queue(evcon), in evhttp_read_cb()
1122 &evcon->read_more_deferred_cb); in evhttp_read_cb()
1124 switch (evcon->state) { in evhttp_read_cb()
1126 evhttp_read_firstline(evcon, req); in evhttp_read_cb()
1131 evhttp_read_header(evcon, req); in evhttp_read_cb()
1136 evhttp_read_body(evcon, req); in evhttp_read_cb()
1141 evhttp_read_trailer(evcon, req); in evhttp_read_cb()
1149 input = bufferevent_get_input(evcon->bufev); in evhttp_read_cb()
1157 evhttp_connection_reset_(evcon); in evhttp_read_cb()
1165 __func__, evcon->state); in evhttp_read_cb()
1172 struct evhttp_connection *evcon = data; in evhttp_deferred_read_cb() local
1173 evhttp_read_cb(evcon->bufev, evcon); in evhttp_deferred_read_cb()
1177 evhttp_write_connectioncb(struct evhttp_connection *evcon, void *arg) in evhttp_write_connectioncb() argument
1180 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); in evhttp_write_connectioncb()
1181 struct evbuffer *output = bufferevent_get_output(evcon->bufev); in evhttp_write_connectioncb()
1184 EVUTIL_ASSERT(evcon->state == EVCON_WRITING); in evhttp_write_connectioncb()
1194 evhttp_start_read_(evcon); in evhttp_write_connectioncb()
1202 evhttp_connection_free(struct evhttp_connection *evcon) in evhttp_connection_free() argument
1207 if (evcon->fd != -1) { in evhttp_connection_free()
1208 if (evhttp_connected(evcon) && evcon->closecb != NULL) in evhttp_connection_free()
1209 (*evcon->closecb)(evcon, evcon->closecb_arg); in evhttp_connection_free()
1217 while ((req = TAILQ_FIRST(&evcon->requests)) != NULL) { in evhttp_connection_free()
1218 evhttp_request_free_(evcon, req); in evhttp_connection_free()
1221 if (evcon->http_server != NULL) { in evhttp_connection_free()
1222 struct evhttp *http = evcon->http_server; in evhttp_connection_free()
1223 TAILQ_REMOVE(&http->connections, evcon, next); in evhttp_connection_free()
1226 if (event_initialized(&evcon->retry_ev)) { in evhttp_connection_free()
1227 event_del(&evcon->retry_ev); in evhttp_connection_free()
1228 event_debug_unassign(&evcon->retry_ev); in evhttp_connection_free()
1231 if (evcon->bufev != NULL) in evhttp_connection_free()
1232 bufferevent_free(evcon->bufev); in evhttp_connection_free()
1234 event_deferred_cb_cancel_(get_deferred_queue(evcon), in evhttp_connection_free()
1235 &evcon->read_more_deferred_cb); in evhttp_connection_free()
1237 if (evcon->fd == -1) in evhttp_connection_free()
1238 evcon->fd = bufferevent_getfd(evcon->bufev); in evhttp_connection_free()
1240 if (evcon->fd != -1) { in evhttp_connection_free()
1241 bufferevent_disable(evcon->bufev, EV_READ|EV_WRITE); in evhttp_connection_free()
1242 shutdown(evcon->fd, EVUTIL_SHUT_WR); in evhttp_connection_free()
1243 if (!(bufferevent_get_options_(evcon->bufev) & BEV_OPT_CLOSE_ON_FREE)) { in evhttp_connection_free()
1244 evutil_closesocket(evcon->fd); in evhttp_connection_free()
1248 if (evcon->bind_address != NULL) in evhttp_connection_free()
1249 mm_free(evcon->bind_address); in evhttp_connection_free()
1251 if (evcon->address != NULL) in evhttp_connection_free()
1252 mm_free(evcon->address); in evhttp_connection_free()
1254 mm_free(evcon); in evhttp_connection_free()
1258 evhttp_connection_free_on_completion(struct evhttp_connection *evcon) { in evhttp_connection_free_on_completion() argument
1259 evcon->flags |= EVHTTP_CON_AUTOFREE; in evhttp_connection_free_on_completion()
1263 evhttp_connection_set_local_address(struct evhttp_connection *evcon, in evhttp_connection_set_local_address() argument
1266 EVUTIL_ASSERT(evcon->state == EVCON_DISCONNECTED); in evhttp_connection_set_local_address()
1267 if (evcon->bind_address) in evhttp_connection_set_local_address()
1268 mm_free(evcon->bind_address); in evhttp_connection_set_local_address()
1269 if ((evcon->bind_address = mm_strdup(address)) == NULL) in evhttp_connection_set_local_address()
1274 evhttp_connection_set_local_port(struct evhttp_connection *evcon, in evhttp_connection_set_local_port() argument
1277 EVUTIL_ASSERT(evcon->state == EVCON_DISCONNECTED); in evhttp_connection_set_local_port()
1278 evcon->bind_port = port; in evhttp_connection_set_local_port()
1282 evhttp_request_dispatch(struct evhttp_connection* evcon) in evhttp_request_dispatch() argument
1284 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); in evhttp_request_dispatch()
1291 evhttp_connection_stop_detectclose(evcon); in evhttp_request_dispatch()
1294 EVUTIL_ASSERT(evcon->state == EVCON_IDLE); in evhttp_request_dispatch()
1296 evcon->state = EVCON_WRITING; in evhttp_request_dispatch()
1299 evhttp_make_header(evcon, req); in evhttp_request_dispatch()
1301 evhttp_write_buffer(evcon, evhttp_write_connectioncb, NULL); in evhttp_request_dispatch()
1307 evhttp_connection_reset_(struct evhttp_connection *evcon) in evhttp_connection_reset_() argument
1323 bufferevent_disable_hard_(evcon->bufev, EV_READ|EV_WRITE); in evhttp_connection_reset_()
1325 if (evcon->fd == -1) in evhttp_connection_reset_()
1326 evcon->fd = bufferevent_getfd(evcon->bufev); in evhttp_connection_reset_()
1328 if (evcon->fd != -1) { in evhttp_connection_reset_()
1330 if (evhttp_connected(evcon) && evcon->closecb != NULL) in evhttp_connection_reset_()
1331 (*evcon->closecb)(evcon, evcon->closecb_arg); in evhttp_connection_reset_()
1333 shutdown(evcon->fd, EVUTIL_SHUT_WR); in evhttp_connection_reset_()
1334 evutil_closesocket(evcon->fd); in evhttp_connection_reset_()
1335 evcon->fd = -1; in evhttp_connection_reset_()
1337 bufferevent_setfd(evcon->bufev, -1); in evhttp_connection_reset_()
1340 tmp = bufferevent_get_output(evcon->bufev); in evhttp_connection_reset_()
1343 tmp = bufferevent_get_input(evcon->bufev); in evhttp_connection_reset_()
1347 evcon->flags &= ~EVHTTP_CON_READING_ERROR; in evhttp_connection_reset_()
1349 evcon->state = EVCON_DISCONNECTED; in evhttp_connection_reset_()
1353 evhttp_connection_start_detectclose(struct evhttp_connection *evcon) in evhttp_connection_start_detectclose() argument
1355 evcon->flags |= EVHTTP_CON_CLOSEDETECT; in evhttp_connection_start_detectclose()
1357 bufferevent_enable(evcon->bufev, EV_READ); in evhttp_connection_start_detectclose()
1361 evhttp_connection_stop_detectclose(struct evhttp_connection *evcon) in evhttp_connection_stop_detectclose() argument
1363 evcon->flags &= ~EVHTTP_CON_CLOSEDETECT; in evhttp_connection_stop_detectclose()
1365 bufferevent_disable(evcon->bufev, EV_READ); in evhttp_connection_stop_detectclose()
1371 struct evhttp_connection *evcon = arg; in evhttp_connection_retry() local
1373 evcon->state = EVCON_DISCONNECTED; in evhttp_connection_retry()
1374 evhttp_connection_connect_(evcon); in evhttp_connection_retry()
1378 evhttp_connection_cb_cleanup(struct evhttp_connection *evcon) in evhttp_connection_cb_cleanup() argument
1382 evhttp_connection_reset_(evcon); in evhttp_connection_cb_cleanup()
1383 if (evcon->retry_max < 0 || evcon->retry_cnt < evcon->retry_max) { in evhttp_connection_cb_cleanup()
1384 struct timeval tv_retry = evcon->initial_retry_timeout; in evhttp_connection_cb_cleanup()
1386 evtimer_assign(&evcon->retry_ev, evcon->base, evhttp_connection_retry, evcon); in evhttp_connection_cb_cleanup()
1388 for (i=0; i < evcon->retry_cnt; ++i) { in evhttp_connection_cb_cleanup()
1400 event_add(&evcon->retry_ev, &tv_retry); in evhttp_connection_cb_cleanup()
1401 evcon->retry_cnt++; in evhttp_connection_cb_cleanup()
1412 while (TAILQ_FIRST(&evcon->requests) != NULL) { in evhttp_connection_cb_cleanup()
1413 struct evhttp_request *request = TAILQ_FIRST(&evcon->requests); in evhttp_connection_cb_cleanup()
1414 TAILQ_REMOVE(&evcon->requests, request, next); in evhttp_connection_cb_cleanup()
1422 request->evcon = NULL; in evhttp_connection_cb_cleanup()
1431 evhttp_connection_read_on_write_error(struct evhttp_connection *evcon, in evhttp_connection_read_on_write_error() argument
1437 if (evcon->flags & EVHTTP_CON_READING_ERROR) { in evhttp_connection_read_on_write_error()
1438 evcon->flags &= ~EVHTTP_CON_READING_ERROR; in evhttp_connection_read_on_write_error()
1439 evhttp_connection_fail_(evcon, EVREQ_HTTP_EOF); in evhttp_connection_read_on_write_error()
1445 buf = bufferevent_get_output(evcon->bufev); in evhttp_connection_read_on_write_error()
1450 evhttp_start_read_(evcon); in evhttp_connection_read_on_write_error()
1451 evcon->flags |= EVHTTP_CON_READING_ERROR; in evhttp_connection_read_on_write_error()
1457 struct evhttp_connection *evcon = arg; in evhttp_error_cb() local
1458 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); in evhttp_error_cb()
1460 if (evcon->fd == -1) in evhttp_error_cb()
1461 evcon->fd = bufferevent_getfd(bufev); in evhttp_error_cb()
1463 switch (evcon->state) { in evhttp_error_cb()
1468 __func__, evcon->address, evcon->port, in evhttp_error_cb()
1469 EV_SOCK_ARG(evcon->fd))); in evhttp_error_cb()
1470 evhttp_connection_cb_cleanup(evcon); in evhttp_error_cb()
1479 evhttp_connection_done(evcon); in evhttp_error_cb()
1497 if (evcon->flags & EVHTTP_CON_CLOSEDETECT) { in evhttp_error_cb()
1498 evcon->flags &= ~EVHTTP_CON_CLOSEDETECT; in evhttp_error_cb()
1499 EVUTIL_ASSERT(evcon->http_server == NULL); in evhttp_error_cb()
1504 EVUTIL_ASSERT(evcon->state == EVCON_IDLE); in evhttp_error_cb()
1505 evhttp_connection_reset_(evcon); in evhttp_error_cb()
1512 if (TAILQ_FIRST(&evcon->requests) == NULL in evhttp_error_cb()
1513 && (evcon->flags & EVHTTP_CON_OUTGOING) in evhttp_error_cb()
1514 && (evcon->flags & EVHTTP_CON_AUTOFREE)) { in evhttp_error_cb()
1515 evhttp_connection_free(evcon); in evhttp_error_cb()
1521 evhttp_connection_fail_(evcon, EVREQ_HTTP_TIMEOUT); in evhttp_error_cb()
1524 evcon->flags & EVHTTP_CON_READ_ON_WRITE_ERROR) { in evhttp_error_cb()
1525 evhttp_connection_read_on_write_error(evcon, req); in evhttp_error_cb()
1529 evhttp_connection_fail_(evcon, EVREQ_HTTP_EOF); in evhttp_error_cb()
1532 evhttp_connection_fail_(evcon, EVREQ_HTTP_BUFFER_ERROR); in evhttp_error_cb()
1542 struct evhttp_connection *evcon = arg; in evhttp_connection_cb() local
1546 if (evcon->fd == -1) in evhttp_connection_cb()
1547 evcon->fd = bufferevent_getfd(bufev); in evhttp_connection_cb()
1562 if (evcon->fd == -1) { in evhttp_connection_cb()
1569 if (getsockopt(evcon->fd, SOL_SOCKET, SO_ERROR, (void*)&error, in evhttp_connection_cb()
1572 __func__, evcon->address, evcon->port, in evhttp_connection_cb()
1573 EV_SOCK_ARG(evcon->fd))); in evhttp_connection_cb()
1580 __func__, evcon->address, evcon->port, in evhttp_connection_cb()
1581 EV_SOCK_ARG(evcon->fd), in evhttp_connection_cb()
1588 __func__, evcon->address, evcon->port, in evhttp_connection_cb()
1589 EV_SOCK_ARG(evcon->fd))); in evhttp_connection_cb()
1592 evcon->retry_cnt = 0; in evhttp_connection_cb()
1593 evcon->state = EVCON_IDLE; in evhttp_connection_cb()
1596 bufferevent_setcb(evcon->bufev, in evhttp_connection_cb()
1600 evcon); in evhttp_connection_cb()
1602 if (!evutil_timerisset(&evcon->timeout)) { in evhttp_connection_cb()
1605 bufferevent_set_timeouts(evcon->bufev, &read_tv, &write_tv); in evhttp_connection_cb()
1607 bufferevent_set_timeouts(evcon->bufev, &evcon->timeout, &evcon->timeout); in evhttp_connection_cb()
1611 evhttp_request_dispatch(evcon); in evhttp_connection_cb()
1615 evhttp_connection_cb_cleanup(evcon); in evhttp_connection_cb()
1845 !evhttp_find_vhost(req->evcon->http_server, NULL, hostname)) in evhttp_parse_request_line()
1987 if (req->evcon != NULL && in evhttp_parse_firstline_()
1988 evbuffer_get_length(buffer) > req->evcon->max_headers_size) in evhttp_parse_firstline_()
1994 if (req->evcon != NULL && in evhttp_parse_firstline_()
1995 line_length > req->evcon->max_headers_size) { in evhttp_parse_firstline_()
2064 if (req->evcon != NULL && in evhttp_parse_headers_()
2065 req->headers_size > req->evcon->max_headers_size) { in evhttp_parse_headers_()
2100 if (req->evcon != NULL && in evhttp_parse_headers_()
2101 req->headers_size + evbuffer_get_length(buffer) > req->evcon->max_headers_size) in evhttp_parse_headers_()
2146 EV_SIZE_ARG(evbuffer_get_length(bufferevent_get_input(req->evcon->bufev))))); in evhttp_get_body_length()
2174 evhttp_get_body(struct evhttp_connection *evcon, struct evhttp_request *req) in evhttp_get_body() argument
2181 evhttp_connection_done(evcon); in evhttp_get_body()
2184 evcon->state = EVCON_READING_BODY; in evhttp_get_body()
2191 evhttp_connection_fail_(evcon, EVREQ_HTTP_INVALID_HEADER); in evhttp_get_body()
2197 evhttp_connection_done(evcon); in evhttp_get_body()
2213 if ((req->evcon->max_body_size <= EV_INT64_MAX) && in evhttp_get_body()
2214 (ev_uint64_t)req->ntoread > req->evcon->max_body_size) { in evhttp_get_body()
2215 evhttp_lingering_fail(evcon, req); in evhttp_get_body()
2219 if (!evbuffer_get_length(bufferevent_get_input(evcon->bufev))) in evhttp_get_body()
2220 evhttp_send_continue(evcon, req); in evhttp_get_body()
2228 evhttp_read_body(evcon, req); in evhttp_get_body()
2233 evhttp_read_firstline(struct evhttp_connection *evcon, in evhttp_read_firstline() argument
2238 res = evhttp_parse_firstline_(req, bufferevent_get_input(evcon->bufev)); in evhttp_read_firstline()
2242 __func__, EV_SOCK_ARG(evcon->fd))); in evhttp_read_firstline()
2243 evhttp_connection_fail_(evcon, EVREQ_HTTP_INVALID_HEADER); in evhttp_read_firstline()
2250 evcon->state = EVCON_READING_HEADERS; in evhttp_read_firstline()
2251 evhttp_read_header(evcon, req); in evhttp_read_firstline()
2255 evhttp_read_header(struct evhttp_connection *evcon, in evhttp_read_header() argument
2259 evutil_socket_t fd = evcon->fd; in evhttp_read_header()
2261 res = evhttp_parse_headers_(req, bufferevent_get_input(evcon->bufev)); in evhttp_read_header()
2266 evhttp_connection_fail_(evcon, EVREQ_HTTP_INVALID_HEADER); in evhttp_read_header()
2276 evhttp_connection_fail_(evcon, EVREQ_HTTP_EOF); in evhttp_read_header()
2286 evhttp_get_body(evcon, req); in evhttp_read_header()
2293 struct evbuffer *output = bufferevent_get_output(evcon->bufev); in evhttp_read_header()
2295 evhttp_start_write_(evcon); in evhttp_read_header()
2301 evhttp_connection_done(evcon); in evhttp_read_header()
2306 evhttp_get_body(evcon, req); in evhttp_read_header()
2315 evhttp_connection_fail_(evcon, EVREQ_HTTP_INVALID_HEADER); in evhttp_read_header()
2341 struct evhttp_connection *evcon = NULL; in evhttp_connection_base_bufferevent_new() local
2345 if ((evcon = mm_calloc(1, sizeof(struct evhttp_connection))) == NULL) { in evhttp_connection_base_bufferevent_new()
2350 evcon->fd = -1; in evhttp_connection_base_bufferevent_new()
2351 evcon->port = port; in evhttp_connection_base_bufferevent_new()
2353 evcon->max_headers_size = EV_SIZE_MAX; in evhttp_connection_base_bufferevent_new()
2354 evcon->max_body_size = EV_SIZE_MAX; in evhttp_connection_base_bufferevent_new()
2356 evutil_timerclear(&evcon->timeout); in evhttp_connection_base_bufferevent_new()
2357 evcon->retry_cnt = evcon->retry_max = 0; in evhttp_connection_base_bufferevent_new()
2359 if ((evcon->address = mm_strdup(address)) == NULL) { in evhttp_connection_base_bufferevent_new()
2371 bufferevent_setcb(bev, evhttp_read_cb, evhttp_write_cb, evhttp_error_cb, evcon); in evhttp_connection_base_bufferevent_new()
2372 evcon->bufev = bev; in evhttp_connection_base_bufferevent_new()
2374 evcon->state = EVCON_DISCONNECTED; in evhttp_connection_base_bufferevent_new()
2375 TAILQ_INIT(&evcon->requests); in evhttp_connection_base_bufferevent_new()
2377 evcon->initial_retry_timeout.tv_sec = 2; in evhttp_connection_base_bufferevent_new()
2378 evcon->initial_retry_timeout.tv_usec = 0; in evhttp_connection_base_bufferevent_new()
2381 evcon->base = base; in evhttp_connection_base_bufferevent_new()
2383 bufferevent_base_set(base, evcon->bufev); in evhttp_connection_base_bufferevent_new()
2387 &evcon->read_more_deferred_cb, in evhttp_connection_base_bufferevent_new()
2389 evhttp_deferred_read_cb, evcon); in evhttp_connection_base_bufferevent_new()
2391 evcon->dns_base = dnsbase; in evhttp_connection_base_bufferevent_new()
2392 evcon->ai_family = AF_UNSPEC; in evhttp_connection_base_bufferevent_new()
2394 return (evcon); in evhttp_connection_base_bufferevent_new()
2397 if (evcon != NULL) in evhttp_connection_base_bufferevent_new()
2398 evhttp_connection_free(evcon); in evhttp_connection_base_bufferevent_new()
2402 struct bufferevent* evhttp_connection_get_bufferevent(struct evhttp_connection *evcon) in evhttp_connection_get_bufferevent() argument
2404 return evcon->bufev; in evhttp_connection_get_bufferevent()
2408 evhttp_connection_get_server(struct evhttp_connection *evcon) in evhttp_connection_get_server() argument
2410 return evcon->http_server; in evhttp_connection_get_server()
2420 void evhttp_connection_set_family(struct evhttp_connection *evcon, in evhttp_connection_set_family() argument
2423 evcon->ai_family = family; in evhttp_connection_set_family()
2426 int evhttp_connection_set_flags(struct evhttp_connection *evcon, in evhttp_connection_set_flags() argument
2435 evcon->flags &= ~avail_flags; in evhttp_connection_set_flags()
2437 evcon->flags |= flags; in evhttp_connection_set_flags()
2443 evhttp_connection_set_base(struct evhttp_connection *evcon, in evhttp_connection_set_base() argument
2446 EVUTIL_ASSERT(evcon->base == NULL); in evhttp_connection_set_base()
2447 EVUTIL_ASSERT(evcon->state == EVCON_DISCONNECTED); in evhttp_connection_set_base()
2448 evcon->base = base; in evhttp_connection_set_base()
2449 bufferevent_base_set(base, evcon->bufev); in evhttp_connection_set_base()
2453 evhttp_connection_set_timeout(struct evhttp_connection *evcon, in evhttp_connection_set_timeout() argument
2457 evhttp_connection_set_timeout_tv(evcon, NULL); in evhttp_connection_set_timeout()
2462 evhttp_connection_set_timeout_tv(evcon, &tv); in evhttp_connection_set_timeout()
2467 evhttp_connection_set_timeout_tv(struct evhttp_connection *evcon, in evhttp_connection_set_timeout_tv() argument
2471 evcon->timeout = *tv; in evhttp_connection_set_timeout_tv()
2472 bufferevent_set_timeouts(evcon->bufev, &evcon->timeout, &evcon->timeout); in evhttp_connection_set_timeout_tv()
2476 evutil_timerclear(&evcon->timeout); in evhttp_connection_set_timeout_tv()
2477 bufferevent_set_timeouts(evcon->bufev, &read_tv, &write_tv); in evhttp_connection_set_timeout_tv()
2482 evhttp_connection_set_initial_retry_tv(struct evhttp_connection *evcon, in evhttp_connection_set_initial_retry_tv() argument
2486 evcon->initial_retry_timeout = *tv; in evhttp_connection_set_initial_retry_tv()
2488 evutil_timerclear(&evcon->initial_retry_timeout); in evhttp_connection_set_initial_retry_tv()
2489 evcon->initial_retry_timeout.tv_sec = 2; in evhttp_connection_set_initial_retry_tv()
2494 evhttp_connection_set_retries(struct evhttp_connection *evcon, in evhttp_connection_set_retries() argument
2497 evcon->retry_max = retry_max; in evhttp_connection_set_retries()
2501 evhttp_connection_set_closecb(struct evhttp_connection *evcon, in evhttp_connection_set_closecb() argument
2504 evcon->closecb = cb; in evhttp_connection_set_closecb()
2505 evcon->closecb_arg = cbarg; in evhttp_connection_set_closecb()
2509 evhttp_connection_get_peer(struct evhttp_connection *evcon, in evhttp_connection_get_peer() argument
2512 *address = evcon->address; in evhttp_connection_get_peer()
2513 *port = evcon->port; in evhttp_connection_get_peer()
2517 evhttp_connection_get_addr(struct evhttp_connection *evcon) in evhttp_connection_get_addr() argument
2519 return bufferevent_socket_get_conn_address_(evcon->bufev); in evhttp_connection_get_addr()
2523 evhttp_connection_connect_(struct evhttp_connection *evcon) in evhttp_connection_connect_() argument
2525 int old_state = evcon->state; in evhttp_connection_connect_()
2526 const char *address = evcon->address; in evhttp_connection_connect_()
2527 const struct sockaddr *sa = evhttp_connection_get_addr(evcon); in evhttp_connection_connect_()
2530 if (evcon->state == EVCON_CONNECTING) in evhttp_connection_connect_()
2533 evhttp_connection_reset_(evcon); in evhttp_connection_connect_()
2535 EVUTIL_ASSERT(!(evcon->flags & EVHTTP_CON_INCOMING)); in evhttp_connection_connect_()
2536 evcon->flags |= EVHTTP_CON_OUTGOING; in evhttp_connection_connect_()
2538 if (evcon->bind_address || evcon->bind_port) { in evhttp_connection_connect_()
2539 evcon->fd = bind_socket( in evhttp_connection_connect_()
2540 evcon->bind_address, evcon->bind_port, 0 /*reuse*/); in evhttp_connection_connect_()
2541 if (evcon->fd == -1) { in evhttp_connection_connect_()
2543 __func__, evcon->bind_address)); in evhttp_connection_connect_()
2547 bufferevent_setfd(evcon->bufev, evcon->fd); in evhttp_connection_connect_()
2549 bufferevent_setfd(evcon->bufev, -1); in evhttp_connection_connect_()
2553 bufferevent_setcb(evcon->bufev, in evhttp_connection_connect_()
2557 evcon); in evhttp_connection_connect_()
2558 if (!evutil_timerisset(&evcon->timeout)) { in evhttp_connection_connect_()
2560 bufferevent_set_timeouts(evcon->bufev, &conn_tv, &conn_tv); in evhttp_connection_connect_()
2562 bufferevent_set_timeouts(evcon->bufev, &evcon->timeout, &evcon->timeout); in evhttp_connection_connect_()
2565 bufferevent_enable(evcon->bufev, EV_WRITE); in evhttp_connection_connect_()
2567 evcon->state = EVCON_CONNECTING; in evhttp_connection_connect_()
2569 if (evcon->flags & EVHTTP_CON_REUSE_CONNECTED_ADDR && in evhttp_connection_connect_()
2576 ret = bufferevent_socket_connect(evcon->bufev, sa, socklen); in evhttp_connection_connect_()
2578 ret = bufferevent_socket_connect_hostname(evcon->bufev, in evhttp_connection_connect_()
2579 evcon->dns_base, evcon->ai_family, address, evcon->port); in evhttp_connection_connect_()
2583 evcon->state = old_state; in evhttp_connection_connect_()
2584 event_sock_warn(evcon->fd, "%s: connection to \"%s\" failed", in evhttp_connection_connect_()
2585 __func__, evcon->address); in evhttp_connection_connect_()
2590 evhttp_connection_cb_cleanup(evcon); in evhttp_connection_connect_()
2604 evhttp_make_request(struct evhttp_connection *evcon, in evhttp_make_request() argument
2625 EVUTIL_ASSERT(req->evcon == NULL); in evhttp_make_request()
2626 req->evcon = evcon; in evhttp_make_request()
2629 TAILQ_INSERT_TAIL(&evcon->requests, req, next); in evhttp_make_request()
2632 if (!evhttp_connected(evcon)) { in evhttp_make_request()
2633 int res = evhttp_connection_connect_(evcon); in evhttp_make_request()
2639 TAILQ_REMOVE(&evcon->requests, req, next); in evhttp_make_request()
2649 if (TAILQ_FIRST(&evcon->requests) == req) in evhttp_make_request()
2650 evhttp_request_dispatch(evcon); in evhttp_make_request()
2658 struct evhttp_connection *evcon = req->evcon; in evhttp_cancel_request() local
2659 if (evcon != NULL) { in evhttp_cancel_request()
2661 if (TAILQ_FIRST(&evcon->requests) == req) { in evhttp_cancel_request()
2665 evhttp_connection_fail_(evcon, in evhttp_cancel_request()
2674 TAILQ_REMOVE(&evcon->requests, req, next); in evhttp_cancel_request()
2687 evhttp_start_read_(struct evhttp_connection *evcon) in evhttp_start_read_() argument
2689 bufferevent_disable(evcon->bufev, EV_WRITE); in evhttp_start_read_()
2690 bufferevent_enable(evcon->bufev, EV_READ); in evhttp_start_read_()
2692 evcon->state = EVCON_READING_FIRSTLINE; in evhttp_start_read_()
2694 bufferevent_setcb(evcon->bufev, in evhttp_start_read_()
2698 evcon); in evhttp_start_read_()
2702 if (evbuffer_get_length(bufferevent_get_input(evcon->bufev))) { in evhttp_start_read_()
2703 event_deferred_cb_schedule_(get_deferred_queue(evcon), in evhttp_start_read_()
2704 &evcon->read_more_deferred_cb); in evhttp_start_read_()
2709 evhttp_start_write_(struct evhttp_connection *evcon) in evhttp_start_write_() argument
2711 bufferevent_disable(evcon->bufev, EV_WRITE); in evhttp_start_write_()
2712 bufferevent_enable(evcon->bufev, EV_READ); in evhttp_start_write_()
2714 evcon->state = EVCON_WRITING; in evhttp_start_write_()
2715 evhttp_write_buffer(evcon, evhttp_write_connectioncb, NULL); in evhttp_start_write_()
2719 evhttp_send_done(struct evhttp_connection *evcon, void *arg) in evhttp_send_done() argument
2722 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); in evhttp_send_done()
2723 TAILQ_REMOVE(&evcon->requests, req, next); in evhttp_send_done()
2738 evhttp_connection_free(evcon); in evhttp_send_done()
2743 if (evhttp_associate_new_request_with_connection(evcon) == -1) { in evhttp_send_done()
2744 evhttp_connection_free(evcon); in evhttp_send_done()
2765 evhttp_connection_free(req->evcon); in evhttp_send_error()
2787 struct evhttp_connection *evcon = req->evcon; in evhttp_send() local
2789 if (evcon == NULL) { in evhttp_send()
2794 EVUTIL_ASSERT(TAILQ_FIRST(&evcon->requests) == req); in evhttp_send()
2804 evhttp_make_header(evcon, req); in evhttp_send()
2806 evhttp_write_buffer(evcon, evhttp_send_done, NULL); in evhttp_send()
2837 evhttp_make_header(req->evcon, req); in evhttp_send_reply_start()
2838 evhttp_write_buffer(req->evcon, NULL, NULL); in evhttp_send_reply_start()
2845 struct evhttp_connection *evcon = req->evcon; in evhttp_send_reply_chunk_with_cb() local
2848 if (evcon == NULL) in evhttp_send_reply_chunk_with_cb()
2851 output = bufferevent_get_output(evcon->bufev); in evhttp_send_reply_chunk_with_cb()
2865 evhttp_write_buffer(evcon, cb, arg); in evhttp_send_reply_chunk_with_cb()
2876 struct evhttp_connection *evcon = req->evcon; in evhttp_send_reply_end() local
2879 if (evcon == NULL) { in evhttp_send_reply_end()
2884 output = bufferevent_get_output(evcon->bufev); in evhttp_send_reply_end()
2891 evhttp_write_buffer(req->evcon, evhttp_send_done, NULL); in evhttp_send_reply_end()
2895 evhttp_send_done(evcon, NULL); in evhttp_send_reply_end()
2898 evcon->cb = evhttp_send_done; in evhttp_send_reply_end()
2899 evcon->cb_arg = NULL; in evhttp_send_reply_end()
3459 evhttp_connection_free(req->evcon); in evhttp_handle_request()
3465 evhttp_connection_free(req->evcon); in evhttp_handle_request()
3674 struct evhttp_connection *evcon; in evhttp_free() local
3688 while ((evcon = TAILQ_FIRST(&http->connections)) != NULL) { in evhttp_free()
3690 evhttp_connection_free(evcon); in evhttp_free()
4021 return req->evcon; in evhttp_request_get_connection()
4168 struct evhttp_connection *evcon; in evhttp_get_request_connection() local
4186 evcon = evhttp_connection_base_bufferevent_new( in evhttp_get_request_connection()
4190 if (evcon == NULL) in evhttp_get_request_connection()
4193 evcon->max_headers_size = http->default_max_headers_size; in evhttp_get_request_connection()
4194 evcon->max_body_size = http->default_max_body_size; in evhttp_get_request_connection()
4196 evcon->flags |= EVHTTP_CON_LINGERING_CLOSE; in evhttp_get_request_connection()
4198 evcon->flags |= EVHTTP_CON_INCOMING; in evhttp_get_request_connection()
4199 evcon->state = EVCON_READING_FIRSTLINE; in evhttp_get_request_connection()
4201 evcon->fd = fd; in evhttp_get_request_connection()
4203 bufferevent_enable(evcon->bufev, EV_READ); in evhttp_get_request_connection()
4204 bufferevent_disable(evcon->bufev, EV_WRITE); in evhttp_get_request_connection()
4205 bufferevent_setfd(evcon->bufev, fd); in evhttp_get_request_connection()
4207 return (evcon); in evhttp_get_request_connection()
4211 evhttp_associate_new_request_with_connection(struct evhttp_connection *evcon) in evhttp_associate_new_request_with_connection() argument
4213 struct evhttp *http = evcon->http_server; in evhttp_associate_new_request_with_connection()
4218 if ((req->remote_host = mm_strdup(evcon->address)) == NULL) { in evhttp_associate_new_request_with_connection()
4223 req->remote_port = evcon->port; in evhttp_associate_new_request_with_connection()
4225 req->evcon = evcon; /* the request ends up owning the connection */ in evhttp_associate_new_request_with_connection()
4235 TAILQ_INSERT_TAIL(&evcon->requests, req, next); in evhttp_associate_new_request_with_connection()
4240 evhttp_start_read_(evcon); in evhttp_associate_new_request_with_connection()
4249 struct evhttp_connection *evcon; in evhttp_get_request() local
4251 evcon = evhttp_get_request_connection(http, fd, sa, salen); in evhttp_get_request()
4252 if (evcon == NULL) { in evhttp_get_request()
4261 evhttp_connection_set_timeout_tv(evcon, &http->timeout); in evhttp_get_request()
4267 evcon->http_server = http; in evhttp_get_request()
4268 TAILQ_INSERT_TAIL(&http->connections, evcon, next); in evhttp_get_request()
4270 if (evhttp_associate_new_request_with_connection(evcon) == -1) in evhttp_get_request()
4271 evhttp_connection_free(evcon); in evhttp_get_request()