public inbox for
help / color / mirror / Atom feed
* [newlib-cygwin] Listening sockets improvements.
@ 2018-08-24 13:09 Sebastian Huber
  0 siblings, 0 replies; only message in thread
From: Sebastian Huber @ 2018-08-24 13:09 UTC (permalink / raw)
  To: newlib-cvs;h=99b9b925fe8fa298177a765f74e9c799ff7006e0

commit 99b9b925fe8fa298177a765f74e9c799ff7006e0
Author: glebius <>
Date:   Thu Jun 8 21:30:34 2017 +0000

    Listening sockets improvements.
    o Separate fields of struct socket that belong to listening from
      fields that belong to normal dataflow, and unionize them.  This
      shrinks the structure a bit.
      - Take out selinfo's from the socket buffers into the socket. The
        first reason is to support braindamaged scenario when a socket is
        added to kevent(2) and then listen(2) is cast on it. The second
        reason is that there is future plan to make socket buffers pluggable,
        so that for a dataflow socket a socket buffer can be changed, and
        in this case we also want to keep same selinfos through the lifetime
        of a socket.
      - Remove struct struct so_accf. Since now listening stuff no longer
        affects struct socket size, just move its fields into listening part
        of the union.
      - Provide sol_upcall field and enforce that so_upcall_set() may be called
        only on a dataflow socket, which has buffers, and for listening sockets
        provide solisten_upcall_set().
    o Remove ACCEPT_LOCK() global.
      - Add a mutex to socket, to be used instead of socket buffer lock to lock
        fields of struct socket that don't belong to a socket buffer.
      - Allow to acquire two socket locks, but the first one must belong to a
        listening socket.
      - Make soref()/sorele() to use atomic(9).  This allows in some situations
        to do soref() without owning socket lock.  There is place for improvement
        here, it is possible to make sorele() also to lock optionally.
      - Most protocols aren't touched by this change, except UNIX local sockets.
        See below for more information.
    o Reduce copy-and-paste in kernel modules that accept connections from
      listening sockets: provide function solisten_dequeue(), and use it in
      the following modules: ctl(4), iscsi(4), ng_btsocket(4), ng_ksocket(4),
      infiniband, rpc.
    o UNIX local sockets.
      - Removal of ACCEPT_LOCK() global uncovered several races in the UNIX
        local sockets.  Most races exist around spawning a new socket, when we
        are connecting to a local listening socket.  To cover them, we need to
        hold locks on both PCBs when spawning a third one.  This means holding
        them across sonewconn().  This creates a LOR between pcb locks and
      - To fix the new LOR, abandon the global unp_list_lock in favor of global
        unp_link_lock.  Indeed, separating these two locks didn't provide us any
        extra parralelism in the UNIX sockets.
      - Now call into uipc_attach() may happen with unp_link_lock hold if, we
        are accepting, or without unp_link_lock in case if we are just creating
        a socket.
      - Another problem in UNIX sockets is that uipc_close() basicly did nothing
        for a listening socket.  The vnode remained opened for connections.  This
        is fixed by removing vnode in uipc_close().  Maybe the right way would be
        to do it for all sockets (not only listening), simply move the vnode
        teardown from uipc_detach() to uipc_close()?
    Sponsored by:		Netflix
    Differential Revision:

 newlib/libc/sys/rtems/include/sys/socket.h | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/newlib/libc/sys/rtems/include/sys/socket.h b/newlib/libc/sys/rtems/include/sys/socket.h
index cec6a24..87d0f33 100644
--- a/newlib/libc/sys/rtems/include/sys/socket.h
+++ b/newlib/libc/sys/rtems/include/sys/socket.h
@@ -111,7 +111,15 @@ typedef	__uintptr_t	uintptr_t;
 #define	SOCK_CLOEXEC	0x10000000
 #define	SOCK_NONBLOCK	0x20000000
+#ifdef _KERNEL
+ * Flags for accept1(), kern_accept4() and solisten_dequeue, in addition
+ */
+#define ACCEPT4_INHERIT 0x1
+#define ACCEPT4_COMPAT  0x2
+#endif	/* _KERNEL */
+#endif	/* __BSD_VISIBLE */
  * Option flags per-socket.
@@ -704,9 +712,5 @@ void so_sowwakeup(struct socket *so);
 void so_lock(struct socket *so);
 void so_unlock(struct socket *so);
-void so_listeners_apply_all(struct socket *so, void (*func)(struct socket *, void *), void *arg);
+#endif /* _KERNEL */
 #endif /* !_SYS_SOCKET_H_ */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-08-24 13:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-24 13:09 [newlib-cygwin] Listening sockets improvements Sebastian Huber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).