added some comments on blocking-io
[rsync/rsync.git] / main.c
diff --git a/main.c b/main.c
index 0c4f2cd..2f422e2 100644 (file)
--- a/main.c
+++ b/main.c
@@ -324,9 +324,10 @@ static int do_recv(int f_in,int f_out,struct file_list *flist,char *local_name)
                write_int(recv_pipe[1],1);
                close(recv_pipe[1]);
                io_flush();
-               /* finally we go to sleep until our parent kills us with
-                  a USR2 signal */
-               while (1) sleep(60);
+               /* finally we go to sleep until our parent kills us
+                  with a USR2 signal. We sleepp for a short time as on
+                  some OSes a signal won't interrupt a sleep! */
+               while (1) sleep(1);
        }
 
        close(recv_pipe[1]);
@@ -417,6 +418,9 @@ void start_server(int f_in, int f_out, int argc, char *argv[])
 
        setup_protocol(f_out, f_in);
 
+       set_nonblocking(f_in);
+       set_nonblocking(f_out);
+
        if (remote_version >= 23)
                io_start_multiplex_out(f_out);
 
@@ -440,6 +444,9 @@ int client_run(int f_in, int f_out, int pid, int argc, char *argv[])
        extern int list_only;
        extern int remote_version;
 
+       set_nonblocking(f_in);
+       set_nonblocking(f_out);
+
        setup_protocol(f_out,f_in);
 
        if (remote_version >= 23)
@@ -695,6 +702,8 @@ int main(int argc,char *argv[])
 #endif
 
        if (am_server) {
+               set_nonblocking(STDIN_FILENO);
+               set_nonblocking(STDOUT_FILENO);
                start_server(STDIN_FILENO, STDOUT_FILENO, argc, argv);
        }