Patch to avoid 'Connection reset by peer' error for rsync on cygwin

Max Bowsher maxb at ukf.net
Wed Apr 3 20:39:57 EST 2002


The problem is caused because rsync does not close its sockets, and WinSock is a
quite strict on this. The solution is to shutdown and close the fd.
This is a 5-minute hack I've done to fix the obvious occurrences of the problem.
It might be better to extend rsyncs cleanup functions for this, but here it is
anyway to alert people to the problem and its fix.

Max.

BEGIN PATCH
diff -mru rsync-2.5.5/clientserver.c rsync-2.5.5-tweaked/clientserver.c
--- rsync-2.5.5/clientserver.c Wed Mar 27 01:03:13 2002
+++ rsync-2.5.5-tweaked/clientserver.c Wed Apr  3 11:01:57 2002
@@ -486,39 +486,44 @@
  }

  if (!read_line(fd, line, sizeof(line)-1)) {
-  return -1;
+  goto exitwithnomodule;
  }

  if (sscanf(line,"@RSYNCD: %d", &remote_version) != 1) {
   io_printf(fd,"@ERROR: protocol startup error\n");
-  return -1;
+  goto exitwithnomodule;
  }

  while (i == -1) {
   line[0] = 0;
   if (!read_line(fd, line, sizeof(line)-1)) {
-   return -1;
+   goto exitwithnomodule;
   }

   if (!*line || strcmp(line,"#list")==0) {
    send_listing(fd);
-   return -1;
+   goto exitwithnomodule;
   }

   if (*line == '#') {
    /* it's some sort of command that I don't understand */
    io_printf(fd,"@ERROR: Unknown command '%s'\n", line);
-   return -1;
+   goto exitwithnomodule;
   }

   i = lp_number(line);
   if (i == -1) {
    io_printf(fd,"@ERROR: Unknown module '%s'\n", line);
-   return -1;
+   goto exitwithnomodule;
   }
  }

  return rsync_module(fd, i);
+
+exitwithnomodule:
+ shutdown(fd,SHUT_WR);
+ close(fd);
+ return -1;
 }


END PATCH







More information about the rsync mailing list