This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patches to improve Hurd parts: bits/socket.h


2008-12-17  Thomas Schwinge  <tschwinge@gnu.org>

	* sysdeps/mach/hurd/bits/socket.h: New file, copy from the bsd4.4 one.
	(SOCK_MAX, SOCK_TYPE_MASK): New definitions.
	(SOCK_CLOEXEC, SOCK_NONBLOCK): New definitions.

Recipe:

Copy sysdeps/unix/bsd/bsd4.4/bits/socket.h to
sysdeps/mach/hurd/bits/socket.h -- I don't think these enhancements fit
into the bsd4.4 case anymore.

--- sysdeps/unix/bsd/bsd4.4/bits/socket.h	2008-12-16 00:04:53.000000000 +0100
+++ sysdeps/mach/hurd/bits/socket.h	2008-12-17 01:06:25.000000000 +0100
@@ -51,9 +51,25 @@ enum __socket_type
 #define SOCK_RAW SOCK_RAW
   SOCK_RDM = 4,			/* Reliably-delivered messages.  */
 #define SOCK_RDM SOCK_RDM
-  SOCK_SEQPACKET = 5		/* Sequenced, reliable, connection-based,
+  SOCK_SEQPACKET = 5,		/* Sequenced, reliable, connection-based,
 				   datagrams of fixed maximum length.  */
 #define SOCK_SEQPACKET SOCK_SEQPACKET
+
+#define SOCK_MAX (SOCK_SEQPACKET + 1)
+  /* Mask which covers at least up to SOCK_MASK-1.  The
+     remaining bits are used as flags. */
+#define SOCK_TYPE_MASK 0xf
+
+  /* Flags to be ORed into the type parameter of socket and socketpair and
+     used for the flags parameter of accept4.  */
+
+  SOCK_CLOEXEC = 0x00400000,	/* Atomically set close-on-exec flag for the
+				   new descriptor(s).  */
+#define SOCK_CLOEXEC SOCK_CLOEXEC
+
+  SOCK_NONBLOCK = 0x0800	/* Atomically mark descriptor(s) as
+				   non-blocking.  */
+#define SOCK_NONBLOCK SOCK_NONBLOCK
 };
 
 /* Protocol families.  */

To discuss: which value to use for SOCK_NONBLOCK?  I changed it away from
our O_NONBLOCK (0x8) which is unusable due to conflicting with the
original SOCK_* flags to the Linux 04000 (i.e. 0x0800) value.  Do it like
this or is there a ``better'' value?

Linux, for example, has the following in commit
aaca0bdca573f3f51ea03139f9c7289541e7bca3 for alpha and parisc:

    +/* 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

We need the SOCK_MAX and SOCK_TYPE_MASK (which are also defined in the
Linux kernel) to check the SOCK_* definitions for consistency and to be
able to extract the original socket type in case of type = SOCK_STREAM |
SOCK_CLOEXEC etc.  Should these definitions be in bits/socket.h or
elsewhere?  This is not really Hurd-specific, by the way.

Attachment: signature.asc
Description: Digital signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]