net/socket: add SO_RCVBUF support

Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an
2021-07-05 16:01:48 +08:00
committed by Xiang Xiao
parent a5bf47b93e
commit b901f22c27
8 changed files with 131 additions and 4 deletions
+63 -2
View File
@@ -131,9 +131,71 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
{
_SO_SETOPT(psock->s_options, option);
}
return OK;
}
return OK;
#if CONFIG_NET_RECV_BUFSIZE > 0
case SO_RCVBUF: /* Sets receive buffer size */
{
int buffersize;
/* Verify that option is the size of an 'int'. Should also check
* that 'value' is properly aligned for an 'int'
*/
if (value_len != sizeof(int))
{
return -EINVAL;
}
/* Get the value. Is the option being set or cleared? */
buffersize = *(FAR int *)value;
if (buffersize < 0 || buffersize > INT_MAX)
{
return -EINVAL;
}
net_lock();
#if defined(CONFIG_NET_TCP) && !defined(CONFIG_NET_TCP_NO_STACK)
if (psock->s_type == SOCK_STREAM)
{
FAR struct tcp_conn_s *conn;
conn = (FAR struct tcp_conn_s *)psock->s_conn;
/* Save the receive buffer size */
conn->rcv_bufs = buffersize;
}
else
#endif
#if defined(CONFIG_NET_UDP) && !defined(CONFIG_NET_UDP_NO_STACK)
if (psock->s_type == SOCK_DGRAM)
{
FAR struct udp_conn_s *conn;
conn = (FAR struct udp_conn_s *)psock->s_conn;
/* Save the receive buffer size */
conn->rcvbufs = buffersize;
}
else
#endif
{
net_unlock();
return -ENOPROTOOPT;
}
net_unlock();
return OK;
}
#endif
}
#ifdef CONFIG_NET_USRSOCK
@@ -274,7 +336,6 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
#endif
/* The following are not yet implemented */
case SO_RCVBUF: /* Sets receive buffer size */
case SO_RCVLOWAT: /* Sets the minimum number of bytes to input */
case SO_SNDBUF: /* Sets send buffer size */
case SO_SNDLOWAT: /* Sets the minimum number of bytes to output */