--- svnup.c.orig 2013-04-09 16:03:01.000000000 +0600 +++ svnup.c 2013-04-10 20:13:40.000000000 +0600 @@ -211,26 +211,30 @@ croak(const char *error) void send_command(const char *command, connector * connection) { - int bytes_written, total_bytes_written, bytes_to_write; + size_t bytes_left; + ssize_t bytes_written; + const char *ptr; - if (command) { - total_bytes_written = 0; - bytes_to_write = strlen(command); + if (command && *command) { - if (connection->verbosity > 1) - fprintf(stdout, "==========\n<< Command: (%d bytes)\n%s", bytes_to_write, command); + ptr = command; + bytes_left = strlen(command); - while (total_bytes_written < bytes_to_write) { - bytes_written = -1; - while (bytes_written == -1) - bytes_written = write( - connection->socket_descriptor, - command + total_bytes_written, - strlen(command - total_bytes_written) - ); + if (connection->verbosity > 1) + fprintf(stdout, "==========\n<< Command: (%d bytes)\n%s", bytes_left, command); - total_bytes_written += bytes_written; + while (bytes_left > 0) { + if ((bytes_written = write(connection->socket_descriptor, ptr, bytes_left)) <= 0) { + if (bytes_written < 0 && errno == EINTR) + bytes_written = 0; /* and call write() + * again */ + else + croak("send_command(), write"); /* error */ + } + bytes_left -= bytes_written; + ptr += bytes_written; } + } } @@ -294,13 +298,17 @@ send_receive_command(const char *command do { bzero(input, BUFFER_UNIT + 1); - bytes_read = -1; - while (bytes_read == -1) - bytes_read = read( + if ((bytes_read = read( connection->socket_descriptor, input, BUFFER_UNIT - ); + )) < 0) + if (errno == EINTR) + continue; + else + croak("send_receive_command(), read"); + else if (bytes_read == 0) /* EOF */ + croak("send_receive_command(), read eof"); connection->response_length += bytes_read; @@ -1100,7 +1108,7 @@ main(int argc, char **argv) char *start, *value, *addr, *branch, *path_target; char temp_file [BUFFER_UNIT], command[COMMAND_BUFFER + 1]; int option , revision, port, family, x, x0, temp, revision_length; - int max_file , file_count, length; + int max_file , file_count, length, so_val; node **file; struct sockaddr_in sin; @@ -1199,7 +1207,16 @@ main(int argc, char **argv) if (connect(connection.socket_descriptor, (struct sockaddr *)&sin, sizeof(sin)) < 0) croak("connect failure"); - fcntl(connection.socket_descriptor, F_SETFL, O_NONBLOCK); + /* Tune up socket */ + + so_val = 1; + if (setsockopt(connection.socket_descriptor, SOL_SOCKET, SO_KEEPALIVE, &so_val, sizeof(int)) == -1) + croak("setsockopt(SO_KEEPALIVE)"); + so_val = COMMAND_BUFFER; + if (setsockopt(connection.socket_descriptor, SOL_SOCKET, SO_SNDBUF, &so_val, sizeof(int)) == -1) + croak("setsockopt(SO_SNDBUF)"); + if (setsockopt(connection.socket_descriptor, SOL_SOCKET, SO_RCVBUF, &so_val, sizeof(int)) == -1) + croak("setsockopt(SO_RCVBUF)"); connection.response_groups = 1; send_receive_command("", &connection);