extern void wdog_proc();
wdog_proc();
#include "qtcpportlist.h"#include "QFile"extern void wdog_proc();// глобальная переменная для чтения конфигурацииstatic QFile* cfgFile = NULL;//static QFile* shadow_file = NULL;#define DEFAULT_CONFIG_TEMPLATE "config.csv"// функции класса списка всех портов в памяти////////////////////////////////////////////////////////////////////////////////// конструктор////////////////////////////////////////////////////////////////////////////////QTcpPortList::QTcpPortList(QObject *parent,bool flag_wdog) : QObject(parent){ // инициализация таймера, для проверки списка портов m_iTimerID = startTimer(PORTLIST_TIMER_INTERVAL); flag_file = false; flag_msg_nofile = false; flag_msg_empty = false; wdog_timer = 0; wdog = flag_wdog;}////////////////////////////////////////////////////////////////////////////////// деструктор////////////////////////////////////////////////////////////////////////////////QTcpPortList::~QTcpPortList(){ // закрываем конфигурационный файл, если он был открыт if (cfgFile) { cfgFile->close(); delete cfgFile; cfgFile = NULL; }}////////////////////////////////////////////////////////////////////////////////// Обработчик событий таймера////////////////////////////////////////////////////////////////////////////////void QTcpPortList::timerEvent(QTimerEvent *event){ // проверяем, что событие от нужного таймера Порт if ( event->timerId() == m_iTimerID ) { //вызов процедуры wdog_proc раз в 10 сек if (wdog) if (wdog_timer<10) { wdog_timer++; } else { wdog_proc(); wdog_timer = 0; }...
#include <unistd.h>#include <errno.h>#include <stdio.h>#include <stdlib.h>#include <signal.h>#include <termios.h>#include <fcntl.h>#include <sys/types.h>#include <sys/socket.h>#include <sys/stat.h>#include <netinet/in.h>#include <netdb.h>#include <string.h>#include <time.h>typedef uint8_t byte;typedef uint16_t word;typedef int16_t sword;typedef uint32_t dword;typedef int32_t sdword;typedef uint64_t qword;typedef int64_t sqword;typedef double dbl;#pragma pack(1)typedef struct { word len; word task; dword pid; dword ip; word port; word flags; word devs; word func; } s_wdpoll;#pragma pack()s_wdpoll wd_pack= {sizeof(s_wdpoll), 2, 0, 0, 0, 0, 0, 0};int wd_fd;fd_set wd_fdset;extern dword wdog_port;//***************************************************** init_c127static int init_c127(int port, int *pfd, int stream) {struct sockaddr_in s_sock;if (*pfd > 0) close(*pfd);s_sock.sin_family = AF_INET;s_sock.sin_port = htons(port);s_sock.sin_addr.s_addr= htonl(0x7f000001);if ((*pfd= socket(PF_INET, stream, 0)) < 0) { *pfd=0; return -1; }if (connect(*pfd, (struct sockaddr *)&s_sock, sizeof((s_sock))) < 0) { close(*pfd); *pfd=0; return -3; }return 0;}//***************************************************** wdog_procvoid wdog_proc() {struct timeval tout;static char buf[128];if (!wd_fd) { if (!wdog_port) return; if (init_c127(wdog_port, &wd_fd, SOCK_STREAM)) { wd_fd= 0; return; } wd_pack.pid= getpid(); FD_ZERO(&wd_fdset); }tout.tv_usec= tout.tv_sec= 0;FD_SET(wd_fd, &wd_fdset);while (select(FD_SETSIZE, &wd_fdset, 0, 0, &tout) > 0) if (read(wd_fd, buf, sizeof(buf)) <= 0) { close(wd_fd); wd_fd= 0; return; }if (write(wd_fd, &wd_pack, wd_pack.len) != wd_pack.len) { close(wd_fd); wd_fd= 0; return;}}
C++ (Qt)extern "C" { extern void wdog_proc();}