diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/vlibmemory/socket_client.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/vlibmemory/socket_client.c b/src/vlibmemory/socket_client.c index bf6861b1ea9..5fa19c6a9c0 100644 --- a/src/vlibmemory/socket_client.c +++ b/src/vlibmemory/socket_client.c @@ -87,12 +87,11 @@ vl_socket_client_read_internal (socket_client_main_t * scm, int wait) while (1) { - while (vec_len (scm->socket_rx_buffer) < sizeof (*mbp)) + current_rx_index = vec_len (scm->socket_rx_buffer); + while (current_rx_index < sizeof (*mbp)) { - current_rx_index = vec_len (scm->socket_rx_buffer); vec_validate (scm->socket_rx_buffer, current_rx_index + scm->socket_buffer_size - 1); - vec_set_len (scm->socket_rx_buffer, current_rx_index); n = read (scm->socket_fd, scm->socket_rx_buffer + current_rx_index, scm->socket_buffer_size); if (n < 0) @@ -101,10 +100,12 @@ vl_socket_client_read_internal (socket_client_main_t * scm, int wait) continue; clib_unix_warning ("socket_read"); + vec_set_len (scm->socket_rx_buffer, current_rx_index); return -1; } - vec_inc_len (scm->socket_rx_buffer, n); + current_rx_index += n; } + vec_set_len (scm->socket_rx_buffer, current_rx_index); #if CLIB_DEBUG > 1 if (n > 0) @@ -115,25 +116,25 @@ vl_socket_client_read_internal (socket_client_main_t * scm, int wait) data_len = ntohl (mbp->data_len); current_rx_index = vec_len (scm->socket_rx_buffer); vec_validate (scm->socket_rx_buffer, current_rx_index + data_len); - vec_set_len (scm->socket_rx_buffer, current_rx_index); mbp = (msgbuf_t *) (scm->socket_rx_buffer); msg_size = data_len + sizeof (*mbp); - while (vec_len (scm->socket_rx_buffer) < msg_size) + while (current_rx_index < msg_size) { - n = read (scm->socket_fd, - scm->socket_rx_buffer + vec_len (scm->socket_rx_buffer), - msg_size - vec_len (scm->socket_rx_buffer)); + n = read (scm->socket_fd, scm->socket_rx_buffer + current_rx_index, + msg_size - current_rx_index); if (n < 0) { if (errno == EAGAIN) continue; clib_unix_warning ("socket_read"); + vec_set_len (scm->socket_rx_buffer, current_rx_index); return -1; } - vec_inc_len (scm->socket_rx_buffer, n); + current_rx_index += n; } + vec_set_len (scm->socket_rx_buffer, current_rx_index); if (vec_len (scm->socket_rx_buffer) >= data_len + sizeof (*mbp)) { |