| |

VerySource

 Forgot password?
 Register
Search
View: 797|Reply: 1

C ++ daemon

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-8 15:43:07
| Show all posts |Read mode
[font = 宋体] [size = 16pt] Chapter 1 [/ size] [/ font] [font = 宋体] [size = 16pt] Function introduction [/ size] [/ font] [/ b ] [/ b] [font = 宋体] [size = 15pt] 1.1 [/ size] [/ font] [font = 宋体] [size = 15pt] Function [/ size] [/ font] [ / b] [/ b] [align = left] l Automatically start the set process when the daemon software starts [/ align] [align = left] l After the process exits, the daemon software will automatically restart [/ align] [align = left] l [font = 宋体] can set the user name and password for remote login [/ font] telnet [font = 宋体] [/ font] [/ align] [align = left] l [font = 宋体] can be accessed via [/ font] telnet [font = 宋体] Control daemon software, the functions that can be executed are described in Chapter 2 [/ font] [/ align] [font = 宋体] [size = 15pt] 1.2 [/ size] [/ font ] [font = 宋体] [size = 15pt] Settings [/ size] [/ font] [/ b] [/ b] [align = left] All information is recorded in the commonDaemon.ini file in the current directory. The contents of the file are as follows. [/ align] [align = left] [setting] [/ align] [align = left] count = 2; [font = 宋体] Number of processes to start [/ font] [/ align] [align = left] [1 ]; [font = 宋体] The serial number of the first process is [/ font] [font = Times New Roman] 1 [/ font] [/ align] [align = left] name = udpTest; [font = 宋体] service name , You can define your own as needed [/ font] [/ align] [align = left] process = .\udpTest.exe; [font = 宋体] filename [/ font] [/ align] [align = left] parameter =; [ font = 宋体] Parameters when starting the process [/ font] [/ align] [align = left] directory = .\; [font = 宋体] working directory [/ font] [/ align] [align = left] auto = 1 ; [font = 宋体] Whether to restart automatically, [/ font] [font = Times New Roman] 1 [/ font] [font = 宋体]: Automatic restart, [/ font] [font = Times New Roman] 0 [/ font ] [font = 宋体]: Do not restart automatically [/ font] [/ align] [align = left] [2]; [font = 宋体] The sequence number of the second process is [/ font] [font = Times New Roman] 2 [/ font] [/ align] [align = left] name = tcpTest.exe [/ align] [align = left] process = .\tcpTest.exe [/ align] [align = left] parameter = [/ align] [ align = left] directory = .\[/ align] [align = left] au to = 0 [/ align] [align = left] [user]; [font = 宋体] username and password for remote login [/ font] [/ align] [align = left] user = pwd; [font = 宋体] etc. The user name is on the left side of the number, and the password is on the right side of the equal sign. Empty passwords are not allowed. = Songti] [size = 15pt] 1.3 [/ size] [/ font] [font = Songti] [size = 15pt] Constants in software [/ size] [/ font] [/ b] [/ b] [align = left] l common daemon [font = 宋体] Remote monitoring [/ font] [font = Times New Roman] LISTEN [/ font] [font = 宋体] Port [/ font]
#define DAEMON_REMOTE_MONITOR_PORT 3411 [/ align] [align = left] l Text output window name
#define SCREEN_NAME "common_daemon" [/ align] [align = left] l Log save directory
#define LOG_DIR ".\\log" [/ align] [align = left] l log file name
#define LOG_NAME "common_daemon_log" [/ align] [align = left] l Configuration file name
#define INI_FILENAME ".\\commonDaemon.ini" [/ align] [font = 宋体] [size = 15pt] 1.4 [/ size] [/ font] [font = 宋体] [size = 15pt] interface [ / size] [/ font] [/ b] [/ b] [align = left] [/ align] [align = left] [/ align] [font = 宋体] [size = 16pt] Chapter 2 [ / size] [/ font] [font = 宋体] [size = 16pt] Remote monitoring command [/ size] [/ font] [/ b] [/ b] [font = 宋体] [size = 15pt] 2.1 [/ size] [/ font] [font = 宋体] [size = 15pt] Function [/ size] [/ font] [/ b] [/ b] [align = left] [font = 宋体] After connecting through remote monitoring software ([/ font] telnet [font = 宋体]) and logging in, you can execute the following command: [/ font] [/ align] [align = left] h [font = 宋体] to display help information. [/ font] [/ align] [align = left] c xxx [font = 宋体] stop [/ font] [font = Times New Roman] xxx [/ font] [font = 宋体] check the service and stop [ / font] [font = Times New Roman] xxx [/ font] [font = 宋体] service will automatically restart. [/ font] [/ align] [align = left] o xxx [font = 宋体] started [/ font] [font = Times New Roman] xxx [/ font] [font = 宋体] / font] [font = Times New Roman] xxx [/ font] [font = 宋体] service will automatically restart. [/ font] [/ align] [align = left] l [font = 宋体] lists all services and lists all configuration data. [/ font] [/ align] [align = left] k xxx [font = 宋体] Forces the specified process to close. [/ font] [/ align] [font = 宋体] [size = 15pt] 2.2 [/ size] [/ font] [font = 宋体] [size = 15pt] Interface [/ size] [/ font] [/ b] [/ b] [align = left] [/ align] [align = left] [/ align] [font = 宋体] [size = 16pt] Chapter 3 [/ size] [/ font] [font = 宋体] [size = 16pt] A description of the program [/ size] [/ font] [/ b] [/ b] [font = 宋体] [size = 15pt] 3.1 [ / size] [/ font] [font = 宋体] [size = 15pt] Start the process [/ size] [/ font] [/ b] [/ b] [align = left] l [font = 宋体] Initialization [/ font] Socket [font = 宋体]: [/ font] AfxSocketInit [/ align] [align = left] l Initialize each daemon thread: InitDaemonEnv [/ align] [align = left] n Initialize the text output window [/ align] [align = left] n Read configuration information: glo_iniDaemon.InitData () [/ align] [align = left] n Initialize the remote monitoring listener thread: InitDeamonRemoteMonitor () [/ align] [align = left] l Execute the daemon thread: RunDaemon [/ align] [font = 宋体] [size = 15pt] 3.2 [/ size] [/ font] [font = 宋体] [size = 15pt] Daemon thread execution process [/ size] [/ font ] [/ b] [/ b] [align = left] Function: BOOL RunDaemon (void), completes the startup of the process, if already started The process exits and restarts again. [/ align] [align = left] for (int i = 0; i <glo_iniDaemon.m_iMaxProcess; i ++) [/ align] [align = left] {// [font = 宋体] judge each item in the configuration [/ font] [/ align] [align = left] if (glo_iniDaemon.m_arrEntry .fAutoStart) [/ align] [align = left] {[/ align] [align = left] glo_lockProcess.Access (); / / [font = 宋体] locks data to prevent multiple threads from modifying it at the same time [/ font] [/ align] [align = left] if (glo_hProcess == NULL) [/ align] [align = left] {// [ font = 宋体] The process is not executed else [/ align] [align = left] {// [font = 宋体] Check if the thread has exited and restart if it has already exited [/ font] [/ align] [align = left] CheckProcess (glo_hProcess , i); [/ align] [align = left]} [/ align] [align = left] glo_lockProcess.LeaveAccess (); // [font = 宋体] contact data lock [/ font] [/ align] [align = left ]} [/ align] [align = left]} [/ align] [font = 宋体] [size = 15pt] 3.3 [/ size] [/ font] [font = 宋体] [size = 15pt ] Remote monitoring service class [/ size] [/ font ] [/ b] [/ b] [font = 宋体] [size = 14pt] 3.3.1 [/ size] [/ font] [font = 宋体] [size = 14pt] Remotely monitor connection elements Class [/ size] [/ font] [/ b] [/ b] [align = left] class CDaemonRmtCtrlEle: public CRmtCtrlElement [/ align] [align = left] records information about a single connection. [/ align] [font = 宋体] [size = 14pt] 3.3.2 [/ size] [/ font] [font = 宋体] [size = 14pt] Remote monitoring connection management class [/ size] [/ font] [/ b] [/ b] [align = left] class CDaemonRmtCtrlResMan: public CRmtCtrlResMan [/ align] [align = left] manages all connection information. The class contains a collection of CDaemonRmtCtrlEle objects. In addition, CDaemonRmtCtrlResMan will Handles synchronous access to the collection of connection information (CDaemonRmtCtrlEle). [/ align] [font = 宋体] [size = 15pt] 3.4 [/ size] [/ font] [font = 宋体] [size = 15pt] Remote monitoring service thread [/ size] [/ font ] [/ b] [/ b] [align = left] The thread function DWORD DaemonRemoteMonitorThread (UINT uHandle). [/ align] [align = left] This function will be created as a thread after remote monitoring establishes a connection. Then complete the monitoring process. [/ align] [font = 宋体] [size = 15pt] 3.5 [/ size] [/ font] [font = 宋体] [size = 15pt] Other development kits and classes used [/ size ] [/ font] [/ b] [/ b] [font = 宋体] [size = 15pt] 3.6 [/ size] [/ font] [font = 宋体] [size = 15pt] Screen output Class [/ size] [/ font] [/ b] [/ b] [align = left] consoleTxtWnd.h [/ align] [align = left] consoleTxtWnd.cpp [/ align] [font = 宋体] [ size = 14pt] 3.6.1 [/ size] [/ font] [font = 宋体] [size = 14pt] Resource Management Class [/ size] [/ font] [/ b] [/ b] [align = left] resManBase.h [/ align] [align = left] resManBase.cpp [font = 宋体] implement resource management [/ font] [/ align] [align = left] resManBaseLock.cpp [font = 宋体] implement various access Lock control [/ font] [/ align] [font = 宋体] [size = 14pt] 3.6.2 [/ size] [/ font] [font = 宋体] [size = 14pt] Remote connection management Class [/ size] [/ font] [/ b] [/ b] [align = left] rmtCtrlElement.h [/ align] [align = left] rmtCtrlElement.cpp [font = 宋体] implements management of remote connection resources [ / font] [/ align] [font = 宋体] [size = 14pt] 3.6.3 [/ size] [/ font] [font = 宋体] [size = 14pt] Socket [font = 宋体] Function [/ font] [/ size] [/ font] [/ b] [/ b] [align = left] socketFun.h [/ align] [align = left] socketFun.cpp [/ align] [align = left] [/ align] [align = left] [/ align]
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-8 15:43:57
| Show all posts
well
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list