diff options
author | Fedor Indutny <fedor@indutny.com> | 2016-05-27 21:40:29 -0400 |
---|---|---|
committer | Fedor Indutny <fedor@indutny.com> | 2016-05-27 21:40:29 -0400 |
commit | 3523bbda22a89eb0e64cd08958efa6cafd710c09 (patch) | |
tree | d57ae82dab951f40cf30a051ac02ab7a79c3b440 /example/src/main.c | |
parent | 9f6eff69114a493047ffdf1bb6f0e3c86b2119aa (diff) | |
download | uv_link_t-3523bbda22a89eb0e64cd08958efa6cafd710c09.tar.gz |
src: simplify uv_link_close
Diffstat (limited to 'example/src/main.c')
-rw-r--r-- | example/src/main.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/example/src/main.c b/example/src/main.c index 01d0447..ac4c4a9 100644 --- a/example/src/main.c +++ b/example/src/main.c @@ -20,6 +20,13 @@ struct client_s { uv_link_observer_t observer; }; +static void close_cb(uv_link_t* link) { + client_t* client; + + client = link->data; + free(client); +} + static void read_cb(uv_link_observer_t* observer, ssize_t nread, const uv_buf_t* buf) { @@ -29,9 +36,7 @@ static void read_cb(uv_link_observer_t* observer, if (nread < 0) { fprintf(stderr, "error or close\n"); - uv_link_read_stop(&observer->link); - uv_close((uv_handle_t*) &client->tcp, NULL); - free(client); + uv_link_close(&observer->link, close_cb); return; } @@ -61,7 +66,10 @@ static void connection_cb(uv_stream_t* s, int status) { err = uv_link_chain(&client->source.link, &client->middle); assert(err == 0); - err = uv_link_observer_init(&client->observer, &client->middle); + err = uv_link_observer_init(&client->observer); + assert(err == 0); + + err = uv_link_chain(&client->middle, &client->observer.link); assert(err == 0); client->observer.read_cb = read_cb; |