diff -Nurd -X freeciv/diff_ignore freeciv.current/client/clinet.c extra_write1/client/clinet.c --- freeciv.current/client/clinet.c Tue Aug 7 15:53:09 2001 +++ extra_write1/client/clinet.c Sat Aug 11 12:38:16 2001 @@ -20,6 +20,7 @@ #include #include #include +#include #ifdef HAVE_UNISTD_H #include @@ -195,12 +196,61 @@ } /************************************************************************** +A wrapper around read_socket_data() which also handles the case the +socket becomes writeable and there is still data which should be sent +to the server. +**************************************************************************/ +static int read_from_connection() +{ + for (;;) { + fd_set readfs, writefs; + int socket_fd = aconnection.sock; + int have_data_for_server = (aconnection.used && aconnection.send_buffer + && aconnection.send_buffer->ndata); + int n; + + MY_FD_ZERO(&readfs); + FD_SET(socket_fd, &readfs); + + if (have_data_for_server) { + MY_FD_ZERO(&writefs); + FD_SET(socket_fd, &writefs); + n = select(socket_fd + 1, &readfs, &writefs, NULL, NULL); + } else { + n = select(socket_fd + 1, &readfs, NULL, NULL, NULL); + } + + /* no timeout expected */ + assert(n != 0); + + if (n == -1) { + if (errno == EINTR) { + freelog(LOG_DEBUG, "select() returned EINTR"); + continue; + } + + freelog(LOG_NORMAL, "error in select() return=%d errno=%d (%s)", + n, errno, strerror(errno)); + return -1; + } + + if (FD_ISSET(socket_fd, &writefs)) { + flush_connection_send_buffer_all(&aconnection); + } + + if (FD_ISSET(socket_fd, &readfs)) { + return read_socket_data(socket_fd, aconnection.buffer); + } + } +} + +/************************************************************************** This function is called when the client received a new input from the server **************************************************************************/ void input_from_server(int fid) { - if(read_socket_data(fid, aconnection.buffer)>=0) { + if(read_from_connection()>=0) { int type, result; char *packet;