Lines Matching refs:evcon

185 	struct evhttp_connection *evcon);
187 struct evhttp_connection *evcon);
189 struct evhttp_connection *evcon);
190 static void evhttp_request_dispatch(struct evhttp_connection* evcon);
191 static void evhttp_read_firstline(struct evhttp_connection *evcon,
193 static void evhttp_read_header(struct evhttp_connection *evcon,
370 evhttp_write_buffer(struct evhttp_connection *evcon, in evhttp_write_buffer() argument
376 evcon->cb = cb; in evhttp_write_buffer()
377 evcon->cb_arg = arg; in evhttp_write_buffer()
382 bufferevent_setcb(evcon->bufev, in evhttp_write_buffer()
386 evcon); in evhttp_write_buffer()
388 bufferevent_enable(evcon->bufev, EV_READ|EV_WRITE); in evhttp_write_buffer()
392 evhttp_send_continue_done(struct evhttp_connection *evcon, void *arg) in evhttp_send_continue_done() argument
394 bufferevent_disable(evcon->bufev, EV_WRITE); in evhttp_send_continue_done()
398 evhttp_send_continue(struct evhttp_connection *evcon, in evhttp_send_continue() argument
401 bufferevent_enable(evcon->bufev, EV_WRITE); in evhttp_send_continue()
402 evbuffer_add_printf(bufferevent_get_output(evcon->bufev), in evhttp_send_continue()
405 evcon->cb = evhttp_send_continue_done; in evhttp_send_continue()
406 evcon->cb_arg = NULL; in evhttp_send_continue()
407 bufferevent_setcb(evcon->bufev, in evhttp_send_continue()
411 evcon); in evhttp_send_continue()
416 evhttp_connected(struct evhttp_connection *evcon) in evhttp_connected() argument
418 switch (evcon->state) { in evhttp_connected()
438 evhttp_make_header_request(struct evhttp_connection *evcon, in evhttp_make_header_request() argument
450 evbuffer_add_printf(bufferevent_get_output(evcon->bufev), in evhttp_make_header_request()
531 evhttp_make_header_response(struct evhttp_connection *evcon, in evhttp_make_header_response() argument
535 evbuffer_add_printf(bufferevent_get_output(evcon->bufev), in evhttp_make_header_response()
569 && evcon->http_server->default_content_type) { in evhttp_make_header_response()
572 evcon->http_server->default_content_type); in evhttp_make_header_response()
606 evhttp_make_header(struct evhttp_connection *evcon, struct evhttp_request *req) in evhttp_make_header() argument
609 struct evbuffer *output = bufferevent_get_output(evcon->bufev); in evhttp_make_header()
616 evhttp_make_header_request(evcon, req); in evhttp_make_header()
618 evhttp_make_header_response(evcon, req); in evhttp_make_header()
638 evhttp_connection_set_max_headers_size(struct evhttp_connection *evcon, in evhttp_connection_set_max_headers_size() argument
642 evcon->max_headers_size = EV_SIZE_MAX; in evhttp_connection_set_max_headers_size()
644 evcon->max_headers_size = new_max_headers_size; in evhttp_connection_set_max_headers_size()
647 evhttp_connection_set_max_body_size(struct evhttp_connection* evcon, in evhttp_connection_set_max_body_size() argument
651 evcon->max_body_size = EV_UINT64_MAX; in evhttp_connection_set_max_body_size()
653 evcon->max_body_size = new_max_body_size; in evhttp_connection_set_max_body_size()
681 TAILQ_REMOVE(&req->evcon->requests, req, next); in evhttp_connection_incoming_fail()
685 req->evcon = NULL; in evhttp_connection_incoming_fail()
723 evhttp_request_free_(struct evhttp_connection *evcon, struct evhttp_request *req) in evhttp_request_free_() argument
725 TAILQ_REMOVE(&evcon->requests, req, next); in evhttp_request_free_()
734 evhttp_connection_fail_(struct evhttp_connection *evcon, in evhttp_connection_fail_() argument
738 struct evhttp_request* req = TAILQ_FIRST(&evcon->requests); in evhttp_connection_fail_()
745 bufferevent_disable(evcon->bufev, EV_READ|EV_WRITE); in evhttp_connection_fail_()
747 if (evcon->flags & EVHTTP_CON_INCOMING) { in evhttp_connection_fail_()
757 evhttp_connection_free(evcon); in evhttp_connection_fail_()
777 evhttp_request_free_(evcon, req); in evhttp_connection_fail_()
780 evhttp_connection_reset_(evcon); in evhttp_connection_fail_()
783 if (TAILQ_FIRST(&evcon->requests) != NULL) in evhttp_connection_fail_()
784 evhttp_connection_connect_(evcon); in evhttp_connection_fail_()
786 if ((evcon->flags & EVHTTP_CON_OUTGOING) && in evhttp_connection_fail_()
787 (evcon->flags & EVHTTP_CON_AUTOFREE)) { in evhttp_connection_fail_()
788 evhttp_connection_free(evcon); in evhttp_connection_fail_()
809 struct evhttp_connection *evcon = arg; in evhttp_write_cb() local
812 if (evcon->cb != NULL) in evhttp_write_cb()
813 (*evcon->cb)(evcon, evcon->cb_arg); in evhttp_write_cb()
824 evhttp_connection_done(struct evhttp_connection *evcon) in evhttp_connection_done() argument
826 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); in evhttp_connection_done()
827 int con_outgoing = evcon->flags & EVHTTP_CON_OUTGOING; in evhttp_connection_done()
833 TAILQ_REMOVE(&evcon->requests, req, next); in evhttp_connection_done()
834 req->evcon = NULL; in evhttp_connection_done()
836 evcon->state = EVCON_IDLE; in evhttp_connection_done()
840 evhttp_connection_reset_(evcon); in evhttp_connection_done()
842 if (TAILQ_FIRST(&evcon->requests) != NULL) { in evhttp_connection_done()
847 if (!evhttp_connected(evcon)) in evhttp_connection_done()
848 evhttp_connection_connect_(evcon); in evhttp_connection_done()
850 evhttp_request_dispatch(evcon); in evhttp_connection_done()
856 evhttp_connection_start_detectclose(evcon); in evhttp_connection_done()
857 } else if ((evcon->flags & EVHTTP_CON_AUTOFREE)) { in evhttp_connection_done()
869 evcon->state = EVCON_WRITING; in evhttp_connection_done()
886 if (free_evcon && TAILQ_FIRST(&evcon->requests) == NULL) { in evhttp_connection_done()
887 evhttp_connection_free(evcon); in evhttp_connection_done()
953 if (req->body_size + (size_t)ntoread > req->evcon->max_body_size) { in evhttp_handle_chunked_read()
997 evhttp_read_trailer(struct evhttp_connection *evcon, struct evhttp_request *req) in evhttp_read_trailer() argument
999 struct evbuffer *buf = bufferevent_get_input(evcon->bufev); in evhttp_read_trailer()
1004 evhttp_connection_fail_(evcon, EVREQ_HTTP_DATA_TOO_LONG); in evhttp_read_trailer()
1007 bufferevent_disable(evcon->bufev, EV_READ); in evhttp_read_trailer()
1008 evhttp_connection_done(evcon); in evhttp_read_trailer()
1018 evhttp_lingering_close(struct evhttp_connection *evcon, in evhttp_lingering_close() argument
1021 struct evbuffer *buf = bufferevent_get_input(evcon->bufev); in evhttp_lingering_close()
1034 evhttp_connection_fail_(evcon, EVREQ_HTTP_DATA_TOO_LONG); in evhttp_lingering_close()
1037 evhttp_lingering_fail(struct evhttp_connection *evcon, in evhttp_lingering_fail() argument
1040 if (evcon->flags & EVHTTP_CON_LINGERING_CLOSE) in evhttp_lingering_fail()
1041 evhttp_lingering_close(evcon, req); in evhttp_lingering_fail()
1043 evhttp_connection_fail_(evcon, EVREQ_HTTP_DATA_TOO_LONG); in evhttp_lingering_fail()
1047 evhttp_read_body(struct evhttp_connection *evcon, struct evhttp_request *req) in evhttp_read_body() argument
1049 struct evbuffer *buf = bufferevent_get_input(evcon->bufev); in evhttp_read_body()
1055 evcon->state = EVCON_READING_TRAILER; in evhttp_read_body()
1056 evhttp_read_trailer(evcon, req); in evhttp_read_body()
1061 evhttp_connection_fail_(evcon, in evhttp_read_body()
1075 evhttp_connection_fail_(evcon, EVREQ_HTTP_INVALID_HEADER); in evhttp_read_body()
1094 if (req->body_size > req->evcon->max_body_size || in evhttp_read_body()
1096 (size_t)req->ntoread > req->evcon->max_body_size)) { in evhttp_read_body()
1100 evhttp_lingering_fail(evcon, req); in evhttp_read_body()
1117 bufferevent_disable(evcon->bufev, EV_READ); in evhttp_read_body()
1119 evhttp_connection_done(evcon); in evhttp_read_body()
1124 #define get_deferred_queue(evcon) \ argument
1125 ((evcon)->base)
1134 struct evhttp_connection *evcon = arg; in evhttp_read_cb() local
1135 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); in evhttp_read_cb()
1138 event_deferred_cb_cancel_(get_deferred_queue(evcon), in evhttp_read_cb()
1139 &evcon->read_more_deferred_cb); in evhttp_read_cb()
1141 switch (evcon->state) { in evhttp_read_cb()
1143 evhttp_read_firstline(evcon, req); in evhttp_read_cb()
1148 evhttp_read_header(evcon, req); in evhttp_read_cb()
1153 evhttp_read_body(evcon, req); in evhttp_read_cb()
1158 evhttp_read_trailer(evcon, req); in evhttp_read_cb()
1166 input = bufferevent_get_input(evcon->bufev); in evhttp_read_cb()
1174 evhttp_connection_reset_(evcon); in evhttp_read_cb()
1182 __func__, evcon->state); in evhttp_read_cb()
1189 struct evhttp_connection *evcon = data; in evhttp_deferred_read_cb() local
1190 struct bufferevent *bev = evcon->bufev; in evhttp_deferred_read_cb()
1192 (bev->readcb)(evcon->bufev, evcon); in evhttp_deferred_read_cb()
1196 evhttp_write_connectioncb(struct evhttp_connection *evcon, void *arg) in evhttp_write_connectioncb() argument
1199 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); in evhttp_write_connectioncb()
1200 struct evbuffer *output = bufferevent_get_output(evcon->bufev); in evhttp_write_connectioncb()
1203 EVUTIL_ASSERT(evcon->state == EVCON_WRITING); in evhttp_write_connectioncb()
1213 evhttp_start_read_(evcon); in evhttp_write_connectioncb()
1221 evhttp_connection_free(struct evhttp_connection *evcon) in evhttp_connection_free() argument
1227 if (evcon->fd != -1) { in evhttp_connection_free()
1228 if (evhttp_connected(evcon) && evcon->closecb != NULL) in evhttp_connection_free()
1229 (*evcon->closecb)(evcon, evcon->closecb_arg); in evhttp_connection_free()
1237 while ((req = TAILQ_FIRST(&evcon->requests)) != NULL) { in evhttp_connection_free()
1238 evhttp_request_free_(evcon, req); in evhttp_connection_free()
1241 if (evcon->http_server != NULL) { in evhttp_connection_free()
1242 struct evhttp *http = evcon->http_server; in evhttp_connection_free()
1243 TAILQ_REMOVE(&http->connections, evcon, next); in evhttp_connection_free()
1246 if (event_initialized(&evcon->retry_ev)) { in evhttp_connection_free()
1247 event_del(&evcon->retry_ev); in evhttp_connection_free()
1248 event_debug_unassign(&evcon->retry_ev); in evhttp_connection_free()
1251 event_deferred_cb_cancel_(get_deferred_queue(evcon), in evhttp_connection_free()
1252 &evcon->read_more_deferred_cb); in evhttp_connection_free()
1254 if (evcon->bufev != NULL) { in evhttp_connection_free()
1256 !(bufferevent_get_options_(evcon->bufev) & BEV_OPT_CLOSE_ON_FREE); in evhttp_connection_free()
1257 if (evcon->fd == -1) in evhttp_connection_free()
1258 evcon->fd = bufferevent_getfd(evcon->bufev); in evhttp_connection_free()
1260 bufferevent_free(evcon->bufev); in evhttp_connection_free()
1263 if (evcon->fd != -1) { in evhttp_connection_free()
1264 shutdown(evcon->fd, EVUTIL_SHUT_WR); in evhttp_connection_free()
1266 evutil_closesocket(evcon->fd); in evhttp_connection_free()
1269 if (evcon->bind_address != NULL) in evhttp_connection_free()
1270 mm_free(evcon->bind_address); in evhttp_connection_free()
1272 if (evcon->address != NULL) in evhttp_connection_free()
1273 mm_free(evcon->address); in evhttp_connection_free()
1275 mm_free(evcon); in evhttp_connection_free()
1279 evhttp_connection_free_on_completion(struct evhttp_connection *evcon) { in evhttp_connection_free_on_completion() argument
1280 evcon->flags |= EVHTTP_CON_AUTOFREE; in evhttp_connection_free_on_completion()
1284 evhttp_connection_set_local_address(struct evhttp_connection *evcon, in evhttp_connection_set_local_address() argument
1287 EVUTIL_ASSERT(evcon->state == EVCON_DISCONNECTED); in evhttp_connection_set_local_address()
1288 if (evcon->bind_address) in evhttp_connection_set_local_address()
1289 mm_free(evcon->bind_address); in evhttp_connection_set_local_address()
1290 if ((evcon->bind_address = mm_strdup(address)) == NULL) in evhttp_connection_set_local_address()
1295 evhttp_connection_set_local_port(struct evhttp_connection *evcon, in evhttp_connection_set_local_port() argument
1298 EVUTIL_ASSERT(evcon->state == EVCON_DISCONNECTED); in evhttp_connection_set_local_port()
1299 evcon->bind_port = port; in evhttp_connection_set_local_port()
1303 evhttp_request_dispatch(struct evhttp_connection* evcon) in evhttp_request_dispatch() argument
1305 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); in evhttp_request_dispatch()
1314 evhttp_connection_stop_detectclose(evcon); in evhttp_request_dispatch()
1317 EVUTIL_ASSERT(evcon->state == EVCON_IDLE); in evhttp_request_dispatch()
1319 evcon->state = EVCON_WRITING; in evhttp_request_dispatch()
1322 evhttp_make_header(evcon, req); in evhttp_request_dispatch()
1324 evhttp_write_buffer(evcon, evhttp_write_connectioncb, NULL); in evhttp_request_dispatch()
1330 evhttp_connection_reset_(struct evhttp_connection *evcon) in evhttp_connection_reset_() argument
1335 bufferevent_setcb(evcon->bufev, NULL, NULL, NULL, NULL); in evhttp_connection_reset_()
1348 bufferevent_disable_hard_(evcon->bufev, EV_READ|EV_WRITE); in evhttp_connection_reset_()
1350 if (evcon->fd == -1) in evhttp_connection_reset_()
1351 evcon->fd = bufferevent_getfd(evcon->bufev); in evhttp_connection_reset_()
1353 if (evcon->fd != -1) { in evhttp_connection_reset_()
1355 if (evhttp_connected(evcon) && evcon->closecb != NULL) in evhttp_connection_reset_()
1356 (*evcon->closecb)(evcon, evcon->closecb_arg); in evhttp_connection_reset_()
1358 shutdown(evcon->fd, EVUTIL_SHUT_WR); in evhttp_connection_reset_()
1359 evutil_closesocket(evcon->fd); in evhttp_connection_reset_()
1360 evcon->fd = -1; in evhttp_connection_reset_()
1362 err = bufferevent_setfd(evcon->bufev, -1); in evhttp_connection_reset_()
1366 tmp = bufferevent_get_output(evcon->bufev); in evhttp_connection_reset_()
1369 tmp = bufferevent_get_input(evcon->bufev); in evhttp_connection_reset_()
1373 evcon->flags &= ~EVHTTP_CON_READING_ERROR; in evhttp_connection_reset_()
1375 evcon->state = EVCON_DISCONNECTED; in evhttp_connection_reset_()
1379 evhttp_connection_start_detectclose(struct evhttp_connection *evcon) in evhttp_connection_start_detectclose() argument
1381 evcon->flags |= EVHTTP_CON_CLOSEDETECT; in evhttp_connection_start_detectclose()
1382 bufferevent_enable(evcon->bufev, EV_READ); in evhttp_connection_start_detectclose()
1386 evhttp_connection_stop_detectclose(struct evhttp_connection *evcon) in evhttp_connection_stop_detectclose() argument
1388 evcon->flags &= ~EVHTTP_CON_CLOSEDETECT; in evhttp_connection_stop_detectclose()
1389 bufferevent_disable(evcon->bufev, EV_READ); in evhttp_connection_stop_detectclose()
1395 struct evhttp_connection *evcon = arg; in evhttp_connection_retry() local
1397 evcon->state = EVCON_DISCONNECTED; in evhttp_connection_retry()
1398 evhttp_connection_connect_(evcon); in evhttp_connection_retry()
1402 evhttp_connection_cb_cleanup(struct evhttp_connection *evcon) in evhttp_connection_cb_cleanup() argument
1406 evhttp_connection_reset_(evcon); in evhttp_connection_cb_cleanup()
1407 if (evcon->retry_max < 0 || evcon->retry_cnt < evcon->retry_max) { in evhttp_connection_cb_cleanup()
1408 struct timeval tv_retry = evcon->initial_retry_timeout; in evhttp_connection_cb_cleanup()
1410 evtimer_assign(&evcon->retry_ev, evcon->base, evhttp_connection_retry, evcon); in evhttp_connection_cb_cleanup()
1412 for (i=0; i < evcon->retry_cnt; ++i) { in evhttp_connection_cb_cleanup()
1424 event_add(&evcon->retry_ev, &tv_retry); in evhttp_connection_cb_cleanup()
1425 evcon->retry_cnt++; in evhttp_connection_cb_cleanup()
1436 while (TAILQ_FIRST(&evcon->requests) != NULL) { in evhttp_connection_cb_cleanup()
1437 struct evhttp_request *request = TAILQ_FIRST(&evcon->requests); in evhttp_connection_cb_cleanup()
1438 TAILQ_REMOVE(&evcon->requests, request, next); in evhttp_connection_cb_cleanup()
1446 request->evcon = NULL; in evhttp_connection_cb_cleanup()
1455 evhttp_connection_read_on_write_error(struct evhttp_connection *evcon, in evhttp_connection_read_on_write_error() argument
1461 if (evcon->flags & EVHTTP_CON_READING_ERROR) { in evhttp_connection_read_on_write_error()
1462 evcon->flags &= ~EVHTTP_CON_READING_ERROR; in evhttp_connection_read_on_write_error()
1463 evhttp_connection_fail_(evcon, EVREQ_HTTP_EOF); in evhttp_connection_read_on_write_error()
1469 buf = bufferevent_get_output(evcon->bufev); in evhttp_connection_read_on_write_error()
1474 evhttp_start_read_(evcon); in evhttp_connection_read_on_write_error()
1475 evcon->flags |= EVHTTP_CON_READING_ERROR; in evhttp_connection_read_on_write_error()
1481 struct evhttp_connection *evcon = arg; in evhttp_error_cb() local
1482 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); in evhttp_error_cb()
1484 if (evcon->fd == -1) in evhttp_error_cb()
1485 evcon->fd = bufferevent_getfd(bufev); in evhttp_error_cb()
1487 switch (evcon->state) { in evhttp_error_cb()
1492 __func__, evcon->address, evcon->port, in evhttp_error_cb()
1493 EV_SOCK_ARG(evcon->fd))); in evhttp_error_cb()
1494 evhttp_connection_cb_cleanup(evcon); in evhttp_error_cb()
1503 evhttp_connection_done(evcon); in evhttp_error_cb()
1521 if (evcon->flags & EVHTTP_CON_CLOSEDETECT) { in evhttp_error_cb()
1522 evcon->flags &= ~EVHTTP_CON_CLOSEDETECT; in evhttp_error_cb()
1523 EVUTIL_ASSERT(evcon->http_server == NULL); in evhttp_error_cb()
1528 EVUTIL_ASSERT(evcon->state == EVCON_IDLE); in evhttp_error_cb()
1529 evhttp_connection_reset_(evcon); in evhttp_error_cb()
1536 if (TAILQ_FIRST(&evcon->requests) == NULL in evhttp_error_cb()
1537 && (evcon->flags & EVHTTP_CON_OUTGOING) in evhttp_error_cb()
1538 && (evcon->flags & EVHTTP_CON_AUTOFREE)) { in evhttp_error_cb()
1539 evhttp_connection_free(evcon); in evhttp_error_cb()
1545 evhttp_connection_fail_(evcon, EVREQ_HTTP_TIMEOUT); in evhttp_error_cb()
1548 evcon->flags & EVHTTP_CON_READ_ON_WRITE_ERROR) { in evhttp_error_cb()
1549 evhttp_connection_read_on_write_error(evcon, req); in evhttp_error_cb()
1554 evcon->flags & EVHTTP_CON_READ_ON_WRITE_ERROR && in evhttp_error_cb()
1556 event_deferred_cb_schedule_(get_deferred_queue(evcon), in evhttp_error_cb()
1557 &evcon->read_more_deferred_cb); in evhttp_error_cb()
1561 evhttp_connection_fail_(evcon, EVREQ_HTTP_EOF); in evhttp_error_cb()
1564 evhttp_connection_fail_(evcon, EVREQ_HTTP_BUFFER_ERROR); in evhttp_error_cb()
1574 struct evhttp_connection *evcon = arg; in evhttp_connection_cb() local
1578 if (evcon->fd == -1) in evhttp_connection_cb()
1579 evcon->fd = bufferevent_getfd(bufev); in evhttp_connection_cb()
1594 if (evcon->fd == -1) { in evhttp_connection_cb()
1601 if (getsockopt(evcon->fd, SOL_SOCKET, SO_ERROR, (void*)&error, in evhttp_connection_cb()
1604 __func__, evcon->address, evcon->port, in evhttp_connection_cb()
1605 EV_SOCK_ARG(evcon->fd))); in evhttp_connection_cb()
1612 __func__, evcon->address, evcon->port, in evhttp_connection_cb()
1613 EV_SOCK_ARG(evcon->fd), in evhttp_connection_cb()
1620 __func__, evcon->address, evcon->port, in evhttp_connection_cb()
1621 EV_SOCK_ARG(evcon->fd))); in evhttp_connection_cb()
1624 evcon->retry_cnt = 0; in evhttp_connection_cb()
1625 evcon->state = EVCON_IDLE; in evhttp_connection_cb()
1628 bufferevent_setcb(evcon->bufev, in evhttp_connection_cb()
1632 evcon); in evhttp_connection_cb()
1634 if (!evutil_timerisset(&evcon->timeout)) { in evhttp_connection_cb()
1637 bufferevent_set_timeouts(evcon->bufev, &read_tv, &write_tv); in evhttp_connection_cb()
1639 bufferevent_set_timeouts(evcon->bufev, &evcon->timeout, &evcon->timeout); in evhttp_connection_cb()
1643 evhttp_request_dispatch(evcon); in evhttp_connection_cb()
1647 evhttp_connection_cb_cleanup(evcon); in evhttp_connection_cb()
1892 !evhttp_find_vhost(req->evcon->http_server, NULL, hostname)) in evhttp_parse_request_line()
2034 if (req->evcon != NULL && in evhttp_parse_firstline_()
2035 evbuffer_get_length(buffer) > req->evcon->max_headers_size) in evhttp_parse_firstline_()
2041 if (req->evcon != NULL && len > req->evcon->max_headers_size) { in evhttp_parse_firstline_()
2110 if (req->evcon != NULL && in evhttp_parse_headers_()
2111 req->headers_size > req->evcon->max_headers_size) { in evhttp_parse_headers_()
2146 if (req->evcon != NULL && in evhttp_parse_headers_()
2147 req->headers_size + evbuffer_get_length(buffer) > req->evcon->max_headers_size) in evhttp_parse_headers_()
2188 EV_SIZE_ARG(evbuffer_get_length(bufferevent_get_input(req->evcon->bufev))))); in evhttp_get_body_length()
2215 evhttp_get_body(struct evhttp_connection *evcon, struct evhttp_request *req) in evhttp_get_body() argument
2222 evhttp_connection_done(evcon); in evhttp_get_body()
2225 evcon->state = EVCON_READING_BODY; in evhttp_get_body()
2232 evhttp_connection_fail_(evcon, EVREQ_HTTP_INVALID_HEADER); in evhttp_get_body()
2238 evhttp_connection_done(evcon); in evhttp_get_body()
2254 if ((req->evcon->max_body_size <= EV_INT64_MAX) && in evhttp_get_body()
2255 (ev_uint64_t)req->ntoread > req->evcon->max_body_size) { in evhttp_get_body()
2256 evhttp_lingering_fail(evcon, req); in evhttp_get_body()
2260 if (!evbuffer_get_length(bufferevent_get_input(evcon->bufev))) in evhttp_get_body()
2261 evhttp_send_continue(evcon, req); in evhttp_get_body()
2269 evhttp_read_body(evcon, req); in evhttp_get_body()
2274 evhttp_read_firstline(struct evhttp_connection *evcon, in evhttp_read_firstline() argument
2279 res = evhttp_parse_firstline_(req, bufferevent_get_input(evcon->bufev)); in evhttp_read_firstline()
2283 __func__, EV_SOCK_ARG(evcon->fd))); in evhttp_read_firstline()
2284 evhttp_connection_fail_(evcon, EVREQ_HTTP_INVALID_HEADER); in evhttp_read_firstline()
2291 evcon->state = EVCON_READING_HEADERS; in evhttp_read_firstline()
2292 evhttp_read_header(evcon, req); in evhttp_read_firstline()
2296 evhttp_read_header(struct evhttp_connection *evcon, in evhttp_read_header() argument
2300 evutil_socket_t fd = evcon->fd; in evhttp_read_header()
2302 res = evhttp_parse_headers_(req, bufferevent_get_input(evcon->bufev)); in evhttp_read_header()
2307 evhttp_connection_fail_(evcon, EVREQ_HTTP_INVALID_HEADER); in evhttp_read_header()
2317 evhttp_connection_fail_(evcon, EVREQ_HTTP_EOF); in evhttp_read_header()
2327 evhttp_get_body(evcon, req); in evhttp_read_header()
2334 struct evbuffer *output = bufferevent_get_output(evcon->bufev); in evhttp_read_header()
2336 evhttp_start_write_(evcon); in evhttp_read_header()
2342 evhttp_connection_done(evcon); in evhttp_read_header()
2347 evhttp_get_body(evcon, req); in evhttp_read_header()
2356 evhttp_connection_fail_(evcon, EVREQ_HTTP_INVALID_HEADER); in evhttp_read_header()
2382 struct evhttp_connection *evcon = NULL; in evhttp_connection_base_bufferevent_new() local
2386 if ((evcon = mm_calloc(1, sizeof(struct evhttp_connection))) == NULL) { in evhttp_connection_base_bufferevent_new()
2391 evcon->fd = -1; in evhttp_connection_base_bufferevent_new()
2392 evcon->port = port; in evhttp_connection_base_bufferevent_new()
2394 evcon->max_headers_size = EV_SIZE_MAX; in evhttp_connection_base_bufferevent_new()
2395 evcon->max_body_size = EV_SIZE_MAX; in evhttp_connection_base_bufferevent_new()
2397 evutil_timerclear(&evcon->timeout); in evhttp_connection_base_bufferevent_new()
2398 evcon->retry_cnt = evcon->retry_max = 0; in evhttp_connection_base_bufferevent_new()
2400 if ((evcon->address = mm_strdup(address)) == NULL) { in evhttp_connection_base_bufferevent_new()
2412 bufferevent_setcb(bev, evhttp_read_cb, evhttp_write_cb, evhttp_error_cb, evcon); in evhttp_connection_base_bufferevent_new()
2413 evcon->bufev = bev; in evhttp_connection_base_bufferevent_new()
2415 evcon->state = EVCON_DISCONNECTED; in evhttp_connection_base_bufferevent_new()
2416 TAILQ_INIT(&evcon->requests); in evhttp_connection_base_bufferevent_new()
2418 evcon->initial_retry_timeout.tv_sec = 2; in evhttp_connection_base_bufferevent_new()
2419 evcon->initial_retry_timeout.tv_usec = 0; in evhttp_connection_base_bufferevent_new()
2422 evcon->base = base; in evhttp_connection_base_bufferevent_new()
2424 bufferevent_base_set(base, evcon->bufev); in evhttp_connection_base_bufferevent_new()
2428 &evcon->read_more_deferred_cb, in evhttp_connection_base_bufferevent_new()
2430 evhttp_deferred_read_cb, evcon); in evhttp_connection_base_bufferevent_new()
2432 evcon->dns_base = dnsbase; in evhttp_connection_base_bufferevent_new()
2433 evcon->ai_family = AF_UNSPEC; in evhttp_connection_base_bufferevent_new()
2435 return (evcon); in evhttp_connection_base_bufferevent_new()
2438 if (evcon != NULL) in evhttp_connection_base_bufferevent_new()
2439 evhttp_connection_free(evcon); in evhttp_connection_base_bufferevent_new()
2443 struct bufferevent* evhttp_connection_get_bufferevent(struct evhttp_connection *evcon) in evhttp_connection_get_bufferevent() argument
2445 return evcon->bufev; in evhttp_connection_get_bufferevent()
2449 evhttp_connection_get_server(struct evhttp_connection *evcon) in evhttp_connection_get_server() argument
2451 return evcon->http_server; in evhttp_connection_get_server()
2461 void evhttp_connection_set_family(struct evhttp_connection *evcon, in evhttp_connection_set_family() argument
2464 evcon->ai_family = family; in evhttp_connection_set_family()
2467 int evhttp_connection_set_flags(struct evhttp_connection *evcon, in evhttp_connection_set_flags() argument
2476 evcon->flags &= ~avail_flags; in evhttp_connection_set_flags()
2478 evcon->flags |= flags; in evhttp_connection_set_flags()
2484 evhttp_connection_set_base(struct evhttp_connection *evcon, in evhttp_connection_set_base() argument
2487 EVUTIL_ASSERT(evcon->base == NULL); in evhttp_connection_set_base()
2488 EVUTIL_ASSERT(evcon->state == EVCON_DISCONNECTED); in evhttp_connection_set_base()
2489 evcon->base = base; in evhttp_connection_set_base()
2490 bufferevent_base_set(base, evcon->bufev); in evhttp_connection_set_base()
2494 evhttp_connection_set_timeout(struct evhttp_connection *evcon, in evhttp_connection_set_timeout() argument
2498 evhttp_connection_set_timeout_tv(evcon, NULL); in evhttp_connection_set_timeout()
2503 evhttp_connection_set_timeout_tv(evcon, &tv); in evhttp_connection_set_timeout()
2508 evhttp_connection_set_timeout_tv(struct evhttp_connection *evcon, in evhttp_connection_set_timeout_tv() argument
2512 evcon->timeout = *tv; in evhttp_connection_set_timeout_tv()
2513 bufferevent_set_timeouts(evcon->bufev, &evcon->timeout, &evcon->timeout); in evhttp_connection_set_timeout_tv()
2517 evutil_timerclear(&evcon->timeout); in evhttp_connection_set_timeout_tv()
2518 bufferevent_set_timeouts(evcon->bufev, &read_tv, &write_tv); in evhttp_connection_set_timeout_tv()
2523 evhttp_connection_set_initial_retry_tv(struct evhttp_connection *evcon, in evhttp_connection_set_initial_retry_tv() argument
2527 evcon->initial_retry_timeout = *tv; in evhttp_connection_set_initial_retry_tv()
2529 evutil_timerclear(&evcon->initial_retry_timeout); in evhttp_connection_set_initial_retry_tv()
2530 evcon->initial_retry_timeout.tv_sec = 2; in evhttp_connection_set_initial_retry_tv()
2535 evhttp_connection_set_retries(struct evhttp_connection *evcon, in evhttp_connection_set_retries() argument
2538 evcon->retry_max = retry_max; in evhttp_connection_set_retries()
2542 evhttp_connection_set_closecb(struct evhttp_connection *evcon, in evhttp_connection_set_closecb() argument
2545 evcon->closecb = cb; in evhttp_connection_set_closecb()
2546 evcon->closecb_arg = cbarg; in evhttp_connection_set_closecb()
2550 evhttp_connection_get_peer(struct evhttp_connection *evcon, in evhttp_connection_get_peer() argument
2553 *address = evcon->address; in evhttp_connection_get_peer()
2554 *port = evcon->port; in evhttp_connection_get_peer()
2558 evhttp_connection_get_addr(struct evhttp_connection *evcon) in evhttp_connection_get_addr() argument
2560 return bufferevent_socket_get_conn_address_(evcon->bufev); in evhttp_connection_get_addr()
2564 evhttp_connection_connect_(struct evhttp_connection *evcon) in evhttp_connection_connect_() argument
2566 int old_state = evcon->state; in evhttp_connection_connect_()
2567 const char *address = evcon->address; in evhttp_connection_connect_()
2568 const struct sockaddr *sa = evhttp_connection_get_addr(evcon); in evhttp_connection_connect_()
2571 if (evcon->state == EVCON_CONNECTING) in evhttp_connection_connect_()
2574 evhttp_connection_reset_(evcon); in evhttp_connection_connect_()
2576 EVUTIL_ASSERT(!(evcon->flags & EVHTTP_CON_INCOMING)); in evhttp_connection_connect_()
2577 evcon->flags |= EVHTTP_CON_OUTGOING; in evhttp_connection_connect_()
2579 if (evcon->bind_address || evcon->bind_port) { in evhttp_connection_connect_()
2580 evcon->fd = bind_socket( in evhttp_connection_connect_()
2581 evcon->bind_address, evcon->bind_port, 0 /*reuse*/); in evhttp_connection_connect_()
2582 if (evcon->fd == -1) { in evhttp_connection_connect_()
2584 __func__, evcon->bind_address)); in evhttp_connection_connect_()
2588 if (bufferevent_setfd(evcon->bufev, evcon->fd)) in evhttp_connection_connect_()
2591 if (bufferevent_setfd(evcon->bufev, -1)) in evhttp_connection_connect_()
2596 bufferevent_setcb(evcon->bufev, in evhttp_connection_connect_()
2600 evcon); in evhttp_connection_connect_()
2601 if (!evutil_timerisset(&evcon->timeout)) { in evhttp_connection_connect_()
2603 bufferevent_set_timeouts(evcon->bufev, &conn_tv, &conn_tv); in evhttp_connection_connect_()
2605 bufferevent_set_timeouts(evcon->bufev, &evcon->timeout, &evcon->timeout); in evhttp_connection_connect_()
2608 if (bufferevent_enable(evcon->bufev, EV_WRITE)) in evhttp_connection_connect_()
2611 evcon->state = EVCON_CONNECTING; in evhttp_connection_connect_()
2613 if (evcon->flags & EVHTTP_CON_REUSE_CONNECTED_ADDR && in evhttp_connection_connect_()
2620 ret = bufferevent_socket_connect(evcon->bufev, sa, socklen); in evhttp_connection_connect_()
2622 ret = bufferevent_socket_connect_hostname(evcon->bufev, in evhttp_connection_connect_()
2623 evcon->dns_base, evcon->ai_family, address, evcon->port); in evhttp_connection_connect_()
2627 evcon->state = old_state; in evhttp_connection_connect_()
2628 event_sock_warn(evcon->fd, "%s: connection to \"%s\" failed", in evhttp_connection_connect_()
2629 __func__, evcon->address); in evhttp_connection_connect_()
2634 evhttp_connection_cb_cleanup(evcon); in evhttp_connection_connect_()
2648 evhttp_make_request(struct evhttp_connection *evcon, in evhttp_make_request() argument
2669 EVUTIL_ASSERT(req->evcon == NULL); in evhttp_make_request()
2670 req->evcon = evcon; in evhttp_make_request()
2673 TAILQ_INSERT_TAIL(&evcon->requests, req, next); in evhttp_make_request()
2676 if (evcon->retry_cnt) in evhttp_make_request()
2680 if (!evhttp_connected(evcon)) { in evhttp_make_request()
2681 int res = evhttp_connection_connect_(evcon); in evhttp_make_request()
2687 TAILQ_REMOVE(&evcon->requests, req, next); in evhttp_make_request()
2697 if (TAILQ_FIRST(&evcon->requests) == req) in evhttp_make_request()
2698 evhttp_request_dispatch(evcon); in evhttp_make_request()
2706 struct evhttp_connection *evcon = req->evcon; in evhttp_cancel_request() local
2707 if (evcon != NULL) { in evhttp_cancel_request()
2709 if (TAILQ_FIRST(&evcon->requests) == req) { in evhttp_cancel_request()
2713 evhttp_connection_fail_(evcon, in evhttp_cancel_request()
2722 TAILQ_REMOVE(&evcon->requests, req, next); in evhttp_cancel_request()
2735 evhttp_start_read_(struct evhttp_connection *evcon) in evhttp_start_read_() argument
2737 bufferevent_disable(evcon->bufev, EV_WRITE); in evhttp_start_read_()
2738 bufferevent_enable(evcon->bufev, EV_READ); in evhttp_start_read_()
2740 evcon->state = EVCON_READING_FIRSTLINE; in evhttp_start_read_()
2742 bufferevent_setcb(evcon->bufev, in evhttp_start_read_()
2746 evcon); in evhttp_start_read_()
2750 if (evbuffer_get_length(bufferevent_get_input(evcon->bufev))) { in evhttp_start_read_()
2751 event_deferred_cb_schedule_(get_deferred_queue(evcon), in evhttp_start_read_()
2752 &evcon->read_more_deferred_cb); in evhttp_start_read_()
2757 evhttp_start_write_(struct evhttp_connection *evcon) in evhttp_start_write_() argument
2759 bufferevent_disable(evcon->bufev, EV_WRITE); in evhttp_start_write_()
2760 bufferevent_enable(evcon->bufev, EV_READ); in evhttp_start_write_()
2762 evcon->state = EVCON_WRITING; in evhttp_start_write_()
2763 evhttp_write_buffer(evcon, evhttp_write_connectioncb, NULL); in evhttp_start_write_()
2767 evhttp_send_done(struct evhttp_connection *evcon, void *arg) in evhttp_send_done() argument
2770 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); in evhttp_send_done()
2771 TAILQ_REMOVE(&evcon->requests, req, next); in evhttp_send_done()
2786 evhttp_connection_free(evcon); in evhttp_send_done()
2791 if (evhttp_associate_new_request_with_connection(evcon) == -1) { in evhttp_send_done()
2792 evhttp_connection_free(evcon); in evhttp_send_done()
2813 evhttp_connection_free(req->evcon); in evhttp_send_error()
2835 struct evhttp_connection *evcon = req->evcon; in evhttp_send() local
2837 if (evcon == NULL) { in evhttp_send()
2842 EVUTIL_ASSERT(TAILQ_FIRST(&evcon->requests) == req); in evhttp_send()
2852 evhttp_make_header(evcon, req); in evhttp_send()
2854 evhttp_write_buffer(evcon, evhttp_send_done, NULL); in evhttp_send()
2872 if (req->evcon == NULL) in evhttp_send_reply_start()
2889 evhttp_make_header(req->evcon, req); in evhttp_send_reply_start()
2890 evhttp_write_buffer(req->evcon, NULL, NULL); in evhttp_send_reply_start()
2897 struct evhttp_connection *evcon = req->evcon; in evhttp_send_reply_chunk_with_cb() local
2900 if (evcon == NULL) in evhttp_send_reply_chunk_with_cb()
2903 output = bufferevent_get_output(evcon->bufev); in evhttp_send_reply_chunk_with_cb()
2917 evhttp_write_buffer(evcon, cb, arg); in evhttp_send_reply_chunk_with_cb()
2928 struct evhttp_connection *evcon = req->evcon; in evhttp_send_reply_end() local
2931 if (evcon == NULL) { in evhttp_send_reply_end()
2936 output = bufferevent_get_output(evcon->bufev); in evhttp_send_reply_end()
2943 evhttp_write_buffer(req->evcon, evhttp_send_done, NULL); in evhttp_send_reply_end()
2947 evhttp_send_done(evcon, NULL); in evhttp_send_reply_end()
2950 evcon->cb = evhttp_send_done; in evhttp_send_reply_end()
2951 evcon->cb_arg = NULL; in evhttp_send_reply_end()
3474 bufferevent_disable(req->evcon->bufev, EV_READ); in evhttp_handle_request()
3516 evhttp_connection_free(req->evcon); in evhttp_handle_request()
3522 evhttp_connection_free(req->evcon); in evhttp_handle_request()
3734 struct evhttp_connection *evcon; in evhttp_free() local
3748 while ((evcon = TAILQ_FIRST(&http->connections)) != NULL) { in evhttp_free()
3750 evhttp_connection_free(evcon); in evhttp_free()
4081 return req->evcon; in evhttp_request_get_connection()
4228 struct evhttp_connection *evcon; in evhttp_get_request_connection() local
4253 evcon = evhttp_connection_base_bufferevent_new( in evhttp_get_request_connection()
4257 if (evcon == NULL) in evhttp_get_request_connection()
4260 evcon->max_headers_size = http->default_max_headers_size; in evhttp_get_request_connection()
4261 evcon->max_body_size = http->default_max_body_size; in evhttp_get_request_connection()
4263 evcon->flags |= EVHTTP_CON_LINGERING_CLOSE; in evhttp_get_request_connection()
4265 evcon->flags |= EVHTTP_CON_INCOMING; in evhttp_get_request_connection()
4266 evcon->state = EVCON_READING_FIRSTLINE; in evhttp_get_request_connection()
4268 evcon->fd = fd; in evhttp_get_request_connection()
4270 if (bufferevent_setfd(evcon->bufev, fd)) in evhttp_get_request_connection()
4272 if (bufferevent_enable(evcon->bufev, EV_READ)) in evhttp_get_request_connection()
4274 if (bufferevent_disable(evcon->bufev, EV_WRITE)) in evhttp_get_request_connection()
4276 bufferevent_socket_set_conn_address_(evcon->bufev, sa, salen); in evhttp_get_request_connection()
4278 return (evcon); in evhttp_get_request_connection()
4281 evhttp_connection_free(evcon); in evhttp_get_request_connection()
4286 evhttp_associate_new_request_with_connection(struct evhttp_connection *evcon) in evhttp_associate_new_request_with_connection() argument
4288 struct evhttp *http = evcon->http_server; in evhttp_associate_new_request_with_connection()
4293 if ((req->remote_host = mm_strdup(evcon->address)) == NULL) { in evhttp_associate_new_request_with_connection()
4298 req->remote_port = evcon->port; in evhttp_associate_new_request_with_connection()
4300 req->evcon = evcon; /* the request ends up owning the connection */ in evhttp_associate_new_request_with_connection()
4310 TAILQ_INSERT_TAIL(&evcon->requests, req, next); in evhttp_associate_new_request_with_connection()
4315 evhttp_start_read_(evcon); in evhttp_associate_new_request_with_connection()
4324 struct evhttp_connection *evcon; in evhttp_get_request() local
4326 evcon = evhttp_get_request_connection(http, fd, sa, salen); in evhttp_get_request()
4327 if (evcon == NULL) { in evhttp_get_request()
4336 evhttp_connection_set_timeout_tv(evcon, &http->timeout); in evhttp_get_request()
4342 evcon->http_server = http; in evhttp_get_request()
4343 TAILQ_INSERT_TAIL(&http->connections, evcon, next); in evhttp_get_request()
4345 if (evhttp_associate_new_request_with_connection(evcon) == -1) in evhttp_get_request()
4346 evhttp_connection_free(evcon); in evhttp_get_request()