Silence most of the msvc warnings
[reactos.git] / reactos / services / tcpsvcs / daytime.c
1 /*
2 * ReactOS Services
3 * Copyright (C) 2005 ReactOS Team
4 *
5 * LICENCE: GPL - See COPYING in the top level directory
6 * PROJECT: ReactOS simple TCP/IP services
7 * FILE: apps/utils/net/tcpsvcs/daytime.c
8 * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
9 * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
10 * REVISIONS:
11 * GM 04/10/05 Created
12 *
13 */
14
15 #include <stdio.h>
16 #include <winsock2.h>
17 #include <tchar.h>
18 #include <time.h>
19 #include "tcpsvcs.h"
20
21 DWORD WINAPI DaytimeHandler(VOID* Sock_)
22 {
23 struct tm *newtime;
24 time_t aclock;
25 TCHAR *pszTime;
26 DWORD RetVal = 0;
27 SOCKET Sock = (SOCKET)Sock_;
28
29 time(&aclock);
30 newtime = localtime(&aclock);
31 pszTime = _tasctime(newtime);
32
33 SendTime(Sock, pszTime);
34
35 LogEvent(_T("DayTime: Shutting connection down...\n"), 0, FALSE);
36 if (ShutdownConnection(Sock, FALSE))
37 LogEvent(_T("DayTime: Connection is down.\n"), 0, FALSE);
38 else
39 {
40 LogEvent(_T("DayTime: Connection shutdown failed\n"), 0, FALSE);
41 RetVal = 1;
42 }
43
44 LogEvent(_T("DayTime: Terminating thread\n"), 0, FALSE);
45 ExitThread(RetVal);
46 }
47
48
49 BOOL SendTime(SOCKET Sock, TCHAR *time)
50 {
51 INT StringSize = (INT)_tcsclen(time);
52 INT RetVal = send(Sock, time, sizeof(TCHAR) * StringSize, 0);
53
54 if (RetVal == SOCKET_ERROR)
55 return FALSE;
56
57 LogEvent(_T("DayTime: Connection closed by peer.\n"), 0, FALSE);
58 return TRUE;
59 }