From ed6ee918cdb69743a228daa23f09736b8af7da8c Mon Sep 17 00:00:00 2001 From: ymmt Date: Thu, 29 Jan 2015 11:20:39 +0900 Subject: [PATCH] Add yrmcds_cnt_shutdown() to interrupt yrmcds_cnt_recv(). --- counter.c | 9 +++++++++ yrmcds.h | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/counter.c b/counter.c index ee2ff87..d40045f 100644 --- a/counter.c +++ b/counter.c @@ -78,6 +78,15 @@ yrmcds_cnt_close(yrmcds_cnt* c) { return YRMCDS_OK; } +yrmcds_error +yrmcds_cnt_shutdown(yrmcds_cnt* c) { + if( c == NULL ) + return YRMCDS_BAD_ARGUMENT; + if( shutdown(c->sock, SHUT_RD) == -1 ) + return YRMCDS_SYSTEM_ERROR; + return YRMCDS_OK; +} + int yrmcds_cnt_fileno(yrmcds_cnt* c) { return c->sock; diff --git a/yrmcds.h b/yrmcds.h index c182052..c6a62f2 100644 --- a/yrmcds.h +++ b/yrmcds.h @@ -880,6 +880,21 @@ yrmcds_cnt_connect(yrmcds_cnt* c, const char* node, uint16_t port); yrmcds_error yrmcds_cnt_close(yrmcds_cnt* c); +/** + * Shutdown the receiving end of the socket. + * @param c A pointer to ::yrmcds_cnt. + * @return 0 if \p c is valid. Other values indicate an error. + * + * This function simply calls \p shutdown system call with \p SHUT_RD . + * This can be used to interrupt a thread waiting in ::yrmcds_cnt_recv. + * + * Note that interrupted ::yrmcds_cnt_recv will return ::YRMCDS_DISCONNECTED. + * + * \see https://github.com/cybozu/libyrmcds/issues/8 + */ +yrmcds_error +yrmcds_cnt_shutdown(yrmcds_cnt* c); + /** * Return the underlying socket in ::yrmcds_cnt. * @param c A pointer to ::yrmcds_cnt.