diff options
author | Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> | 2017-08-04 18:14:26 +0300 |
---|---|---|
committer | Eric Blake <eblake@redhat.com> | 2017-08-30 13:00:38 -0500 |
commit | ba8456442b597848fb5585273c47de8476c3a0c1 (patch) | |
tree | e47b423473219963cbd52950618dc59f302f0b49 /nbd/client.c | |
parent | ab01df1fe21c013d1fd9e3f4c782430741c7dd33 (diff) | |
download | qemu-ba8456442b597848fb5585273c47de8476c3a0c1.zip qemu-ba8456442b597848fb5585273c47de8476c3a0c1.tar.gz qemu-ba8456442b597848fb5585273c47de8476c3a0c1.tar.bz2 |
nbd/client: refactor nbd_receive_reply
Refactor nbd_receive_reply to return 1 on success, 0 on eof, when no
data was read and <0 for other cases, because returned size of read
data is not actually used.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20170804151440.320927-4-vsementsov@virtuozzo.com>
[eblake: tweak function comments]
Signed-off-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'nbd/client.c')
-rw-r--r-- | nbd/client.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/nbd/client.c b/nbd/client.c index 4556056..f8c213b 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -914,11 +914,16 @@ ssize_t nbd_send_request(QIOChannel *ioc, NBDRequest *request) return nbd_write(ioc, buf, sizeof(buf), NULL); } -ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp) +/* nbd_receive_reply + * Returns 1 on success + * 0 on eof, when no data was read (errp is not set) + * negative errno on failure (errp is set) + */ +int nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp) { uint8_t buf[NBD_REPLY_SIZE]; uint32_t magic; - ssize_t ret; + int ret; ret = nbd_read_eof(ioc, buf, sizeof(buf), errp); if (ret <= 0) { @@ -948,6 +953,7 @@ ssize_t nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp) error_setg(errp, "invalid magic (got 0x%" PRIx32 ")", magic); return -EINVAL; } - return sizeof(buf); + + return 1; } |