From: Mark Atwood Date: Sat, 22 Sep 2007 22:46:56 +0000 (-0700) Subject: emit messages to stderr when write fails X-Git-Tag: 0.2~8^2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=557de9b08007dd2b482778ba934574bcf7ee531f;p=m6w6%2Flibmemcached emit messages to stderr when write fails --- diff --git a/lib/memcached_auto.c b/lib/memcached_auto.c index 86ee7669..70c72999 100644 --- a/lib/memcached_auto.c +++ b/lib/memcached_auto.c @@ -24,10 +24,18 @@ static memcached_return memcached_auto(memcached_st *ptr, offset); if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE) return MEMCACHED_WRITE_FAILURE; - if ((sent_length= write(ptr->hosts[server_key].fd, buffer, send_length) == -1)) + sent_length= write(ptr->hosts[server_key].fd, buffer, send_length); + if (sent_length == -1) + { + fprintf(stderr, "error %s: write: %m\n", __FUNCTION__); return MEMCACHED_WRITE_FAILURE; + } if (sent_length != send_length) + { + fprintf(stderr, "error %s: short write %d %d: %m\n", + __FUNCTION__, sent_length, send_length); return MEMCACHED_WRITE_FAILURE; + } memset(buffer, 0, MEMCACHED_DEFAULT_COMMAND_SIZE); send_length= read(ptr->hosts[server_key].fd, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE); diff --git a/lib/memcached_delete.c b/lib/memcached_delete.c index 11b22ece..75087bd4 100644 --- a/lib/memcached_delete.c +++ b/lib/memcached_delete.c @@ -26,10 +26,20 @@ memcached_return memcached_delete(memcached_st *ptr, char *key, size_t key_lengt if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE) return MEMCACHED_WRITE_FAILURE; - if ((sent_length = write(ptr->hosts[server_key].fd, buffer, send_length) == -1)) + sent_length= write(ptr->hosts[server_key].fd, buffer, send_length); + + if (sent_length == -1) + { + fprintf(stderr, "error %s: write: %m\n", __FUNCTION__); return MEMCACHED_WRITE_FAILURE; + } + if (sent_length != send_length) + { + fprintf(stderr, "error %s: short write %d %d: %m\n", + __FUNCTION__, sent_length, send_length); return MEMCACHED_WRITE_FAILURE; + } return memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, server_key); } diff --git a/lib/memcached_flush.c b/lib/memcached_flush.c index 4ca73e30..07fc3ac0 100644 --- a/lib/memcached_flush.c +++ b/lib/memcached_flush.c @@ -24,10 +24,20 @@ memcached_return memcached_flush(memcached_st *ptr, time_t expiration) if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE) return MEMCACHED_WRITE_FAILURE; - if ((sent_length= write(ptr->hosts[x].fd, buffer, send_length) == -1)) + sent_length= write(ptr->hosts[x].fd, buffer, send_length); + + if (sent_length == -1) + { + fprintf(stderr, "error %s: write: %m\n", __FUNCTION__); return MEMCACHED_WRITE_FAILURE; + } + if (sent_length != send_length) + { + fprintf(stderr, "error %s: short write %d %d: %m\n", + __FUNCTION__, sent_length, send_length); return MEMCACHED_WRITE_FAILURE; + } rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, x); diff --git a/lib/memcached_get.c b/lib/memcached_get.c index 9eb60e26..560a50de 100644 --- a/lib/memcached_get.c +++ b/lib/memcached_get.c @@ -22,14 +22,24 @@ char *memcached_get(memcached_st *ptr, char *key, size_t key_length, (int)key_length, key); if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE) - return MEMCACHED_WRITE_FAILURE; + { + *error= MEMCACHED_WRITE_FAILURE; + return NULL; + } - if ((sent_length = write(ptr->hosts[server_key].fd, buffer, send_length) == -1)) + sent_length= write(ptr->hosts[server_key].fd, buffer, send_length); + + if (sent_length == -1) { + fprintf(stderr, "error %s: write: %m\n", __FUNCTION__); *error= MEMCACHED_WRITE_FAILURE; return NULL; } - if (sent_length != send_length) { + + if (sent_length != send_length) + { + fprintf(stderr, "error %s: short write %d %d: %m\n", + __FUNCTION__, sent_length, send_length); *error= MEMCACHED_WRITE_FAILURE; return NULL; } diff --git a/lib/memcached_stats.c b/lib/memcached_stats.c index 8a05dfd9..86714759 100644 --- a/lib/memcached_stats.c +++ b/lib/memcached_stats.c @@ -139,15 +139,20 @@ static memcached_return memcached_stats_fetch(memcached_st *ptr, if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE) return MEMCACHED_WRITE_FAILURE; - if ((sent_length= write(ptr->hosts[server_key].fd, buffer, send_length) == -1)) - { - fprintf(stderr, "failed on stats\n"); + sent_length= write(ptr->hosts[server_key].fd, buffer, send_length); + if (sent_length == -1) + { + fprintf(stderr, "error %s: write: %m\n", __FUNCTION__); return MEMCACHED_WRITE_FAILURE; } + if (sent_length != send_length) + { + fprintf(stderr, "error %s: short write %d %d: %m\n", + __FUNCTION__, sent_length, send_length); return MEMCACHED_WRITE_FAILURE; - + } rc= memcached_response(ptr, buffer, HUGE_STRING_LEN, 0); diff --git a/lib/memcached_verbosity.c b/lib/memcached_verbosity.c index ecea6f22..55a51842 100644 --- a/lib/memcached_verbosity.c +++ b/lib/memcached_verbosity.c @@ -21,10 +21,20 @@ memcached_return memcached_verbosity(memcached_st *ptr, unsigned int verbosity) { memcached_return rc; - if ((sent_length= write(ptr->hosts[x].fd, buffer, send_length) == -1)) + sent_length= write(ptr->hosts[x].fd, buffer, send_length); + + if (sent_length == -1) + { + fprintf(stderr, "error %s: write: %m\n", __FUNCTION__); return MEMCACHED_WRITE_FAILURE; + } + if (sent_length != send_length) + { + fprintf(stderr, "error %s: short write %d %d: %m\n", + __FUNCTION__, sent_length, send_length); return MEMCACHED_WRITE_FAILURE; + } rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, x); diff --git a/src/memflush.c b/src/memflush.c index 474fb47e..95e3e986 100644 --- a/src/memflush.c +++ b/src/memflush.c @@ -27,8 +27,8 @@ int main(int argc, char *argv[]) rc = memcached_flush(memc, opt_expire); if (rc != MEMCACHED_SUCCESS) { - fprintf(stderr, "memflush: %s: memcache error %s\n", - argv[optind], memcached_strerror(memc, rc)); + fprintf(stderr, "memflush: memcache error %s\n", + memcached_strerror(memc, rc)); } memcached_deinit(memc);