mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 23:40:19 +08:00
net/socket: add SOCK_CLOEXEC/SOCK_NONBLOCK support
Reference here: https://github.com/torvalds/linux/blob/master/include/linux/net.h Change-Id: I9fd0170bcd1ae7e778e951d454ada76f63854de5 Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
@@ -108,6 +108,16 @@
|
|||||||
*/
|
*/
|
||||||
#define SOCK_PACKET 10 /* Obsolete and should not be used in new programs */
|
#define SOCK_PACKET 10 /* Obsolete and should not be used in new programs */
|
||||||
|
|
||||||
|
#define SOCK_CLOEXEC 02000000 /* Atomically set close-on-exec flag for the new
|
||||||
|
* descriptor(s).
|
||||||
|
*/
|
||||||
|
#define SOCK_NONBLOCK 00004000 /* Atomically mark descriptor(s) as non-blocking. */
|
||||||
|
|
||||||
|
#define SOCK_MAX (SOCK_PACKET + 1)
|
||||||
|
#define SOCK_TYPE_MASK 0xf /* Mask which covers at least up to SOCK_MASK-1.
|
||||||
|
* The remaining bits are used as flags.
|
||||||
|
*/
|
||||||
|
|
||||||
/* Bits in the FLAGS argument to `send', `recv', et al. These are the bits
|
/* Bits in the FLAGS argument to `send', `recv', et al. These are the bits
|
||||||
* recognized by Linux, not all are supported by NuttX.
|
* recognized by Linux, not all are supported by NuttX.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+13
-1
@@ -86,12 +86,24 @@ int psock_socket(int domain, int type, int protocol,
|
|||||||
|
|
||||||
psock->s_crefs = 1;
|
psock->s_crefs = 1;
|
||||||
psock->s_domain = domain;
|
psock->s_domain = domain;
|
||||||
psock->s_type = type;
|
|
||||||
psock->s_conn = NULL;
|
psock->s_conn = NULL;
|
||||||
#if defined(CONFIG_NET_TCP_WRITE_BUFFERS) || defined(CONFIG_NET_UDP_WRITE_BUFFERS)
|
#if defined(CONFIG_NET_TCP_WRITE_BUFFERS) || defined(CONFIG_NET_UDP_WRITE_BUFFERS)
|
||||||
psock->s_sndcb = NULL;
|
psock->s_sndcb = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (type & SOCK_CLOEXEC)
|
||||||
|
{
|
||||||
|
psock->s_flags |= _SF_CLOEXEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type & SOCK_NONBLOCK)
|
||||||
|
{
|
||||||
|
psock->s_flags |= _SF_NONBLOCK;
|
||||||
|
}
|
||||||
|
|
||||||
|
type &= SOCK_TYPE_MASK;
|
||||||
|
psock->s_type = type;
|
||||||
|
|
||||||
#ifdef CONFIG_NET_USRSOCK
|
#ifdef CONFIG_NET_USRSOCK
|
||||||
if (domain != PF_LOCAL && domain != PF_UNSPEC)
|
if (domain != PF_LOCAL && domain != PF_UNSPEC)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user