Implement SO_NOSIGPIPE option for sockets. This allows one to request that

an EPIPE error return not generate SIGPIPE on sockets.

Submitted by: lioux
Inspired by: Darwin
This commit is contained in:
alfred 2002-06-20 18:52:54 +00:00
parent c2afd32ef7
commit 619c88aeeb
4 changed files with 7 additions and 2 deletions

View File

@ -420,7 +420,8 @@ dofilewrite(td, fp, fd, buf, nbyte, offset, flags)
if (auio.uio_resid != cnt && (error == ERESTART || if (auio.uio_resid != cnt && (error == ERESTART ||
error == EINTR || error == EWOULDBLOCK)) error == EINTR || error == EWOULDBLOCK))
error = 0; error = 0;
if (error == EPIPE) { /* Socket layer is responsible for issuing SIGPIPE. */
if (error == EPIPE && fp->f_type != DTYPE_SOCKET) {
PROC_LOCK(td->td_proc); PROC_LOCK(td->td_proc);
psignal(td->td_proc, SIGPIPE); psignal(td->td_proc, SIGPIPE);
PROC_UNLOCK(td->td_proc); PROC_UNLOCK(td->td_proc);

View File

@ -1179,6 +1179,7 @@ sosetopt(so, sopt)
case SO_REUSEPORT: case SO_REUSEPORT:
case SO_OOBINLINE: case SO_OOBINLINE:
case SO_TIMESTAMP: case SO_TIMESTAMP:
case SO_NOSIGPIPE:
error = sooptcopyin(sopt, &optval, sizeof optval, error = sooptcopyin(sopt, &optval, sizeof optval,
sizeof optval); sizeof optval);
if (error) if (error)
@ -1362,6 +1363,7 @@ sogetopt(so, sopt)
case SO_BROADCAST: case SO_BROADCAST:
case SO_OOBINLINE: case SO_OOBINLINE:
case SO_TIMESTAMP: case SO_TIMESTAMP:
case SO_NOSIGPIPE:
optval = so->so_options & sopt->sopt_name; optval = so->so_options & sopt->sopt_name;
integer: integer:
error = sooptcopyout(sopt, &optval, sizeof optval); error = sooptcopyout(sopt, &optval, sizeof optval);

View File

@ -649,7 +649,8 @@ sendit(td, s, mp, flags)
if (auio.uio_resid != len && (error == ERESTART || if (auio.uio_resid != len && (error == ERESTART ||
error == EINTR || error == EWOULDBLOCK)) error == EINTR || error == EWOULDBLOCK))
error = 0; error = 0;
if (error == EPIPE) { /* Generation of SIGPIPE can be controlled per socket */
if (error == EPIPE && !(so->so_options & SO_NOSIGPIPE)) {
PROC_LOCK(td->td_proc); PROC_LOCK(td->td_proc);
psignal(td->td_proc, SIGPIPE); psignal(td->td_proc, SIGPIPE);
PROC_UNLOCK(td->td_proc); PROC_UNLOCK(td->td_proc);

View File

@ -82,6 +82,7 @@ typedef _BSD_SOCKLEN_T_ socklen_t;
#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */ #define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */ #define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
#define SO_TIMESTAMP 0x0400 /* timestamp received dgram traffic */ #define SO_TIMESTAMP 0x0400 /* timestamp received dgram traffic */
#define SO_NOSIGPIPE 0x0800 /* no SIGPIPE from EPIPE */
#define SO_ACCEPTFILTER 0x1000 /* there is an accept filter */ #define SO_ACCEPTFILTER 0x1000 /* there is an accept filter */
/* /*