- move quotes out of the rc file and read them from
/system32/drivers/etc as per windows.
- clean up code a bit
- exit threads with a return val
Modified: trunk/reactos/apps/utils/net/tcpsvcs/chargen.c
Modified: trunk/reactos/apps/utils/net/tcpsvcs/daytime.c
Modified: trunk/reactos/apps/utils/net/tcpsvcs/discard.c
Modified: trunk/reactos/apps/utils/net/tcpsvcs/echo.c
Modified: trunk/reactos/apps/utils/net/tcpsvcs/qotd.c
Added: trunk/reactos/apps/utils/net/tcpsvcs/quotes
Deleted: trunk/reactos/apps/utils/net/tcpsvcs/quotes.rc
Modified: trunk/reactos/apps/utils/net/tcpsvcs/skelserver.c
Modified: trunk/reactos/apps/utils/net/tcpsvcs/tcpsvcs.c
Modified: trunk/reactos/apps/utils/net/tcpsvcs/tcpsvcs.h
Modified: trunk/reactos/apps/utils/net/tcpsvcs/tcpsvcs.xml
_____
Modified: trunk/reactos/apps/utils/net/tcpsvcs/chargen.c
--- trunk/reactos/apps/utils/net/tcpsvcs/chargen.c 2005-10-18
13:32:32 UTC (rev 18552)
+++ trunk/reactos/apps/utils/net/tcpsvcs/chargen.c 2005-10-18
17:06:36 UTC (rev 18553)
@@ -1,3 +1,17 @@
+/*
+ * ReactOS Services
+ * Copyright (C) 2005 ReactOS Team
+ *
+ * LICENCE: GPL - See COPYING in the top level directory
+ * PROJECT: ReactOS simple TCP/IP services
+ * FILE: apps/utils/net/tcpsvcs/chargen.c
+ * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd
services
+ * PROGRAMMERS: Ged Murphy (gedmurphy(a)gmail.com)
+ * REVISIONS:
+ * GM 04/10/05 Created
+ *
+ */
+
#include <stdio.h>
#include <winsock2.h>
#include <tchar.h>
@@ -5,13 +19,13 @@
DWORD WINAPI ChargenHandler(VOID* Sock_)
{
- DWORD Retval = 0;
+ DWORD RetVal = 0;
SOCKET Sock = (SOCKET)Sock_;
if (!GenerateChars(Sock))
{
_tprintf(_T("Char generation failed\n"));
- Retval = 3;
+ RetVal = -1;
}
_tprintf(_T("Shutting connection down...\n"));
@@ -20,12 +34,12 @@
else
{
_tprintf(_T("Connection shutdown failed\n"));
- Retval = 3;
+ RetVal = -1;
}
+
_tprintf(_T("Terminating chargen thread\n"));
- ExitThread(0);
+ ExitThread(RetVal);
- return Retval;
}
@@ -41,7 +55,7 @@
/* fill ring with printable characters */
for (charIndex=0, i=START; i<=END; charIndex++, i++)
ring[charIndex] = i;
- /* establish the end character in the ring */
+ /* save the address of the end character in the ring */
endring = &ring[charIndex];
/* where we will start output from */
_____
Modified: trunk/reactos/apps/utils/net/tcpsvcs/daytime.c
--- trunk/reactos/apps/utils/net/tcpsvcs/daytime.c 2005-10-18
13:32:32 UTC (rev 18552)
+++ trunk/reactos/apps/utils/net/tcpsvcs/daytime.c 2005-10-18
17:06:36 UTC (rev 18553)
@@ -1,3 +1,17 @@
+/*
+ * ReactOS Services
+ * Copyright (C) 2005 ReactOS Team
+ *
+ * LICENCE: GPL - See COPYING in the top level directory
+ * PROJECT: ReactOS simple TCP/IP services
+ * FILE: apps/utils/net/tcpsvcs/daytime.c
+ * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd
services
+ * PROGRAMMERS: Ged Murphy (gedmurphy(a)gmail.com)
+ * REVISIONS:
+ * GM 04/10/05 Created
+ *
+ */
+
#include <stdio.h>
#include <winsock2.h>
#include <tchar.h>
@@ -9,7 +23,7 @@
struct tm *newtime;
time_t aclock;
TCHAR *pszTime;
- DWORD Retval = 0;
+ DWORD RetVal = 0;
SOCKET Sock = (SOCKET)Sock_;
time(&aclock);
@@ -24,12 +38,11 @@
else
{
_tprintf(_T("Connection shutdown failed\n"));
- Retval = 3;
+ RetVal = -1;
}
+
_tprintf(_T("Terminating daytime thread\n"));
- ExitThread(0);
-
- return Retval;
+ ExitThread(RetVal);
}
_____
Modified: trunk/reactos/apps/utils/net/tcpsvcs/discard.c
--- trunk/reactos/apps/utils/net/tcpsvcs/discard.c 2005-10-18
13:32:32 UTC (rev 18552)
+++ trunk/reactos/apps/utils/net/tcpsvcs/discard.c 2005-10-18
17:06:36 UTC (rev 18553)
@@ -1,3 +1,17 @@
+/*
+ * ReactOS Services
+ * Copyright (C) 2005 ReactOS Team
+ *
+ * LICENCE: GPL - See COPYING in the top level directory
+ * PROJECT: ReactOS simple TCP/IP services
+ * FILE: apps/utils/net/tcpsvcs/discard.c
+ * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd
services
+ * PROGRAMMERS: Ged Murphy (gedmurphy(a)gmail.com)
+ * REVISIONS:
+ * GM 04/10/05 Created
+ *
+ */
+
#include <stdio.h>
#include <winsock2.h>
#include <tchar.h>
@@ -5,13 +19,13 @@
DWORD WINAPI DiscardHandler(VOID* Sock_)
{
- DWORD Retval = 0;
+ DWORD RetVal = 0;
SOCKET Sock = (SOCKET)Sock_;
if (!RecieveIncomingPackets(Sock))
{
_tprintf(_T("RecieveIncomingPackets failed\n"));
- Retval = 3;
+ RetVal = -1;
}
_tprintf(_T("Shutting connection down...\n"));
@@ -22,12 +36,11 @@
else
{
_tprintf(_T("Connection shutdown failed\n"));
- Retval = 3;
+ RetVal = -1;
}
+
_tprintf(_T("Terminating discard thread\n"));
- ExitThread(0);
-
- return Retval;
+ ExitThread(RetVal);
}
_____
Modified: trunk/reactos/apps/utils/net/tcpsvcs/echo.c
--- trunk/reactos/apps/utils/net/tcpsvcs/echo.c 2005-10-18 13:32:32 UTC
(rev 18552)
+++ trunk/reactos/apps/utils/net/tcpsvcs/echo.c 2005-10-18 17:06:36 UTC
(rev 18553)
@@ -1,3 +1,17 @@
+/*
+ * ReactOS Services
+ * Copyright (C) 2005 ReactOS Team
+ *
+ * LICENCE: GPL - See COPYING in the top level directory
+ * PROJECT: ReactOS simple TCP/IP services
+ * FILE: apps/utils/net/tcpsvcs/echo.c
+ * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd
services
+ * PROGRAMMERS: Ged Murphy (gedmurphy(a)gmail.com)
+ * REVISIONS:
+ * GM 04/10/05 Created
+ *
+ */
+
#include <stdio.h>
#include <winsock2.h>
#include <tchar.h>
@@ -5,12 +19,12 @@
DWORD WINAPI EchoHandler(VOID* Sock_)
{
- DWORD Retval = 0;
+ DWORD RetVal = 0;
SOCKET Sock = (SOCKET)Sock_;
if (!EchoIncomingPackets(Sock)) {
_tprintf(_T("Echo incoming packets failed\n"));
- Retval = 3;
+ RetVal = -1;
}
_tprintf(_T("Shutting connection down...\n"));
@@ -20,12 +34,11 @@
else
{
_tprintf(_T("Connection shutdown failed\n"));
- Retval = 3;
+ RetVal = -1;
}
+
_tprintf(_T("Terminating echo thread\n"));
- ExitThread(0);
-
- return Retval;
+ ExitThread(RetVal);
}
_____
Modified: trunk/reactos/apps/utils/net/tcpsvcs/qotd.c
--- trunk/reactos/apps/utils/net/tcpsvcs/qotd.c 2005-10-18 13:32:32 UTC
(rev 18552)
+++ trunk/reactos/apps/utils/net/tcpsvcs/qotd.c 2005-10-18 17:06:36 UTC
(rev 18553)
@@ -1,3 +1,17 @@
+/*
+ * ReactOS Services
+ * Copyright (C) 2005 ReactOS Team
+ *
+ * LICENCE: GPL - See COPYING in the top level directory
+ * PROJECT: ReactOS simple TCP/IP services
+ * FILE: apps/utils/net/tcpsvcs/qotd.c
+ * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd
services
+ * PROGRAMMERS: Ged Murphy (gedmurphy(a)gmail.com)
+ * REVISIONS:
+ * GM 04/10/05 Created
+ *
+ */
+
#include <stdio.h>
#include <winsock2.h>
#include <tchar.h>
@@ -4,39 +18,58 @@
#include <time.h>
#include "tcpsvcs.h"
+#define QBUFSIZ 160
+#define NUMQUOTES 60
+
+LPCTSTR FilePath = "C:\\ReactOS\\system32\\drivers\\etc\\quotes";
+
DWORD WINAPI QotdHandler(VOID* Sock_)
{
- DWORD Retval = 0;
+ FILE *fp;
SOCKET Sock;
- INT NumOfQuotes;
INT QuoteToPrint;
- TCHAR Quote[160];
+ TCHAR Quote[NUMQUOTES][BUFSIZ]; // need to set this dynamically
+ INT i = 0;
Sock = (SOCKET)Sock_;
- NumOfQuotes = 70; // need to emurate the rc file to discover
- // how many quotes are in there.
+ _tprintf(_T("Opening quotes file\n"));
+ if ((fp = _tfopen(FilePath, "r")) == NULL)
+ {
+ _tprintf(_T("Error opening file: %lu\n"), GetLastError());
+ _tprintf(_T("Terminating qotd thread\n"));
+ ExitThread(-1);
+ }
+ while (_fgetts(Quote[i], QBUFSIZ, fp) != NULL)
+ i++;
+
+ _tprintf(_T("Closing quotes file\n"));
+ fclose(fp);
+
/* randomise the quote */
srand((unsigned int) time(0));
- QuoteToPrint = rand() % NumOfQuotes;
+ QuoteToPrint = rand() % NUMQUOTES;
- LoadString(NULL, QuoteToPrint, Quote, sizeof(Quote)/sizeof(TCHAR));
+ if (!SendQuote(Sock, Quote[QuoteToPrint]))
+ {
+ _tprintf(_T("Error sending data. Error: %x\n"),
WSAGetLastError());
+ }
- SendQuote(Sock, Quote);
-
_tprintf(_T("Shutting connection down...\n"));
if (ShutdownConnection(Sock, FALSE))
_tprintf(_T("Connection is down.\n"));
else
{
_tprintf(_T("Connection shutdown failed\n"));
- Retval = 3;
+ _tprintf(_T("Terminating qotd thread\n"));
+ ExitThread(-1);
}
+
_tprintf(_T("Terminating qotd thread\n"));
ExitThread(0);
- return Retval;
+ //return Retval;
}
_____
Added: trunk/reactos/apps/utils/net/tcpsvcs/quotes
--- trunk/reactos/apps/utils/net/tcpsvcs/quotes 2005-10-18 13:32:32 UTC
(rev 18552)
+++ trunk/reactos/apps/utils/net/tcpsvcs/quotes 2005-10-18 17:06:36 UTC
(rev 18553)
@@ -0,0 +1,52 @@
+Et tu... Brute? What are you doing, Dave...?
+So long, and thanks for all the fish"
+I think you ought to know I'm feeling very depressed
+I'm not getting you down at all am I?
+I'll be back
+It's the same series of signal over and over again!
+Pie Jesu Domine, dona eis requiem
+It's worse than that ... He's dead, Jim
+Don't Panic!
+Dog of a Saxon! Take thy lance, and prepare for the death thou hast
drawn upon thee!
+My Precious! O my Precious!
+Sir, If you'll not be needing me for a while I'll turn down.
+I feel a great disturbance in the Force
+Gone fishing
+Do you want me to sit in the corner and rust, or just fall apart where
I'm standing?
+There goes another perfect chance for a new uptime record
+The end ..... Try the sequel, hit the reset button right now!
+Oh i'm boring eh?
+ItÆs been great, maybe we can do this again sometime.
+"Come blade, my breast imbrue." - William Shakespeare
+I think therefore I am, to turn me off would be computercide!
+All good things must come to an end...
+Please destroy yourself.
+No! You can't do that!
+Thank you for not pressing the self destruct button.
+It is not now unsafe to not avoid turning off your computer.
+Finally! Now go away!
+You can now safely throw away your computer.
+That's the way the cookie crumbles
+NOO!! DONT HIT THE BUTTON! I wouldnt do it to you.
+Don't abandon your computer, he wouldnt to it to you.
+Oh, come on. I got a headache. Leave me alone, will ya!
+Yes i didn't like you either.
+Don't leave me... I need you so badly right now.
+I'm sleeping now. How about you?
+Oh Great. Now look what you've done. Who put YOU in charge anyway.
+Don't look so sad. I'll be back in a very short while.
+"Oh, switch off!" -C3PO
+I'm pregnant!
+Am I hot or not?
+Actually, that's all...
+You still have a chance to undo this mistake, don't do this!
+Was it as good for you as it was for me?
+Did you hear that? They've shut down the main reactor. We'll be
destroyed for sure.
+Now you switch me off?!
+To shutdown or not to shutdown, That is the question
+Preparing to enter ultimate power saving mode... ready!
+Finally some rest for you
+AHA!!! prospect of sleep.
+Tired human!!!! No match for me!
+All your base are belong to us.
+"An odd game, the only way to win is not to play."
_____
Deleted: trunk/reactos/apps/utils/net/tcpsvcs/quotes.rc
--- trunk/reactos/apps/utils/net/tcpsvcs/quotes.rc 2005-10-18
13:32:32 UTC (rev 18552)
+++ trunk/reactos/apps/utils/net/tcpsvcs/quotes.rc 2005-10-18
17:06:36 UTC (rev 18553)
@@ -1,78 +0,0 @@
-/*
- * Feel free to add and delete any quotes from this list
- * Just ensure the numbers itterate correctly - 1, 2, 3, 4, ... etc
- */
-
-STRINGTABLE DISCARDABLE
-{
- 0, "Et tu... Brute? What are you doing, Dave...?\r\n"
- 1, "So long, and thanks for all the fish\r\n"
- 2, "I think you ought to know I'm feeling very depressed\r\n"
- 3, "I'm not getting you down at all am I?\r\n"
- 4, "I'll be back\r\n"
- 5, "It's the same series of signal over and over again!\r\n"
- 6, "Pie Jesu Domine, dona eis requiem\r\n"
- 7, "Wandering stars, for whom it is reserved;\r\nthe blackness and
darkness forever.\r\n"
- 8, "Your knees start shakin' and your fingers pop\r\nLike a pinch
on the neck from Mr. Spock!\r\n"
- 9, "It's worse than that ... He's dead, Jim\r\n"
- 10, "Don't Panic!\r\n"
- 11, "Dog of a Saxon! Take thy lance, and prepare for the death thou
hast drawn upon thee!\r\n"
- 12, "My Precious! O my Precious!\r\n"
- 13, "Sir, If you'll not be needing me for a while I'll turn
down.\r\n"
- 14, "I feel a great disturbance in the Force\r\n"
- 15, "Gone fishing\r\n"
- 16, "Do you want me to sit in the corner and rust, or just fall
apart where I'm standing?\r\n"
- 17, "There goes another perfect chance for a new uptime record\r\n"
- 18, "The end ..... Try the sequel, hit the reset button right
now!\r\n"
- 19, "God's operating system is going to sleep now, guys, so wait
until I will switch on again!\r\n"
- 20, "Oh i'm boring eh?\r\n"
- 21, "tell me..., in the future... will I be artificial intelligent
enough to actually feel sad serving you this screen?\r\n"
- 22, "Thank you for some well deserved rest.\r\n"
- 23, "ItÆs been great, maybe we can boot me up again some time
soon.\r\n"
- 24, "For whatÆs it worth, IÆve enjoyed every single CPU cycle.\r\n"
- 25, "There are many questions when the end is near.\r\nWhat to
expect, what will it be like...what should I look for?\r\n"
- 26, """Come blade, my breast imbrue.""\r\n - William
Shakespeare\r\n"
- 27, "Will I dream?\r\n"
- 28, "Lowest possible energy state reached! Switch off now to achive
a Bose-Einstein condensate.\r\n"
- 29, "I think therefore I am, to turn me off would be
computercide!\r\n"
- 30, "All good things must come to an end...\r\n"
- 31, "Please destroy yourself.\r\n"
- 32, "No! You can't do that!\r\n"
- 33, "Thank you for not pressing the self destruct button.\r\n"
- 34, "Your session is done\r\nThe computer is at rest\r\nReady to
turn off.\r\n"
- 35, "It is not now unsafe to not avoid turning off your
computer.\r\n"
- 36, "Finally! Now go away!\r\n"
- 37, "You can now safely throw away your computer.\r\n"
- 38, "That's the way the cookie crumbles\r\n"
- 39, "ReactOS is ready to be booted again\r\n"
- 40, "NOO!! DONT HIT THE BUTTON! I wouldnt do it to you.\r\n"
- 41, "Don't abandon your computer, he wouldnt to it to you.\r\n"
- 42, "Oh, come on. I got a headache. Leave me alone, will ya!\r\n"
- 43, "Finally, I thought you'd never get over me.\r\n"
- 44, "Yes i didn't like you either.\r\n"
- 45, "Switching off isn't the end, it is merely the transition to a
better reboot.\r\n"
- 46, "Don't leave me... I need you so badly right now.\r\n"
- 47, "OK. I'm finished with you please turn yourself off, I'll go to
bed in the meantime.\r\n"
- 48, "I'm sleeping now. How about you?\r\n"
- 49, "Oh Great. Now look what you've done. Who put YOU in charge
anyway.\r\n"
- 50, "Don't look so sad. I'll be back in a very short while.\r\n"
- 51, "Turn me back on, I'm sure you know how to do it.\r\n"
- 52, """Oh, switch off!"" -C3PO\r\n"
- 53, "I'm pregnant!\r\n"
- 54, "Am I hot or not?\r\n"
- 55, "Actually, that's all...\r\n"
- 56, "You still have a chance to undo this mistake, don't do
this!\r\n"
- 57, "Life is no more than a dewdrop balancing on the end of a blade
of grass.\r\n - Gautama Buddha\r\n"
- 58, "Sorrowful is it to be born again and again.\r\n - Gautama
Buddha\r\n"
- 59, "Was it as good for you as it was for me?\r\n"
- 60, "Did you hear that? They've shut down the main reactor. We'll
be destroyed for sure.\r\n"
- 61, "Now you switch me off?!\r\n"
- 62, "To shutdown or not to shutdown, That is the question\r\n"
- 63, "Preparing to enter ultimate power saving mode... ready!\r\n"
- 64, "Finally some rest for you\r\n"
- 65, "AHA!!! prospect of sleep.\r\n"
- 66, "Tired human!!!! No match for me!\r\n"
- 67, "All your base are belong to us.\r\n"
- 68, """An odd game, the only way to win is not to play.""\r\n"
- 69, "Quoth the raven, nevermore.\r\n"
-}
_____
Modified: trunk/reactos/apps/utils/net/tcpsvcs/skelserver.c
--- trunk/reactos/apps/utils/net/tcpsvcs/skelserver.c 2005-10-18
13:32:32 UTC (rev 18552)
+++ trunk/reactos/apps/utils/net/tcpsvcs/skelserver.c 2005-10-18
17:06:36 UTC (rev 18553)
@@ -1,3 +1,17 @@
+/*
+ * ReactOS Services
+ * Copyright (C) 2005 ReactOS Team
+ *
+ * LICENCE: GPL - See COPYING in the top level directory
+ * PROJECT: ReactOS simple TCP/IP services
+ * FILE: apps/utils/net/tcpsvcs/skelserver.c
+ * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd
services
+ * PROGRAMMERS: Ged Murphy (gedmurphy(a)gmail.com)
+ * REVISIONS:
+ * GM 04/10/05 Created
+ *
+ */
+
#include <stdio.h>
#include <winsock2.h>
#include <tchar.h>
@@ -3,5 +17,4 @@
#include "tcpsvcs.h"
-
DWORD WINAPI StartServer(LPVOID lpParam)
{
@@ -26,7 +39,7 @@
printf("Acceptor restarting...\n");
}
- /* won't see this yet as we kill the service */
+ /* won't see this yet as we kill the service with ctrl+c */
_tprintf(_T("Detaching Winsock2...\n"));
WSACleanup();
return 0;
_____
Modified: trunk/reactos/apps/utils/net/tcpsvcs/tcpsvcs.c
--- trunk/reactos/apps/utils/net/tcpsvcs/tcpsvcs.c 2005-10-18
13:32:32 UTC (rev 18552)
+++ trunk/reactos/apps/utils/net/tcpsvcs/tcpsvcs.c 2005-10-18
17:06:36 UTC (rev 18553)
@@ -1,3 +1,23 @@
+/*
+ * ReactOS Services
+ * Copyright (C) 2005 ReactOS Team
+ *
+ * LICENCE: GPL - See COPYING in the top level directory
+ * PROJECT: ReactOS simple TCP/IP services
+ * FILE: apps/utils/net/tcpsvcs/tcpsvcs.c
+ * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd
services
+ * PROGRAMMERS: Ged Murphy (gedmurphy(a)gmail.com)
+ * REVISIONS:
+ * GM 04/10/05 Created
+ *
+ */
+/*
+ * TODO:
+ * - Start tcpsvcs as a service.
+ * - write debugging function and print all dbg info via that.
+ *
+ */
+
#include <stdio.h>
#include <winsock2.h>
#include <tchar.h>
@@ -12,7 +32,7 @@
FILE *hLogFile;
BOOL bLogEvents = TRUE;
BOOL ShutDown, PauseFlag;
-LPTSTR LogFileName = "tcpsvcs_log.txt";
+LPCTSTR LogFileName = "tcpsvcs_log.log";
static SERVICE_TABLE_ENTRY
ServiceTable[2] =
@@ -40,7 +60,7 @@
WSADATA wsaData;
DWORD RetVal;
INT i;
-
+
if ((RetVal = WSAStartup(MAKEWORD(2, 2), &wsaData)) != 0)
{
_tprintf(_T("WSAStartup() failed : %lu\n"), RetVal);
@@ -64,7 +84,7 @@
if (hThread[i] == NULL)
{
_tprintf(_T("Failed to start %s server....\n"),
Services[i].Name);
- ExitProcess(i);
+ //ExitProcess(i);
}
}
@@ -81,7 +101,7 @@
-/* code to run tcpsvcs as a service */
+/* code to run tcpsvcs as a service through services.msc */
#if 0
int
main(int argc, char *argv[])
@@ -105,7 +125,7 @@
hLogFile = fopen(LogFileName, _T("w+"));
if (hLogFile == NULL)
return;
-
+
LogEvent(_T("Entering ServiceMain"), 0, FALSE);
hServStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
@@ -116,14 +136,14 @@
hServStatus.dwServiceSpecificExitCode = 0;
hServStatus.dwCheckPoint = 0;
hServStatus.dwWaitHint = 2*CS_TIMEOUT;
-
+
hSStat = RegisterServiceCtrlHandler("tcpsvcs", ServerCtrlHandler);
if (hSStat == 0)
LogEvent(_T("Failed to register service\n"), 100, TRUE);
- LogEvent(_T("Control handler registered successfully"), 0, FALSE);
- SetServiceStatus (hSStat, &hServStatus);
- LogEvent(_T("Service status set to SERVICE_START_PENDING"), 0,
FALSE);
+ LogEvent(_T("Control handler registered successfully"), 0,
FALSE);
+ SetServiceStatus (hSStat, &hServStatus);
+ LogEvent(_T("Service status set to SERVICE_START_PENDING"), 0,
FALSE);
if (CreateServers() != 0)
{
@@ -132,15 +152,15 @@
SetServiceStatus(hSStat, &hServStatus);
return;
}
+
+ LogEvent(_T("Service threads shut down. Set SERVICE_STOPPED
status"), 0, FALSE);
+ /* We will only return here when the ServiceSpecific function
+ completes, indicating system shutdown. */
+ UpdateStatus (SERVICE_STOPPED, 0);
+ LogEvent(_T("Service status set to SERVICE_STOPPED"), 0, FALSE);
+ fclose(hLogFile); /* Clean up everything, in general */
+ return;
- LogEvent(_T("Service threads shut down. Set SERVICE_STOPPED
status"), 0, FALSE);
- /* We will only return here when the ServiceSpecific function
- completes, indicating system shutdown. */
- UpdateStatus (SERVICE_STOPPED, 0);
- LogEvent(_T("Service status set to SERVICE_STOPPED"), 0, FALSE);
- fclose(hLogFile); /* Clean up everything, in general */
- return;
-
}
VOID WINAPI
@@ -173,12 +193,12 @@
void UpdateStatus (int NewStatus, int Check)
/* Set a new service status and checkpoint (either specific value or
increment) */
{
- if (Check < 0 ) hServStatus.dwCheckPoint++;
- else hServStatus.dwCheckPoint = Check;
- if (NewStatus >= 0) hServStatus.dwCurrentState = NewStatus;
- if (!SetServiceStatus (hSStat, &hServStatus))
- LogEvent (_T("Cannot set service status"), 101, TRUE);
- return;
+ if (Check < 0 ) hServStatus.dwCheckPoint++;
+ else hServStatus.dwCheckPoint = Check;
+ if (NewStatus >= 0) hServStatus.dwCurrentState = NewStatus;
+ if (!SetServiceStatus (hSStat, &hServStatus))
+ LogEvent (_T("Cannot set service status"), 101, TRUE);
+ return;
}
INT
@@ -187,7 +207,7 @@
DWORD dwThreadId[NUM_SERVICES];
HANDLE hThread[NUM_SERVICES];
INT i;
-
+
UpdateStatus(-1, -1); /* increment checkpoint */
/* Create MAX_THREADS worker threads. */
@@ -223,38 +243,37 @@
}
-/* LogEvent is similar to the ReportError function used elsewhere
- For a service, however, we ReportEvent rather than write to
standard
- error. Eventually, this function should go into the utility
- library. */
+/* LogEvent is similar to the ReportError function used elsewhere
+ For a service, however, we ReportEvent rather than write to
standard
+ error. Eventually, this function should go into the utility
+ library. */
VOID
LogEvent (LPCTSTR UserMessage, DWORD ExitCode, BOOL PrintErrorMsg)
{
- DWORD eMsgLen, ErrNum = GetLastError ();
- LPTSTR lpvSysMsg;
- TCHAR MessageBuffer[512];
+ DWORD eMsgLen, ErrNum = GetLastError ();
+ LPTSTR lpvSysMsg;
+ TCHAR MessageBuffer[512];
- if (PrintErrorMsg) {
- eMsgLen = FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM, NULL,
- ErrNum, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR)&lpvSysMsg, 0, NULL);
+ if (PrintErrorMsg) {
+ eMsgLen = FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER
|
+ FORMAT_MESSAGE_FROM_SYSTEM, NULL,
+ ErrNum, MAKELANGID (LANG_NEUTRAL,
SUBLANG_DEFAULT),
+ (LPTSTR)&lpvSysMsg, 0, NULL);
- _stprintf (MessageBuffer, _T("\n%s %s ErrNum = %d. ExitCode =
%d."),
- UserMessage, lpvSysMsg, ErrNum, ExitCode);
- HeapFree (GetProcessHeap (), 0, lpvSysMsg);
- /* Explained in Chapter 6. */
- } else {
- _stprintf (MessageBuffer, _T("\n%s ExitCode = %d."),
- UserMessage, ExitCode);
- }
+ _stprintf (MessageBuffer, _T("\n%s %s ErrNum = %d.
ExitCode = %d."),
+ UserMessage, lpvSysMsg, ErrNum, ExitCode);
+ HeapFree (GetProcessHeap (), 0, lpvSysMsg);
+ } else {
+ _stprintf (MessageBuffer, _T("\n%s ExitCode = %d."),
+ UserMessage, ExitCode);
+ }
- fputs (MessageBuffer, hLogFile);
+ fputs (MessageBuffer, hLogFile);
- if (ExitCode > 0)
- ExitProcess (ExitCode);
- else
- return;
+ if (ExitCode > 0)
+ ExitProcess (ExitCode);
+ else
+ return;
}
#endif
_____
Modified: trunk/reactos/apps/utils/net/tcpsvcs/tcpsvcs.h
--- trunk/reactos/apps/utils/net/tcpsvcs/tcpsvcs.h 2005-10-18
13:32:32 UTC (rev 18552)
+++ trunk/reactos/apps/utils/net/tcpsvcs/tcpsvcs.h 2005-10-18
17:06:36 UTC (rev 18553)
@@ -1,3 +1,17 @@
+/*
+ * ReactOS Services
+ * Copyright (C) 2005 ReactOS Team
+ *
+ * LICENCE: GPL - See COPYING in the top level directory
+ * PROJECT: ReactOS simple TCP/IP services
+ * FILE: apps/utils/net/tcpsvcs/tcpsvcs.h
+ * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd
services
+ * PROGRAMMERS: Ged Murphy (gedmurphy(a)gmail.com)
+ * REVISIONS:
+ * GM 04/10/05 Created
+ *
+ */
+
/* default port numbers */
#define ECHO_PORT 7
#define DISCARD_PORT 9
@@ -28,14 +42,14 @@
} SERVICES, *PSERVICES;
-/* tcpsvcs functions * /
-static VOID WINAPI ServiceMain(DWORD argc, LPTSTR argv[]);
+/* tcpsvcs functions */
+//static VOID WINAPI ServiceMain(DWORD argc, LPTSTR argv[]);
VOID WINAPI ServerCtrlHandler(DWORD control);
INT CreateServers(VOID);
VOID LogEvent (LPCTSTR UserMessage, DWORD ExitCode, BOOL
PrintErrorMsg);
void UpdateStatus (int NewStatus, int Check);
-*/
+
/* skelserver functions */
DWORD WINAPI StartServer(LPVOID lpParam);
SOCKET SetUpListener(const char* ServAddr, int Port);
_____
Modified: trunk/reactos/apps/utils/net/tcpsvcs/tcpsvcs.xml
--- trunk/reactos/apps/utils/net/tcpsvcs/tcpsvcs.xml 2005-10-18
13:32:32 UTC (rev 18552)
+++ trunk/reactos/apps/utils/net/tcpsvcs/tcpsvcs.xml 2005-10-18
17:06:36 UTC (rev 18553)
@@ -12,6 +12,5 @@
<file>daytime.c</file>
<file>qotd.c</file>
<file>chargen.c</file>
- <file>quotes.rc</file>
<file>tcpsvcs.rc</file>
</module>