X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Futils%2Fchannel.c;h=c72953e956911b9e69ffc6ab44889283c5d319b7;hb=c9a8aeb13d617c36e5ef71d6abf8223ac91fcdb1;hp=8e55ae564872f1052494f78ddd62658b40d48394;hpb=bed406a8fce9eb683059a3138dd33e4cf7bd71cd;p=sysdb.git diff --git a/src/utils/channel.c b/src/utils/channel.c index 8e55ae5..c72953e 100644 --- a/src/utils/channel.c +++ b/src/utils/channel.c @@ -25,12 +25,16 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#if HAVE_CONFIG_H +# include "config.h" +#endif /* HAVE_CONFIG_H */ + #include "utils/channel.h" #include - #include +#include #include #include @@ -56,7 +60,9 @@ struct sdb_channel { size_t head; size_t tail; - _Bool full; + bool full; + + bool shutdown; }; /* @@ -79,7 +85,7 @@ channel_write(sdb_channel_t *chan, const void *data) { assert(chan); - if (chan->full) + if (chan->full || chan->shutdown) return -1; else if (! data) return 0; @@ -199,6 +205,12 @@ sdb_channel_select(sdb_channel_t *chan, int *wantread, void *read_data, break; } + if (chan->shutdown) { + if (read_status) + status = EBADF; + break; + } + if (timeout) { struct timespec abstime; @@ -258,5 +270,14 @@ sdb_channel_read(sdb_channel_t *chan, void *data) return status; } /* sdb_channel_read */ +int +sdb_channel_shutdown(sdb_channel_t *chan) +{ + if (! chan) + return -1; + chan->shutdown = 1; + return 0; +} /* sdb_channel_shutdown */ + /* vim: set tw=78 sw=4 ts=4 noexpandtab : */