+static int
+picotls_ctx_init_client (tls_ctx_t *ctx)
+{
+ picotls_ctx_t *ptls_ctx = (picotls_ctx_t *) ctx;
+ picotls_main_t *pm = &picotls_main;
+ ptls_context_t *client_ptls_ctx = pm->client_ptls_ctx;
+ ptls_handshake_properties_t hsprop = { { { { NULL } } } };
+
+ session_t *tls_session = session_get_from_handle (ctx->tls_session_handle);
+ ptls_buffer_t hs_buf;
+
+ ptls_ctx->tls = ptls_new (client_ptls_ctx, 0);
+ if (ptls_ctx->tls == NULL)
+ {
+ TLS_DBG (1, "Failed to initialize ptls_ssl structure");
+ return -1;
+ }
+
+ ptls_ctx->rx_len = 0;
+ ptls_ctx->rx_offset = 0;
+ ptls_ctx->write_buffer_offset = 0;
+
+ ptls_buffer_init (&hs_buf, "", 0);
+ if (ptls_handshake (ptls_ctx->tls, &hs_buf, NULL, NULL, &hsprop) !=
+ PTLS_ERROR_IN_PROGRESS)
+ {
+ TLS_DBG (1, "Failed to initialize tls connection");
+ }
+
+ picotls_try_handshake_write (ptls_ctx, tls_session, &hs_buf);
+
+ ptls_buffer_dispose (&hs_buf);
+
+ return 0;
+}
+