Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
protocol: Refactor read_wire_data function
Browse files Browse the repository at this point in the history
Change the type of parameter "size" from size_t to ssize_t as this
really needs to be an unsigned value. Change the loop
to a while loop. Get rid of the casts in some of the calls to
read_wire_data.

Signed-off-by: Archana Shinde <[email protected]>
  • Loading branch information
amshinde committed May 25, 2017
1 parent 56b45ee commit e1e5c05
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,17 +331,17 @@ send_connect_command(struct cc_shim *shim)
*
* \return true on success, false otherwise
*/
bool read_wire_data(int fd, uint8_t *buf, ssize_t size)
bool read_wire_data(int fd, uint8_t *buf, size_t size)
{
ssize_t ret;
ssize_t offset = 0;
size_t offset = 0;

if ( fd < 0 || ! buf ) {
return false;
}

do {
ret = recv(fd, buf+offset, (size_t)(size-offset), 0);
while(offset < size) {
ret = recv(fd, buf+offset, size-offset, 0);
if (ret == 0) {
shim_error("Received EOF on file descriptor\n");
// TODO: Exit for now, add logic to try to reconnect
Expand All @@ -352,11 +352,8 @@ bool read_wire_data(int fd, uint8_t *buf, ssize_t size)
strerror(errno));
return false;
}
if (ret >= size) {
break;
}
offset += ret;
} while(1);
offset += (size_t)ret;
}

return true;
}
Expand Down Expand Up @@ -391,7 +388,7 @@ read_frame(struct cc_shim *shim)
abort();
}

if (! read_wire_data(shim->proxy_sock_fd, buf, (ssize_t)size)) {
if (! read_wire_data(shim->proxy_sock_fd, buf, size)) {
goto error;
}

Expand Down Expand Up @@ -423,7 +420,7 @@ read_frame(struct cc_shim *shim)
}

if (! read_wire_data(shim->proxy_sock_fd, buf + size,
(ssize_t)(header_size_in_bytes) - (ssize_t)size)) {
header_size_in_bytes - size)) {
shim_error("Error while reading frame from proxy at %s\n",
shim->proxy_address);
goto error;
Expand Down

0 comments on commit e1e5c05

Please sign in to comment.