--- svnup.c.orig 2013-04-11 14:14:53.000000000 +0600 +++ svnup.c 2013-04-11 14:26:50.000000000 +0600 @@ -200,25 +200,26 @@ void 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); + ptr = command; + bytes_left = strlen(command); if (connection->verbosity > 1) - fprintf(stdout, "==========\n<< Command: (%d bytes)\n%s", bytes_to_write, command); + fprintf(stdout, "==========\n<< Command: (%d bytes)\n%s", bytes_left, 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) - ); - - 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; + else + croak("send_command(), write"); + } + bytes_left -= bytes_written; + ptr += bytes_written; } } } @@ -275,13 +276,15 @@ char *send_receive_command(const char *c 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 EOF"); connection->response_length += bytes_read; @@ -1056,7 +1059,7 @@ int 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; @@ -1134,7 +1137,17 @@ int 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);