revert between 56095 -> 55830 in arch
[AROS.git] / arch / all-mingw32 / bsdsocket / closesocket.c
blob5da5936d88b3e5b5de41414250ea7114de444907
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 #include <sys/errno.h>
11 #include "bsdsocket_intern.h"
12 #include "bsdsocket_util.h"
13 #include "socket_intern.h"
15 /*****************************************************************************
17 NAME */
19 AROS_LH1(int, CloseSocket,
21 /* SYNOPSIS */
22 AROS_LHA(int, s, D0),
24 /* LOCATION */
25 struct TaskBase *, taskBase, 20, BSDSocket)
27 /* FUNCTION
29 INPUTS
31 RESULT
33 NOTES
35 EXAMPLE
37 BUGS
39 SEE ALSO
41 INTERNALS
43 HISTORY
45 *****************************************************************************/
47 AROS_LIBFUNC_INIT
49 struct Socket *sd;
51 D(bug("[bsdsocket] CloseSocket(%u)\n", s));
53 sd = IntCloseSocket(s, taskBase);
54 if (sd)
56 Remove((struct Node *)sd);
57 FreePooled(taskBase->pool, sd, sizeof(struct Socket));
59 taskBase->dTable[s] = NULL;
60 return 0;
62 else
63 return -1;
65 AROS_LIBFUNC_EXIT
66 } /* CloseSocket */
68 struct Socket *IntCloseSocket(int s, struct TaskBase *taskBase)
70 struct Socket *sd = GetSocket(s, taskBase);
72 if (sd)
74 struct bsdsocketBase *SocketBase = taskBase->glob;
75 int err;
77 Forbid();
78 err = WSclosesocket(sd->s);
79 if (err)
80 err = WSAGetLastError() - WSABASEERR;
81 Permit();
82 D(bug("[CloseSocket] Closed socket %u, error %u\n", s, err));
84 if (err)
86 SetError(err, taskBase);
87 sd = NULL;
91 return sd;