net/usrsock: Combine some the duplicated logic.
This commit is contained in:
parent
67193ff5c4
commit
31b3dc6c27
5 changed files with 39 additions and 71 deletions
|
@ -255,6 +255,19 @@ void usrsock_teardown_request_callback(FAR struct usrsock_reqstate_s *pstate);
|
|||
#define usrsock_teardown_data_request_callback(datastate) \
|
||||
usrsock_teardown_request_callback(&(datastate)->reqstate)
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usrsock_setup_datain
|
||||
****************************************************************************/
|
||||
|
||||
void usrsock_setup_datain(FAR struct usrsock_conn_s *conn,
|
||||
FAR struct iovec *iov, unsigned int iovcnt);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usrsock_teardown_datain
|
||||
****************************************************************************/
|
||||
|
||||
#define usrsock_teardown_datain(conn) usrsock_setup_datain(conn, NULL, 0)
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usrsock_event
|
||||
*
|
||||
|
|
|
@ -306,6 +306,26 @@ void usrsock_teardown_request_callback(FAR struct usrsock_reqstate_s *pstate)
|
|||
pstate->cb = NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usrsock_setup_datain
|
||||
****************************************************************************/
|
||||
|
||||
void usrsock_setup_datain(FAR struct usrsock_conn_s *conn,
|
||||
FAR struct iovec *iov, unsigned int iovcnt)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
conn->resp.datain.iov = iov;
|
||||
conn->resp.datain.pos = 0;
|
||||
conn->resp.datain.total = 0;
|
||||
conn->resp.datain.iovcnt = iovcnt;
|
||||
|
||||
for (i = 0; i < iovcnt; i++)
|
||||
{
|
||||
conn->resp.datain.total += iov[i].iov_len;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usrsock_initialize()
|
||||
*
|
||||
|
|
|
@ -140,27 +140,6 @@ static int do_getsockname_request(FAR struct usrsock_conn_s *conn,
|
|||
return usrsockdev_do_request(conn, bufs, ARRAY_SIZE(bufs));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: setup_conn_getsockopt
|
||||
****************************************************************************/
|
||||
|
||||
static void setup_conn_getsockname(FAR struct usrsock_conn_s *conn,
|
||||
FAR struct iovec *iov,
|
||||
unsigned int iovcnt)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
conn->resp.datain.iov = iov;
|
||||
conn->resp.datain.pos = 0;
|
||||
conn->resp.datain.total = 0;
|
||||
conn->resp.datain.iovcnt = iovcnt;
|
||||
|
||||
for (i = 0; i < iovcnt; i++)
|
||||
{
|
||||
conn->resp.datain.total += iov[i].iov_len;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
@ -224,7 +203,7 @@ int usrsock_getsockname(FAR struct socket *psock,
|
|||
inbufs[0].iov_base = (FAR void *)addr;
|
||||
inbufs[0].iov_len = *addrlen;
|
||||
|
||||
setup_conn_getsockname(conn, inbufs, ARRAY_SIZE(inbufs));
|
||||
usrsock_setup_datain(conn, inbufs, ARRAY_SIZE(inbufs));
|
||||
|
||||
/* Request user-space daemon to close socket. */
|
||||
|
||||
|
@ -251,7 +230,7 @@ int usrsock_getsockname(FAR struct socket *psock,
|
|||
}
|
||||
}
|
||||
|
||||
setup_conn_getsockname(conn, NULL, 0);
|
||||
usrsock_teardown_datain(conn);
|
||||
usrsock_teardown_data_request_callback(&state);
|
||||
|
||||
errout_unlock:
|
||||
|
|
|
@ -150,26 +150,6 @@ static int do_getsockopt_request(FAR struct usrsock_conn_s *conn, int level,
|
|||
return usrsockdev_do_request(conn, bufs, ARRAY_SIZE(bufs));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: setup_conn_getsockopt
|
||||
****************************************************************************/
|
||||
|
||||
static void setup_conn_getsockopt(FAR struct usrsock_conn_s *conn,
|
||||
FAR struct iovec *iov, unsigned int iovcnt)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
conn->resp.datain.iov = iov;
|
||||
conn->resp.datain.pos = 0;
|
||||
conn->resp.datain.total = 0;
|
||||
conn->resp.datain.iovcnt = iovcnt;
|
||||
|
||||
for (i = 0; i < iovcnt; i++)
|
||||
{
|
||||
conn->resp.datain.total += iov[i].iov_len;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
@ -235,7 +215,7 @@ int usrsock_getsockopt(FAR struct usrsock_conn_s *conn, int level, int option,
|
|||
inbufs[0].iov_base = (FAR void *)value;
|
||||
inbufs[0].iov_len = *value_len;
|
||||
|
||||
setup_conn_getsockopt(conn, inbufs, ARRAY_SIZE(inbufs));
|
||||
usrsock_setup_datain(conn, inbufs, ARRAY_SIZE(inbufs));
|
||||
|
||||
/* Request user-space daemon to close socket. */
|
||||
|
||||
|
@ -261,7 +241,7 @@ int usrsock_getsockopt(FAR struct usrsock_conn_s *conn, int level, int option,
|
|||
}
|
||||
}
|
||||
|
||||
setup_conn_getsockopt(conn, NULL, 0);
|
||||
usrsock_teardown_datain(conn);
|
||||
usrsock_teardown_data_request_callback(&state);
|
||||
|
||||
errout_unlock:
|
||||
|
|
|
@ -187,30 +187,6 @@ static int do_recvfrom_request(FAR struct usrsock_conn_s *conn, size_t buflen,
|
|||
return usrsockdev_do_request(conn, bufs, ARRAY_SIZE(bufs));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: setup_conn_recvfrom
|
||||
****************************************************************************/
|
||||
|
||||
static void setup_conn_recvfrom(FAR struct usrsock_conn_s *conn,
|
||||
FAR struct iovec *iov, unsigned int iovcnt)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
conn->resp.datain.iov = iov;
|
||||
conn->resp.datain.pos = 0;
|
||||
conn->resp.datain.total = 0;
|
||||
conn->resp.datain.iovcnt = iovcnt;
|
||||
|
||||
for (i = 0; i < iovcnt; i++)
|
||||
{
|
||||
conn->resp.datain.total += iov[i].iov_len;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usrsock_recvfrom
|
||||
*
|
||||
|
@ -433,7 +409,7 @@ ssize_t usrsock_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
|||
inbufs[1].iov_base = (FAR void *)buf;
|
||||
inbufs[1].iov_len = len;
|
||||
|
||||
setup_conn_recvfrom(conn, inbufs, ARRAY_SIZE(inbufs));
|
||||
usrsock_setup_datain(conn, inbufs, ARRAY_SIZE(inbufs));
|
||||
|
||||
/* Request user-space daemon to close socket. */
|
||||
|
||||
|
@ -462,7 +438,7 @@ ssize_t usrsock_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
|||
}
|
||||
}
|
||||
|
||||
setup_conn_recvfrom(conn, NULL, 0);
|
||||
usrsock_teardown_datain(conn);
|
||||
usrsock_teardown_data_request_callback(&state);
|
||||
}
|
||||
while (ret == -EAGAIN);
|
||||
|
|
Loading…
Reference in a new issue