Skip to content

Commit

Permalink
fix read return 0
Browse files Browse the repository at this point in the history
  • Loading branch information
bg6cq committed Jun 22, 2012
1 parent 28d18d5 commit e5d702a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions hpfdcli/hpfdcli.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,18 @@ UNKNOWN } cmd_t;
u_char *read_msg(int s) {
u_char *buffer;
u_int32_t msglen;
int len;

if (read(s, &msglen, 4) == -1) {
perror("read()");
exit(EXIT_FAILURE);
while (1) {
len = read(s, &msglen, 4);
if (len == -1) {
perror("read()");
exit(EXIT_FAILURE);
}
if (len == 0) continue;
if (len >0 ) break;
}

if ((buffer = malloc(msglen)) == NULL) {
perror("malloc()");
exit(EXIT_FAILURE);
Expand Down Expand Up @@ -308,7 +314,6 @@ int main(int argc, char *argv[]) {
close(s);
return EXIT_SUCCESS;
}
printf("read %d, ",len);
if(buf[len - 1] == '\n') {
buf[len - 1] = 0;
len --;
Expand Down

0 comments on commit e5d702a

Please sign in to comment.