aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/networking/streams/stream.c
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2014-01-21 17:36:38 +0100
committerMartin Willi <martin@revosec.ch>2014-01-22 15:34:53 +0100
commite49b299867989bbad677c9cc86c1e9be80d8ca2a (patch)
tree1b8fe3d45e4b3e97929a31b1c45aa837fb74601e /src/libstrongswan/networking/streams/stream.c
parenta40c66194ed82fa7c752c9fa5528d31692f6024a (diff)
downloadstrongswan-e49b299867989bbad677c9cc86c1e9be80d8ca2a.tar.bz2
strongswan-e49b299867989bbad677c9cc86c1e9be80d8ca2a.tar.xz
stream: Make sure no watcher callback is active while changing stream callbacks
When changing async callbacks on streams, we have to make sure the watcher callback is not currently active and has temporarily disabled callbacks. This could have been the case, as we didn't explicitly removed any pending watcher registration if both callbacks are NULL. By enforcing the watcher unregistration, we are sure the watcher callback is not active and currently is not mangling the callback hooks. This should make sure we avoid any races for the callback variables.
Diffstat (limited to 'src/libstrongswan/networking/streams/stream.c')
-rw-r--r--src/libstrongswan/networking/streams/stream.c17
1 files changed, 3 insertions, 14 deletions
diff --git a/src/libstrongswan/networking/streams/stream.c b/src/libstrongswan/networking/streams/stream.c
index 8ecb89fc9..f6fec0b4a 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);
}