From 84c7f315bccabaa9853264a4e640f58cdb6b4ed4 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Sat, 15 Mar 2014 13:29:28 +0100 Subject: [PATCH] ustream-server-example: close connection on error Signed-off-by: Felix Fietkau --- ustream-example-server.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ustream-example-server.c b/ustream-example-server.c index 3e10543..f1c02cb 100644 --- a/ustream-example-server.c +++ b/ustream-example-server.c @@ -101,12 +101,10 @@ static void client_read_cb(struct ustream *s, int bytes) } } -static void client_close(struct ustream *s) +static void client_close(struct client *cl) { - struct client *cl = container_of(s, struct client, ssl.stream); - fprintf(stderr, "Connection closed\n"); - ustream_free(s); + ustream_free(&cl->ssl.stream); ustream_free(&cl->s.stream); close(cl->s.fd.fd); free(cl); @@ -131,7 +129,7 @@ static void client_notify_state(struct ustream *s) fprintf(stderr, "eof!, pending: %d, total: %d\n", s->w.data_bytes, cl->ctr); if (!s->w.data_bytes) - return client_close(s); + return client_close(cl); } static void client_notify_connected(struct ustream_ssl *ssl) @@ -141,7 +139,10 @@ static void client_notify_connected(struct ustream_ssl *ssl) static void client_notify_error(struct ustream_ssl *ssl, int error, const char *str) { + struct client *cl = container_of(ssl, struct client, ssl); + fprintf(stderr, "SSL connection error(%d): %s\n", error, str); + client_close(cl); } static void server_cb(struct uloop_fd *fd, unsigned int events) -- 2.25.1