simplify osx_write_pre_select()
[paraslash.git] / dccp_send.c
index cfff309..bb46678 100644 (file)
@@ -34,7 +34,7 @@
 #include "fd.h"
 #include "close_on_fork.h"
 #include "server.cmdline.h"
-extern struct gengetopt_args_info conf;
+
 /** the list of connected clients **/
 static struct list_head clients;
 static int listen_fd = -1;
@@ -120,15 +120,22 @@ static void dccp_shutdown_client(struct dccp_client *dc)
        free(dc);
 }
 
+#define DCCP_RETRIES 100
+
 static int dccp_write(int fd, const char *buf, size_t len)
 {
-       size_t send, written = 0;
-       int ret;
+       size_t size, written = 0;
+       int ret, retries = 0;
 again:
-       send = PARA_MIN(1024, len - written);
-       ret = write(fd, buf + written, send);
-       if (ret < 0)
-               goto err_out;
+       size = PARA_MIN(1024, len - written);
+       ret = write(fd, buf + written, size);
+       if (ret < 0) {
+               if (errno != EAGAIN || !retries++ > DCCP_RETRIES)
+                       goto err_out;
+               PARA_DEBUG_LOG("EAGAIN #%d@%zd/%zd\n", retries, written, len);
+               goto again;
+       }
+       retries = 0;
        written += ret;
        if (written >= len)
                return written;