Index: src/vortex_channel.c =================================================================== --- src/vortex_channel.c (revision 3394) +++ src/vortex_channel.c (working copy) @@ -173,6 +173,15 @@ int window_size; + + /* desired_window_size + * + * This value tracks changes the client has requested in the + * window_size. The actual window_size will not be adjusted until + * the current window fills up and a new SEQ frame is sent. */ + int desired_window_size; + + bool complete_flag; axlList * previous_frame; @@ -1382,6 +1391,7 @@ channel->profile = axl_strdup (profile); channel->connection = connection; channel->window_size = 4096; + channel->desired_window_size = 4096; /* Attention commander: the following two values *must* be * 4095 because they represent the maximum seq no value * accepted at the channel start up, which is the same to say, @@ -2795,6 +2805,30 @@ } /** + * @brief Allows the caller to change the channel window size. + * + * A larger window size than the default (4096) allows the remote peer + * to send more data over this channel at once. This increases the + * bandwidth that can be received, especially over high-latency sockets, + * at the expense of increasing the latency for other channels. + * + * (The window size divided by the socket's bandwidth in bytes per second + * represents the maximum amount of time that the channel is allowed + * to "hog" the socket, keeping other channels waiting.) + * + * @param channel the channel to operate on. + * @param desired_size the desired window size; must be at least 4096. + */ +void vortex_channel_set_window_size (VortexChannel * channel, + int desired_size) +{ + v_return_if_fail (channel); + v_return_if_fail (desired_size >= 4096); + + channel->desired_window_size = desired_size; +} + +/** * @brief Returns current mime type used for messages exchange perform * on the given channel. * @@ -3001,6 +3035,14 @@ * configured to be smaller. */ if (new_max_seq_no_accepted > channel->max_seq_no_accepted) { + /* if the client wants to change the channel window size, do so now */ + if (window_size != channel->desired_window_size) { + vortex_log (LOG_DOMAIN, VORTEX_LEVEL_DEBUG, "SEQ FRAME: Changing window size from %d to %d", + window_size,channel->desired_window_size); + window_size = channel->window_size = channel->desired_window_size; + new_max_seq_no_accepted = (consumed_seqno + window_size - 1) % (MAX_SEQ_NO); + } + vortex_log (LOG_DOMAIN, VORTEX_LEVEL_DEBUG, "SEQ FRAME: updating allowed max seq no to be received from %d to %d (delta: %d)", channel->max_seq_no_accepted, new_max_seq_no_accepted, Index: src/vortex_channel.h =================================================================== --- src/vortex_channel.h (revision 3394) +++ src/vortex_channel.h (working copy) @@ -148,6 +148,9 @@ int vortex_channel_get_window_size (VortexChannel * channel); +void vortex_channel_set_window_size (VortexChannel * channel, + int desired_size); + const char * vortex_channel_get_mime_type (VortexChannel * channel); const char * vortex_channel_get_transfer_encoding (VortexChannel * channel); Index: src/vortex_frame_factory.c =================================================================== --- src/vortex_frame_factory.c (revision 3394) +++ src/vortex_frame_factory.c (working copy) @@ -659,7 +659,7 @@ * @param buffer buffer to hold data. * @param maxlen * - * @return how many bytes were read. + * @return how many bytes were read, or 0 if no data is available, or -1 on a socket error */ int vortex_frame_receive_raw (VortexConnection * connection, char * buffer, int maxlen) { @@ -679,12 +679,14 @@ error_msg = vortex_errno_get_last_error (); vortex_log (LOG_DOMAIN, VORTEX_LEVEL_CRITICAL, "unable to readn=%d, error was: %s", maxlen, error_msg ? error_msg : ""); + } else if (nread == -2 ) { + return 0; } /* ensure we don't access outside the array */ if (nread < 0) - nread = 0; - + buffer[0] = 0; + else buffer[nread] = 0; return nread; } @@ -874,7 +876,7 @@ vortex_log (LOG_DOMAIN, VORTEX_LEVEL_DEBUG, "bytes already read: %d", bytes_read); bytes_read = vortex_frame_receive_raw (connection, buffer + bytes_read, remaining); - if (bytes_read == 0) { + if (bytes_read < 0) { vortex_frame_free (frame); axl_free (buffer); vortex_connection_set_data (connection, "buffer", NULL); @@ -1041,7 +1043,7 @@ /* read the next frame content */ bytes_read = vortex_frame_receive_raw (connection, buffer, frame->size + 5); - if (bytes_read == 0) { + if (bytes_read < 0) { vortex_log (LOG_DOMAIN, VORTEX_LEVEL_CRITICAL, "remote peer have closed connection while reading the rest of the frame"); __vortex_connection_set_not_connected (connection, "remote peer have closed connection while reading the rest of the frame"); Index: src/vortex_tunnel.c =================================================================== --- src/vortex_tunnel.c (revision 3394) +++ src/vortex_tunnel.c (working copy) @@ -752,7 +752,7 @@ read = vortex_frame_receive_raw (connection, buffer, MAX_BUFFER_SIZE - 2); /* check data read */ - if (read == 0) { + if (read <= 0) { vortex_log (LOG_DOMAIN, VORTEX_LEVEL_DEBUG, "TUNNEL, nothing read from the connection(%s:%s) close connection", vortex_connection_get_host (connection), vortex_connection_get_port (connection));