Watt-32 tcp/ip  2.2 dev-rel.10
shutdown.c
Go to the documentation of this file.
1 
5 /* BSD sockets functionality for Watt-32 TCP/IP
6  *
7  * Copyright (c) 1997-2002 Gisle Vanem <gvanem@yahoo.no>
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  * must display the following acknowledgement:
19  * This product includes software developed by Gisle Vanem
20  * Bergen, Norway.
21  *
22  * THIS SOFTWARE IS PROVIDED BY ME (Gisle Vanem) AND CONTRIBUTORS ``AS IS''
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL I OR CONTRIBUTORS BE LIABLE FOR ANY
26  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * Version
34  *
35  * 0.5 : Dec 18, 1997 : G. Vanem - created
36  */
37 
38 #include "socket.h"
39 
40 #if defined(USE_BSD_API)
41 
42 #define SHUT_RD 0 /* Further receives are disallowed */
43 #define SHUT_WR 1 /* Further sends are disallowed */
44 #define SHUT_RDWR 2 /* Further sends and receives are disallowed */
45 
46 int W32_CALL shutdown (int s, int how)
47 {
49 
50 #if defined(USE_DEBUG)
51  static char fmt[] = "\nshutdown:%d/??";
52  static char rrw[] = "r w rw";
53 
54  how &= 3;
55  fmt [sizeof(fmt)-3] = rrw [2*how];
56  fmt [sizeof(fmt)-2] = rrw [2*how+1];
57 #endif
58 
59  SOCK_PROLOGUE (socket, fmt, s);
60 
61  switch (how)
62  {
63  case SHUT_RD:
64  socket->so_error = ESHUTDOWN;
65  socket->so_state |= SS_CANTRCVMORE;
66  /* socket->so_options &= ~SO_ACCEPTCONN; */
67 
71  return (0);
72 
73  case SHUT_WR:
74  socket->so_error = ESHUTDOWN;
75  socket->so_state |= SS_CANTSENDMORE;
76  socket->so_state &= ~SS_ISLISTENING;
77  /* socket->so_options &= ~SO_ACCEPTCONN; */
78 
83  return (0);
84 
85  case SHUT_RDWR:
86  socket->so_error = ESHUTDOWN;
87  socket->so_state |= (SS_CANTRCVMORE | SS_CANTSENDMORE);
88  socket->so_state &= ~SS_ISLISTENING;
89  /* socket->so_options &= ~SO_ACCEPTCONN; */
90  return (0);
91  }
92 
93  SOCK_ERRNO (EINVAL);
94  return (-1);
95 }
96 #endif /* USE_BSD_API */
Definition: socket.h:137
Definition: if.h:84
int W32_CALL shutdown(int s, int how)
Definition: shutdown.c:46
Socket * _socklist_find(int s)
Returns a pointer to the Socket structure associated with socket 's'.
Definition: socket.c:1534