summaryrefslogtreecommitdiff
path: root/ustream-example-server.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2014-03-15 13:29:28 +0100
committerFelix Fietkau <nbd@openwrt.org>2014-03-15 13:29:28 +0100
commit84c7f315bccabaa9853264a4e640f58cdb6b4ed4 (patch)
tree2ca51b6131e1318a00f83c6833a038dafc36acd3 /ustream-example-server.c
parent8c95a99d23fa0ec35878ad98ec8757d8dbff4f8d (diff)
downloadustream-ssl-84c7f315bccabaa9853264a4e640f58cdb6b4ed4.tar.gz
ustream-server-example: close connection on error
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Diffstat (limited to 'ustream-example-server.c')
-rw-r--r--ustream-example-server.c11
1 files 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)