Skip to contentSkip to conversation

flag parameters: arch-specific SOCK_NONBLOCK

PATCH In review Ulrich Drepper 2 participants 2 messages May 13, 2008 – May 15, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 flag parameters: arch-specific SOCK_NONBLOCK

The value of O_NONBLOCK clashes on Alpha dn PARISC with the bits used for socket types. Therefore we cannot define SOCK_NONBLOCK as O_NONBLOCK on these platforms. This patch adds support for an arch-specific SOCK_NONBLOCK value which doesn't add costs for other architectures.

 include/asm-alpha/socket.h  |    5 +++++
 include/asm-parisc/socket.h |    5 +++++
 include/linux/net.h         |    2 ++
 net/socket.c                |    9 +++++++++
 4 files changed, 21 insertions(+)
include/asm-alpha/socket.h +5 -0
index 08c9793..a1057c2 100644
@@ -62,4 +62,9 @@
 
 #define SO_MARK			36
 
+/* O_NONBLOCK clashes with the bits used for socket types.  Therefore we
+ * have to define SOCK_NONBLOCK to a different value here.
+ */
+#define SOCK_NONBLOCK	0x40000000
+
 #endif /* _ASM_SOCKET_H */
include/asm-parisc/socket.h +5 -0
index 69a7a0d..fba402c 100644
@@ -54,4 +54,9 @@
 
 #define SO_MARK			0x401f
 
+/* O_NONBLOCK clashes with the bits used for socket types.  Therefore we
+ * have to define SOCK_NONBLOCK to a different value here.
+ */
+#define SOCK_NONBLOCK   0x40000000
+
 #endif /* _ASM_SOCKET_H */
include/linux/net.h +2 -0
index 1b35fd5..dd3b6cd 100644
@@ -102,7 +102,9 @@ enum sock_type {
 
 /* Flags for socket, socketpair, paccept */
 #define SOCK_CLOEXEC	O_CLOEXEC
+#ifndef SOCK_NONBLOCK
 #define SOCK_NONBLOCK	O_NONBLOCK
+#endif
 
 #endif /* ARCH_HAS_SOCKET_TYPES */
 
net/socket.c +9 -0
index 962bf07..5111af1 100644
@@ -1231,6 +1231,9 @@ asmlinkage long sys_socket(int family, int type, int protocol)
 		return -EINVAL;
 	type &= SOCK_TYPE_MASK;
 
+	if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
+		flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
+
 	retval = sock_create(family, type, protocol, &sock);
 	if (retval < 0)
 		goto out;
@@ -1265,6 +1268,9 @@ asmlinkage long sys_socketpair(int family, int type, int protocol,
 		return -EINVAL;
 	type &= SOCK_TYPE_MASK;
 
+	if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
+		flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
+
 	/*
 	 * Obtain the first socket and check if the underlying protocol
 	 * supports the socketpair call.
@@ -1430,6 +1436,9 @@ long do_accept(int fd, struct sockaddr __user *upeer_sockaddr,
 	if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK))
 		return -EINVAL;
 
+	if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
+		flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
+
 	sock = sockfd_lookup_light(fd, &err, &fput_needed);
 	if (!sock)
 		goto out;
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Ulrich Drepper

The value of O_NONBLOCK clashes on Alpha dn PARISC with the bits used for socket types. Therefore we cannot define SOCK_NONBLOCK as O_NONBLOCK on these platforms. This patch adds support for an arch-specific SOCK_NONBLOCK value which doesn't add costs for other architectures.

Quoted 9 lines
 include/asm-alpha/socket.h  |    5 +++++
 include/asm-parisc/socket.h |    5 +++++
 include/linux/net.h         |    2 ++
 net/socket.c                |    9 +++++++++
 4 files changed, 21 insertions(+)

This looks fine to me. Thanks, Ulrich!