X-Git-Url: https://git.strongswan.org/?p=strongswan.git;a=blobdiff_plain;f=src%2Flibstrongswan%2Fnetworking%2Fstreams%2Fstream.c;h=f6fec0b4a4d99723b07b49286fefd59ff07c951d;hp=b3dd7680b256fb9a127bfd4a1147508099e6e0af;hb=e49b2998;hpb=666dff70ebeaeccab58299cba7740b6be7de0b0c diff --git a/src/libstrongswan/networking/streams/stream.c b/src/libstrongswan/networking/streams/stream.c index b3dd768..f6fec0b 100644 --- a/src/libstrongswan/networking/streams/stream.c +++ b/src/libstrongswan/networking/streams/stream.c @@ -159,17 +159,6 @@ METHOD(stream_t, write_all, bool, } /** - * Remove a registered watcher - */ -static void remove_watcher(private_stream_t *this) -{ - if (this->read_cb || this->write_cb) - { - lib->watcher->remove(lib->watcher, this->fd); - } -} - -/** * Watcher callback */ static bool watch(private_stream_t *this, int fd, watcher_event_t event) @@ -228,7 +217,7 @@ static void add_watcher(private_stream_t *this) METHOD(stream_t, on_read, void, private_stream_t *this, stream_cb_t cb, void *data) { - remove_watcher(this); + lib->watcher->remove(lib->watcher, this->fd); this->read_cb = cb; this->read_data = data; @@ -239,7 +228,7 @@ METHOD(stream_t, on_read, void, METHOD(stream_t, on_write, void, private_stream_t *this, stream_cb_t cb, void *data) { - remove_watcher(this); + lib->watcher->remove(lib->watcher, this->fd); this->write_cb = cb; this->write_data = data; @@ -270,7 +259,7 @@ METHOD(stream_t, get_file, FILE*, METHOD(stream_t, destroy, void, private_stream_t *this) { - remove_watcher(this); + lib->watcher->remove(lib->watcher, this->fd); close(this->fd); free(this); } @@ -313,6 +302,7 @@ int stream_parse_uri_unix(char *uri, struct sockaddr_un *addr) memset(addr, 0, sizeof(*addr)); addr->sun_family = AF_UNIX; strncpy(addr->sun_path, uri, sizeof(addr->sun_path)); + addr->sun_path[sizeof(addr->sun_path)-1] = '\0'; return offsetof(struct sockaddr_un, sun_path) + strlen(addr->sun_path); }