In soshutdown(), use SHUT_{RD,WR,RDWR} instead of FREAD and FWRITE.

Also, return EINVAL if `how' is invalid, as required by POSIX spec.
This commit is contained in:
Ruslan Ermilov 2001-02-27 13:48:07 +00:00
parent 4c0440cb86
commit 8ac6dca795
2 changed files with 35 additions and 26 deletions
lib/libc/sys
sys/kern

@ -32,9 +32,9 @@
.\" @(#)shutdown.2 8.1 (Berkeley) 6/4/93 .\" @(#)shutdown.2 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd June 4, 1993 .Dd February 27, 2001
.Dt SHUTDOWN 2 .Dt SHUTDOWN 2
.Os BSD 4.2 .Os
.Sh NAME .Sh NAME
.Nm shutdown .Nm shutdown
.Nd shut down part of a full-duplex connection .Nd shut down part of a full-duplex connection
@ -49,37 +49,42 @@
The The
.Fn shutdown .Fn shutdown
call causes all or part of a full-duplex connection on call causes all or part of a full-duplex connection on
the socket associated with the socket associated with the file descriptor
.Fa s .Fa s
to be shut down. to be shut down.
If The
.Fa how .Fa how
is argument specifies the type of shutdown.
.No Dv SHUT_RD Pq 0 , Possible values are:
.Bl -tag -width SHUT_RDWR
.It Dv SHUT_RD
further receives will be disallowed. further receives will be disallowed.
If .It Dv SHUT_WR
.Fa how
is
.No Dv SHUT_WR Pq 1 ,
further sends will be disallowed. further sends will be disallowed.
If .It Dv SHUT_RDWR
.Fa how
is
.No Dv SHUT_RDWR Pq 2 ,
further sends and receives will be disallowed. further sends and receives will be disallowed.
.El
.Sh RETURN VALUES .Sh RETURN VALUES
A 0 is returned if the call succeeds, -1 if it fails. .Rv -std shutdown .
.Sh ERRORS .Sh ERRORS
The call succeeds unless: The
.Fn shutdown
call fails if:
.Bl -tag -width Er .Bl -tag -width Er
.It Bq Er EBADF .It Bq Er EBADF
.Fa S The
is not a valid descriptor. .Fa s
.It Bq Er ENOTSOCK argument is not a valid file descriptor.
.Fa S .It Bq Er EINVAL
is a file, not a socket. The
.Fa how
argument is invalid.
.It Bq Er ENOTCONN .It Bq Er ENOTCONN
The specified socket is not connected. The socket is not connected.
.It Bq Er ENOTSOCK
The
.Fa s
argument does not refer to a socket.
.El .El
.Sh SEE ALSO .Sh SEE ALSO
.Xr connect 2 , .Xr connect 2 ,
@ -96,6 +101,8 @@ The
function call appeared in function call appeared in
.Bx 4.2 . .Bx 4.2 .
The The
.Dv SHUT_ .Dv SHUT_RD , SHUT_WR ,
and
.Dv SHUT_RDWR
constants appeared in constants appeared in
.St -p1003.1g . .St -p1003.1g .

@ -958,10 +958,12 @@ soshutdown(so, how)
{ {
register struct protosw *pr = so->so_proto; register struct protosw *pr = so->so_proto;
how++; if (!(how == SHUT_RD || how == SHUT_WR || how == SHUT_RDWR))
if (how & FREAD) return (EINVAL);
if (how != SHUT_WR)
sorflush(so); sorflush(so);
if (how & FWRITE) if (how != SHUT_RD)
return ((*pr->pr_usrreqs->pru_shutdown)(so)); return ((*pr->pr_usrreqs->pru_shutdown)(so));
return (0); return (0);
} }