-/* $OpenBSD: uipc_socket.c,v 1.304 2023/06/30 11:52:11 mvs Exp $ */
+/* $OpenBSD: uipc_socket.c,v 1.305 2023/07/04 22:28:24 mvs Exp $ */
/* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */
/*
int m_getuio(struct mbuf **, int, long, struct uio *);
-#define SBLOCKWAIT(f) (((f) & MSG_DONTWAIT) ? M_NOWAIT : M_WAITOK)
+#define SBLOCKWAIT(f) (((f) & MSG_DONTWAIT) ? 0 : SBL_WAIT)
/*
* Send on a socket.
* If send must go all at once and message is larger than
const struct protosw *pr = so->so_proto;
int error;
- sb->sb_flags |= SB_NOINTR;
- error = sblock(so, sb, M_WAITOK);
- /* with SB_NOINTR and M_WAITOK sblock() must not fail */
+ error = sblock(so, sb, SBL_WAIT | SBL_NOINTR);
+ /* with SBL_WAIT and SLB_NOINTR sblock() must not fail */
KASSERT(error == 0);
socantrcvmore(so);
m = sb->sb_mb;
/* If no fd is given, unsplice by removing existing link. */
if (fd < 0) {
/* Lock receive buffer. */
- if ((error = sblock(so, &so->so_rcv, M_WAITOK)) != 0) {
+ if ((error = sblock(so, &so->so_rcv, SBL_WAIT)) != 0) {
return (error);
}
if (so->so_sp->ssp_socket)
}
/* Lock both receive and send buffer. */
- if ((error = sblock(so, &so->so_rcv, M_WAITOK)) != 0) {
+ if ((error = sblock(so, &so->so_rcv, SBL_WAIT)) != 0) {
goto frele;
}
- if ((error = sblock(so, &sosp->so_snd, M_WAITOK)) != 0) {
+ if ((error = sblock(so, &sosp->so_snd, SBL_WAIT)) != 0) {
sbunlock(so, &so->so_rcv);
goto frele;
}
-/* $OpenBSD: uipc_socket2.c,v 1.136 2023/02/10 14:34:17 visa Exp $ */
+/* $OpenBSD: uipc_socket2.c,v 1.137 2023/07/04 22:28:24 mvs Exp $ */
/* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */
/*
}
int
-sblock(struct socket *so, struct sockbuf *sb, int wait)
+sblock(struct socket *so, struct sockbuf *sb, int flags)
{
- int error, prio = (sb->sb_flags & SB_NOINTR) ? PSOCK : PSOCK | PCATCH;
+ int error, prio = PSOCK;
soassertlocked(so);
sb->sb_flags |= SB_LOCK;
return (0);
}
- if (wait & M_NOWAIT)
+ if ((flags & SBL_WAIT) == 0)
return (EWOULDBLOCK);
+ if (!(flags & SBL_NOINTR || sb->sb_flags & SB_NOINTR))
+ prio |= PCATCH;
while (sb->sb_flags & SB_LOCK) {
sb->sb_flags |= SB_WANT;
-/* $OpenBSD: socketvar.h,v 1.119 2023/01/27 18:46:34 mvs Exp $ */
+/* $OpenBSD: socketvar.h,v 1.120 2023/07/04 22:28:24 mvs Exp $ */
/* $NetBSD: socketvar.h,v 1.18 1996/02/09 18:25:38 christos Exp $ */
/*-
sb->sb_mbcnt -= m->m_ext.ext_size;
}
+/*
+ * Flags to sblock()
+ */
+#define SBL_WAIT 0x01 /* Wait if lock not immediately available. */
+#define SBL_NOINTR 0x02 /* Enforce non-interruptible sleep. */
+
/*
* Set lock on sockbuf sb; sleep if lock is already held.
- * Unless SB_NOINTR is set on sockbuf, sleep is interruptible.
- * Returns error without lock if sleep is interrupted.
+ * Unless SB_NOINTR is set on sockbuf or SBL_NOINTR passed,
+ * sleep is interruptible. Returns error without lock if
+ * sleep is interrupted.
*/
int sblock(struct socket *, struct sockbuf *, int);