38 lines
824 B
C++
38 lines
824 B
C++
#ifndef SERVER_HEARTBEAT_H
|
|
#define SERVER_HEARTBEAT_H
|
|
|
|
#include <vector>
|
|
#include <thread>
|
|
#include <mutex>
|
|
#include <cstring>
|
|
#include <unistd.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <algorithm>
|
|
#include <iostream>
|
|
|
|
namespace Heartbeat {
|
|
|
|
// 配置常量
|
|
extern const int PORT;
|
|
extern const int TIMEOUT;
|
|
extern const int HEARTBEAT_INTERVAL;
|
|
|
|
// 核心功能
|
|
void start_server();
|
|
|
|
// 内部函数声明
|
|
void send_heartbeat(int client_sock);
|
|
void handle_client(int client_sock, sockaddr_in addr);
|
|
void cleanup_disconnected(int client_sock);
|
|
|
|
// 辅助函数
|
|
bool initialize_socket(int& server_sock);
|
|
void bind_socket(int server_sock, sockaddr_in& server_addr);
|
|
void listen_for_connections(int server_sock);
|
|
void accept_connections(int server_sock);
|
|
|
|
} // namespace Heartbeat
|
|
|
|
#endif // SERVER_HEARTBEAT_H
|