/* * server
c * * Created on: 2025-6-15 * Author: root */#include #include #include #include #include #include #include #include #include#define PORT 7999#define MAX_NUM 3 //client 连接最大个数#define MAX_CLIENT 15#define MAX_SIZE 1024pthread_rwlock_t idx_lock, wait_lock;//client 信息typedef struct _client {int sockfd;char name[20];pthread_t pid;int flg;} c_client;c_client client[MAX_CLIENT];//定义 client;//等待的 clientstruct _client_ {int sockfd;char name[20];pthread_t pid;struct _client_ *next;};typedef struct _client_ c_client_c;c_client_c *head = NULL;c_client_c *temp_c1 = NULL, *temp_c2 = NULL;//等待的//初始化 client 信息void init_client() {int i = 0;for (i = 0; i < MAX_CLIENT; i++) {client[i]
sockfd = -1;memset(client[i]
name, 0, 20);client[i]
pid = -1;client[i]
flg = -1;}}//查找结构体数组中 sockfd 为-1 的下标值int