nouveau.hidd: disable warnings about not initialized variables
[AROS.git] / arch / all-mingw32 / bsdsocket / host_socket.c
blob94e7f5567dd62284f1472caf11717b81c0d3c884
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/irq.h>
8 #include <stdio.h>
9 #include <windows.h>
10 #include <winsock2.h>
12 #include "host_socket.h"
14 #define D(x) x
16 static struct SocketController ctl;
18 static DWORD WINAPI ResolverThread(struct SocketController *ctl)
20 D(printf("[Resolver] Thread started\n"));
22 for (;;)
24 WaitForSingleObject(ctl->ResolverEvent, INFINITE);
26 switch(ctl->Command)
28 case SOCK_CMD_SHUTDOWN:
29 D(printf("[Resolver] Shutdown requested\n"));
31 CloseHandle(ctl->ResolverEvent);
32 return 0;
35 ctl->Command = 0;
36 KrnCauseIRQ(ctl->ResolverIRQ);
40 struct SocketController * __declspec(dllexport) __aros sock_init(void)
42 struct WSAData wsdata;
43 HANDLE thread;
44 int irq;
45 int state = WSAStartup(0x0002, &wsdata);
47 D(printf("[sock_init] WSAStartup reply: %u\n", state));
48 D(printf("[sock_init] Using WinSock v%u.%u (%s)\n", wsdata.wVersion & 0x00FF, wsdata.wVersion >> 8, wsdata.szDescription));
49 D(printf("[sock_init] Status: %s\n", wsdata.szSystemStatus));
50 if (state)
51 return NULL;
53 irq = KrnAllocIRQ();
54 if (irq != -1)
56 ctl.SocketIRQ = irq;
58 irq = KrnAllocIRQ();
59 if (irq != -1)
61 ctl.ResolverIRQ = irq;
63 ctl.ResolverEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
64 if (ctl.ResolverEvent)
66 DWORD id;
68 thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ResolverThread, &ctl, 0, &id);
69 if (thread)
71 CloseHandle(thread);
73 ctl.SocketEvent = KrnGetIRQObject(ctl.SocketIRQ);
74 return &ctl;
76 CloseHandle(ctl.ResolverEvent);
79 KrnFreeIRQ(ctl.SocketIRQ);
82 return NULL;
85 int __declspec(dllexport) __aros sock_shutdown(struct SocketController *ctl)
87 int res = WSACleanup();
89 if (res)
90 return res;
92 ctl->Command = SOCK_CMD_SHUTDOWN;
93 SetEvent(ctl->ResolverEvent);
95 KrnFreeIRQ(ctl->ResolverIRQ);
96 KrnFreeIRQ(ctl->SocketIRQ);
98 return 0;