#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<sys/types.h>
#include<arpa/inet.h>
#include<sys/epoll.h>
#include <unistd.h>
#include<sys/wait.h>
#include<stdio.h>
#include<map>
#include<fstream>
#include<time.h>
#include <unistd.h>
#include <fcntl.h>
#include <dirent.h>
#include<errno.h>
using namespace std;
#define MAX_CON_CNT 1000
#define MAX_EV_CNT 20
static int SER_PORT;
std::map<int, pid_t> ve;
struct flock* file_lock_fun(short type, short whence)
{
static struct flock ret;
ret.l_type = type;
ret.l_start = 0x00;
ret.l_whence = whence;
ret.l_len = 0x05;
ret.l_pid = getpid();
return & ret;
}
void set_noblock(int fd)
{
int opts = fcntl(fd,F_GETFL);
if(opts < 0x00)
{
std::cout<<"set no block failed ....."<<std::endl;
}
else
{
opts |= O_NONBLOCK;
fcntl(fd,F_SETFL,opts);
}
}
int pre_work()
{
int ser_fd = socket(AF_INET,SOCK_STREAM,0x00);
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
addr.sin_port = htons(SER_PORT);
int flag = 0x01;
if(setsockopt(ser_fd,SOL_SOCKET,SO_REUSEADDR, &flag, sizeof(flag)) == -1)
{
std::cout<<"reuse failed ..."<<std::endl;
return -1;
}
if( -1 == bind(ser_fd, (struct sockaddr*)&addr, sizeof(a
一个epoll多进程服务器示例
最新推荐文章于 2024-06-23 18:43:24 发布
本文介绍了一个使用Python编写的基于epoll的多进程服务器示例,探讨了如何实现服务器的负载均衡,但指出该实现仍有待优化。
摘要由CSDN通过智能技术生成