cleaner tryread()
parent
ef165ee7ea
commit
be18d7193a
|
@ -196,21 +196,18 @@ static int sendmessage(enum at_direction dir, struct at_msg *msg) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tryread(int fd, void* buf, size_t bytes) {
|
static int tryread(int fd, void *vbuf, size_t bytes) {
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
unsigned char *out = buf;
|
unsigned char *buf = vbuf;
|
||||||
again:
|
|
||||||
ret = read(fd, out, bytes);
|
for(;;) {
|
||||||
switch(ret) {
|
ret = read(fd, buf, bytes);
|
||||||
case -1:
|
if (ret == -1 && errno != EINTR)
|
||||||
if(errno == EINTR) goto again;
|
|
||||||
case 0:
|
|
||||||
return 0;
|
return 0;
|
||||||
default:
|
else if (ret == bytes)
|
||||||
if(ret == bytes || !bytes) return 1;
|
return 1;
|
||||||
out += ret;
|
buf += ret;
|
||||||
bytes -= ret;
|
bytes -= ret;
|
||||||
goto again;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue