ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/CCSFinger/CCSFinger.cpp
(Generate patch)

Comparing CCSFinger/CCSFinger.cpp (file contents):
Revision 595 by douglas, 2005-11-27T17:57:41-08:00 vs.
Revision 596 by douglas, 2005-11-27T18:58:37-08:00

# Line 6 | Line 6
6  
7   #include <windows.h>
8   #include <tchar.h>
9 + #include <signal.h>
10  
11   #include <iostream>
12  
# Line 15 | Line 16 | SERVICE_STATUS_HANDLE handle;
16   HANDLE stop;
17   WSADATA data;
18  
19 + void FingerDaemon();
20 + void FingerStop(int);
21   void WINAPI FingerMain(DWORD argc, LPTSTR *argv);
22   void WINAPI FingerControl(DWORD control);
23  
# Line 51 | Line 54 | int _tmain(int argc, TCHAR *argv[])
54          return 0;
55  
56   go:
57 <        std::cout << "Here!" << std::endl;
57 >        signal(SIGINT, FingerStop);
58 >
59 >        try
60 >        {
61 >                FingerDaemon();
62 >        }
63 >        catch (...) {}
64  
65          return 0;
66   }
67  
68 < void WINAPI FingerMain(DWORD argc, LPTSTR *argv)
68 > void FingerDaemon()
69   {
61        name = argv[0];
62        handle = RegisterServiceCtrlHandler(name, LPHANDLER_FUNCTION(FingerControl));
63        stop = CreateEvent(NULL, TRUE, FALSE, NULL);
64
65        //
66
70          WSAStartup(MAKEWORD(2, 0), &data);
71  
72          //
73  
71        status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
72        status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
73        status.dwServiceSpecificExitCode = 0;
74        status.dwCurrentState = SERVICE_RUNNING;
75        status.dwWin32ExitCode = NO_ERROR;
76        status.dwCheckPoint = 0;
77        status.dwWaitHint = 0;
78
79        SetServiceStatus(handle, &status);
80
74          SOCKET sock(socket(PF_INET, SOCK_STREAM, IPPROTO_TCP));
75          SOCKADDR_IN service;
76          
# Line 96 | Line 89 | void WINAPI FingerMain(DWORD argc, LPTST
89          //
90  
91          WSACleanup();
92 + }
93 +
94 + void FingerStop(int)
95 + {
96 +        SetEvent(stop);
97 +
98 +        std::cout << "Stop!" << std::endl;
99 + }
100 +
101 + void WINAPI FingerMain(DWORD argc, LPTSTR *argv)
102 + {
103 +        name = argv[0];
104 +        handle = RegisterServiceCtrlHandler(name, LPHANDLER_FUNCTION(FingerControl));
105 +        stop = CreateEvent(NULL, TRUE, FALSE, NULL);
106 +
107 +        //
108 +
109 +        status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
110 +        status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
111 +        status.dwServiceSpecificExitCode = 0;
112 +        status.dwCurrentState = SERVICE_RUNNING;
113 +        status.dwWin32ExitCode = NO_ERROR;
114 +        status.dwCheckPoint = 0;
115 +        status.dwWaitHint = 0;
116 +
117 +        SetServiceStatus(handle, &status);
118 +
119 +        try
120 +        {
121 +                FingerDaemon();
122 +        }
123 +        catch (...) {}
124  
125          status.dwCurrentState = SERVICE_STOPPED;
126          status.dwWin32ExitCode = NO_ERROR;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines