usrsock:add done flag in usrsock_iovec_do
set done to true if all data in iovec array is copied Signed-off-by: liangchaozhong <liangchaozhong@xiaomi.com>
This commit is contained in:
parent
f9a9a02e3e
commit
cc426f8539
4 changed files with 17 additions and 10 deletions
|
@ -401,7 +401,7 @@ int usrsock_request(struct iovec *iov, unsigned int iovcnt)
|
|||
/* Copy request to buffer */
|
||||
|
||||
ret = usrsock_iovec_get(g_usrsock.in, sizeof(g_usrsock.in),
|
||||
iov, iovcnt, 0);
|
||||
iov, iovcnt, 0, NULL);
|
||||
if (ret <= 0)
|
||||
{
|
||||
return ret;
|
||||
|
|
|
@ -194,7 +194,7 @@ static ssize_t usrsockdev_read(FAR struct file *filep, FAR char *buffer,
|
|||
/* Copy request to user-space. */
|
||||
|
||||
rlen = usrsock_iovec_get(buffer, len, dev->req.iov, dev->req.iovcnt,
|
||||
dev->req.pos);
|
||||
dev->req.pos, NULL);
|
||||
if (rlen < 0)
|
||||
{
|
||||
/* Tried reading beyond buffer. */
|
||||
|
@ -263,7 +263,7 @@ static off_t usrsockdev_seek(FAR struct file *filep, off_t offset,
|
|||
/* Copy request to user-space. */
|
||||
|
||||
rlen = usrsock_iovec_get(NULL, 0, dev->req.iov, dev->req.iovcnt,
|
||||
pos);
|
||||
pos, NULL);
|
||||
if (rlen < 0)
|
||||
{
|
||||
/* Tried seek beyond buffer. */
|
||||
|
@ -484,7 +484,7 @@ static int usrsockdev_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
|||
|
||||
if (dev->req.iov != NULL &&
|
||||
!(usrsock_iovec_get(NULL, 0, dev->req.iov,
|
||||
dev->req.iovcnt, dev->req.pos) < 0))
|
||||
dev->req.iovcnt, dev->req.pos, NULL) < 0))
|
||||
{
|
||||
eventset |= POLLIN;
|
||||
}
|
||||
|
|
|
@ -266,7 +266,7 @@ begin_packed_struct struct usrsock_message_socket_event_s
|
|||
|
||||
ssize_t usrsock_iovec_get(FAR void *dst, size_t dstlen,
|
||||
FAR const struct iovec *iov, int iovcnt,
|
||||
size_t pos);
|
||||
size_t pos, FAR bool *done);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usrsock_iovec_put() - copy to iovec from buffer.
|
||||
|
|
|
@ -90,7 +90,7 @@ static struct usrsock_req_s g_usrsock_req =
|
|||
|
||||
static ssize_t usrsock_iovec_do(FAR void *srcdst, size_t srcdstlen,
|
||||
FAR struct iovec *iov, int iovcnt,
|
||||
size_t pos, bool from_iov)
|
||||
size_t pos, bool from_iov, FAR bool *done)
|
||||
{
|
||||
FAR uint8_t *ioout = srcdst;
|
||||
FAR uint8_t *iovbuf;
|
||||
|
@ -117,7 +117,8 @@ static ssize_t usrsock_iovec_do(FAR void *srcdst, size_t srcdstlen,
|
|||
{
|
||||
/* Position beyond iovec. */
|
||||
|
||||
return -EINVAL;
|
||||
total = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
iovbuf = iov->iov_base;
|
||||
|
@ -177,6 +178,12 @@ static ssize_t usrsock_iovec_do(FAR void *srcdst, size_t srcdstlen,
|
|||
}
|
||||
}
|
||||
|
||||
out:
|
||||
if (done)
|
||||
{
|
||||
*done = !srclen && !iovcnt;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
|
@ -586,10 +593,10 @@ ssize_t usrsock_response(FAR const char *buffer, size_t len,
|
|||
|
||||
ssize_t usrsock_iovec_get(FAR void *dst, size_t dstlen,
|
||||
FAR const struct iovec *iov, int iovcnt,
|
||||
size_t pos)
|
||||
size_t pos, FAR bool *done)
|
||||
{
|
||||
return usrsock_iovec_do(dst, dstlen, (FAR struct iovec *)iov, iovcnt,
|
||||
pos, true);
|
||||
pos, true, done);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -600,7 +607,7 @@ ssize_t usrsock_iovec_put(FAR struct iovec *iov, int iovcnt, size_t pos,
|
|||
FAR const void *src, size_t srclen)
|
||||
{
|
||||
return usrsock_iovec_do((FAR void *)src, srclen, iov, iovcnt,
|
||||
pos, false);
|
||||
pos, false, NULL);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
Loading…
Reference in a new issue