Start to implement the beginneings of tcpsvcs.exe. Just ideas at the moment, subject...
[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 #include "skelserver/skelserver.h"
6 #include "echo/echo.h"
7 #include "chargen/chargen.h"
8
9 int main(int argc, char *argv[])
10 {
11 PMYDATA pData[MAX_THREADS];
12 DWORD dwThreadId[MAX_THREADS];
13 HANDLE hThread[MAX_THREADS];
14 INT i;
15
16 /* Create MAX_THREADS worker threads. */
17 for( i=0; i<MAX_THREADS; i++ )
18 {
19 /* Allocate memory for thread data. */
20 pData[i] = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MYDATA));
21
22 if( pData == NULL )
23 ExitProcess(2);
24
25 /* Generate unique data for each thread. */
26 pData[0]->Port = ECHO_PORT;
27 pData[0]->Service = EchoHandler;
28 pData[1]->Port = CHARGEN_PORT;
29 pData[1]->Service = ChargenHandler;
30
31 hThread[i] = CreateThread(
32 NULL, // default security attributes
33 0, // use default stack size
34 StartServer, // thread function
35 pData[i], // argument to thread function
36 0, // use default creation flags
37 &dwThreadId[i]); // returns the thread identifier
38
39 /* Check the return value for success. */
40 if (hThread[i] == NULL)
41 {
42 ExitProcess(i);
43 }
44 }
45
46 /* Wait until all threads have terminated. */
47 WaitForMultipleObjects(MAX_THREADS, hThread, TRUE, INFINITE);
48
49 /* Close all thread handles upon completion. */
50 for(i=0; i<MAX_THREADS; i++)
51 {
52 CloseHandle(hThread[i]);
53 }
54
55 return 0;
56 }
57