factorize the code from `h2o_open_tunnel_from_socket`
@@ -850,26 +850,11 @@ static h2o_httpclient_tunnel_t *do_open_tunnel(h2o_httpclient_t *_client)
/* detatch the socket from client */
struct st_h2o_http1client_t *client = (void *)_client;
h2o_socket_t *sock = client->sock;
- h2o_socket_read_stop(sock);
h2o_buffer_consume(&sock->input, client->bytes_to_consume);
client->bytes_to_consume = 0;
client->sock = NULL;
- /* create tunnel */
- struct st_h2o_http1client_tunnel_t *tunnel = h2o_mem_alloc(sizeof(*tunnel));
- *tunnel = (struct st_h2o_http1client_tunnel_t){
- .super =
- (h2o_httpclient_tunnel_t){
- .destroy = tunnel_on_destroy,
- .write_ = tunnel_on_write,
- .proceed_read = tunnel_proceed_read,
- },
- .sock = sock,
- };
- tunnel->sock->data = tunnel;
- h2o_doublebuffer_init(&tunnel->buf, &h2o_socket_buffer_prototype);
-
- return &tunnel->super;
+ return h2o_open_tunnel_from_socket(sock);
}
static void do_get_conn_properties(h2o_httpclient_t *_client, h2o_httpclient_conn_properties_t *properties)
