76b9714b7d17bd67a05383fea69f05d709dd2b2e
5 #include "../skelserver/skelserver.h"
7 DWORD WINAPI
ChargenHandler(VOID
* Sock_
)
10 SOCKET Sock
= (SOCKET
)Sock_
;
12 if (!GenerateChars(Sock
)) {
13 _tprintf(_T("Echo incoming packets failed\n"));
17 _tprintf(_T("Shutting connection down...\n"));
18 if (ShutdownConnection(Sock
)) {
19 _tprintf(_T("Connection is down.\n"));
23 _tprintf(_T("Connection shutdown failed\n"));
31 BOOL
GenerateChars(SOCKET Sock
)
34 charIndex
, /* internal loop */
35 loopIndex
; /* line loop */
39 /* fill ring with printable characters */
40 for (charIndex
=0, i
=START
; i
<=END
; charIndex
++, i
++)
42 /* establish the end character in the ring */
43 endring
= &ring
[charIndex
];
45 /* where we will start output from */
50 /* if the loop index is equal to number of chars previously
51 * printed, start the loop from the beginning */
52 if (loopIndex
== END
-START
)
55 /* start printing from char controled by loopIndex */
56 charIndex
= loopIndex
;
57 for (i
=0; i
<LINESIZ
; i
++)
59 SendChar(Sock
, ring
[charIndex
]);
60 /* if current char equal last char, reset */
61 if (ring
[charIndex
] == *endring
)
66 SendChar(Sock
, L
'\r');
67 SendChar(Sock
, L
'\n');
69 /* increment loop index to start printing from next char in ring */
76 BOOL
SendChar(SOCKET Sock
, TCHAR c
)
82 RetVal
= send(Sock
, &c
, sizeof(TCHAR
), 0);
86 else if (RetVal
== SOCKET_ERROR
) {
91 /* Client closed connection before we could reply to
92 all the data it sent, so quit early. */
93 _tprintf(_T("Peer unexpectedly dropped connection!\n"));
97 _tprintf(("Connection closed by peer.\n"));