+static void
+__ustream_ssl_save_session(struct ustream_ssl *us)
+{
+ struct ustream_ssl_ctx *ctx = us->ctx;
+ mbedtls_ssl_session sess;
+
+ if (ctx->server)
+ return;
+
+ free(ctx->session_data);
+ ctx->session_data = NULL;
+
+ mbedtls_ssl_session_init(&sess);
+ if (mbedtls_ssl_get_session(us->ssl, &sess) != 0)
+ return;
+
+ mbedtls_ssl_session_save(&sess, NULL, 0, &ctx->session_data_len);
+ ctx->session_data = malloc(ctx->session_data_len);
+ if (mbedtls_ssl_session_save(&sess, ctx->session_data, ctx->session_data_len,
+ &ctx->session_data_len))
+ ctx->session_data_len = 0;
+ mbedtls_ssl_session_free(&sess);
+}
+
+static int ssl_check_return(struct ustream_ssl *us, int ret)