- Added daytime and quote of the day services
[reactos.git] / reactos / apps / utils / net / tcpsvcs / tcpsvcs.c
1 #include <stdio.h>
2 #include <winsock2.h>
3 #include <tchar.h>
4 #include "tcpsvcs.h"
5
6 LPTHREAD_START_ROUTINE
7 ServiceHandler[NUM_SERVICES] = {
8 EchoHandler,
9 ChargenHandler,
10 DaytimeHandler,
11 NULL,
12 QotdHandler
13 };
14
15 INT ServicePort[NUM_SERVICES] = {
16 ECHO_PORT,
17 CHARGEN_PORT,
18 DAYTIME_PORT,
19 DISCARD_PORT,
20 QOTD_PORT
21 };
22
23 int main(int argc, char *argv[])
24 {
25 PSERVICES pServices[NUM_SERVICES];
26 DWORD dwThreadId[NUM_SERVICES];
27 HANDLE hThread[NUM_SERVICES];
28 INT i;
29
30 /* Create MAX_THREADS worker threads. */
31 for( i=0; i<NUM_SERVICES; i++ )
32 {
33 /* Allocate memory for thread data. */
34 pServices[i] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SERVICES));
35
36 if( pServices[i] == NULL )
37 ExitProcess(2);
38
39 /* Generate unique data for each thread. */
40 pServices[i]->Service = ServiceHandler[i];
41 pServices[i]->Port = ServicePort[i];
42
43 hThread[i] = CreateThread(
44 NULL, // default security attributes
45 0, // use default stack size
46 StartServer, // thread function
47 pServices[i], // argument to thread function
48 0, // use default creation flags
49 &dwThreadId[i]); // returns the thread identifier
50
51 /* Check the return value for success. */
52 if (hThread[i] == NULL)
53 {
54 ExitProcess(i);
55 }
56 }
57
58 /* Wait until all threads have terminated. */
59 WaitForMultipleObjects(NUM_SERVICES, hThread, TRUE, INFINITE);
60
61 /* Close all thread handles upon completion. */
62 for(i=0; i<NUM_SERVICES; i++)
63 {
64 CloseHandle(hThread[i]);
65 }
66
67 return 0;
68 }