Documented GVF_SAVE_VAR alongside other flags, and removed a query/doubt
[AROS.git] / arch / all-mingw32 / bsdsocket / socket.c
blob492588c40c8eb16cff2495fc66a2b4351de3d14d
1 /*
2 Copyright © 2000-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 #include <proto/exec.h>
10 #include <sys/errno.h>
12 #include "bsdsocket_intern.h"
13 #include "bsdsocket_util.h"
14 #include "socket_intern.h"
16 /*****************************************************************************
18 NAME */
20 AROS_LH3(int, socket,
22 /* SYNOPSIS */
23 AROS_LHA(int, domain, D0),
24 AROS_LHA(int, type, D1),
25 AROS_LHA(int, protocol, D2),
27 /* LOCATION */
28 struct TaskBase *, taskBase, 12, BSDSocket)
30 /* FUNCTION
32 INPUTS
34 RESULT
36 NOTES
38 EXAMPLE
40 BUGS
42 SEE ALSO
44 INTERNALS
46 HISTORY
48 *****************************************************************************/
50 AROS_LIBFUNC_INIT
52 struct bsdsocketBase *SocketBase = taskBase->glob;
53 struct Socket *sd;
54 int err = 0;
55 int s;
57 D(bug("[bsdsocket] socket(%d, %d, %d)\n", domain, type, protocol));
59 s = GetFreeFD(taskBase);
60 if (s == -1)
61 return -1;
63 sd = AllocPooled(taskBase->pool, sizeof(struct Socket));
64 if (!sd)
66 SetError(ENOMEM, taskBase);
67 return -1;
70 sd->flags = 0;
72 Forbid();
74 sd->s = WSsocket(domain, type, protocol);
75 if (sd->s == -1)
76 err = WSAGetLastError();
77 else
79 /* This implies setting the socket to non-blocking mode, so no ioctlsocket() is needed */
80 err = WSAEventSelect(sd->s, SocketBase->ctl->SocketEvent, WS_FD_READ|WS_FD_WRITE|WS_FD_OOB|WS_FD_ACCEPT|WS_FD_CONNECT|WS_FD_CLOSE);
81 if (err)
83 err = WSAGetLastError();
85 WSclosesocket(sd->s);
89 Permit();
91 if (err)
93 FreePooled(taskBase->pool, sd, sizeof(struct Socket));
94 SetError(err - WSABASEERR, taskBase);
95 return -1;
98 AddTail((struct List *)&SocketBase->socks, (struct Node *)sd);
99 taskBase->dTable[s] = sd;
101 D(bug("[socket] Created socket %u (descriptor 0x%p, Windows socket %d)\n", s, sd, sd->s));
102 return s;
104 AROS_LIBFUNC_EXIT
106 } /* socket */