Skip to content

Commit

Permalink
Add yrmcds_cnt_shutdown() to interrupt yrmcds_cnt_recv().
Browse files Browse the repository at this point in the history
  • Loading branch information
ymmt2005 committed Jan 29, 2015
1 parent d142e03 commit ed6ee91
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions counter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions yrmcds.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ed6ee91

Please sign in to comment.