emit messages to stderr when write fails
[awesomized/libmemcached] / lib / memcached_stats.c
index 8a05dfd93a30d12c0d8d409906ac2b08c904b73e..867147591c195116773d2a62ce752232846d0919 100644 (file)
@@ -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);