Optimize gcc10 compilation error

Set the maximum number of open files per process
This commit is contained in:
aixiao 2020-09-09 21:55:48 +08:00
parent 9ba3f7dcf1
commit c7d9d6ab03
9 changed files with 42 additions and 26 deletions

View File

@ -2,7 +2,7 @@ global {
uid=3004;
process=2;
timeout=60;
sslencoding=128;
encode=128;
tcp_listen=0124;
dns_listen=0125;
}

View File

@ -1,7 +1,7 @@
CROSS_COMPILE ?=
CC := $(CROSS_COMPILE)gcc
STRIP := $(CROSS_COMPILE)strip
CFLAGS += -g -O2 -Wall -pthread -fcommon
CFLAGS += -g -O2 -Wall -pthread
LIBS =
OBJ := CProxy

2
conf.c
View File

@ -114,7 +114,7 @@ static void parse_global_module(char *content, conf * p)
p->process = atoi(val_begin);
} else if (strcasecmp(var, "timeout") == 0) {
p->timeout = atoi(val_begin);
} else if (strcasecmp(var, "sslencoding") == 0) {
} else if (strcasecmp(var, "encode") == 0) {
p->sslencoding = atoi(val_begin);
} else if (strcasecmp(var, "tcp_listen") == 0) {
p->tcp_listen = atoi(val_begin);

View File

@ -2,6 +2,8 @@
#include "main.h"
int sslEncodeCode;
int remote_port;
char remote_host[128];
/* 对数据进行编码 */
void dataEncode(char *data, int data_len)

View File

@ -7,9 +7,8 @@
#define HTTP_TYPE 0
#define OTHER_TYPE 1
int remote_port;
char remote_host[128];
extern int remote_port;
extern char remote_host[128];
extern int sslEncodeCode;
typedef struct conn_t {

View File

@ -13,6 +13,8 @@ char *cachePath = NULL;
struct dns_cache *cache, *cache_temp;
socklen_t addr_len = sizeof(dst_addr);
unsigned int cache_using, cacheLimit;
dns_t dns_list[DNS_MAX_CONNECTION];
struct epoll_event evs[DNS_MAX_CONNECTION+1], event;
int read_cache_file()
{
@ -152,9 +154,9 @@ void respond_clients()
dns_list[i].wait_response_client = 0;
}
}
ev.events = EPOLLIN;
ev.data.fd = dnsListenFd;
epoll_ctl(dns_efd, EPOLL_CTL_MOD, dnsListenFd, &ev);
event.events = EPOLLIN;
event.data.fd = dnsListenFd;
epoll_ctl(dns_efd, EPOLL_CTL_MOD, dnsListenFd, &event);
}
/* 分析DNS请求 */
@ -245,9 +247,9 @@ int build_dns_response(dns_t * dns)
}
if (respond_client(dns) == 1) {
dns->wait_response_client = 1;
ev.events = EPOLLIN | EPOLLOUT;
ev.data.fd = dnsListenFd;
epoll_ctl(dns_efd, EPOLL_CTL_MOD, dnsListenFd, &ev);
event.events = EPOLLIN | EPOLLOUT;
event.data.fd = dnsListenFd;
epoll_ctl(dns_efd, EPOLL_CTL_MOD, dnsListenFd, &event);
}
return 0;
@ -263,9 +265,9 @@ void http_out(dns_t * out)
if (write_len == out->http_request_len) {
//puts("write success");
free(out->http_request);
ev.events = EPOLLIN | EPOLLET;
ev.data.ptr = out;
epoll_ctl(dns_efd, EPOLL_CTL_MOD, out->fd, &ev);
event.events = EPOLLIN | EPOLLET;
event.data.ptr = out;
epoll_ctl(dns_efd, EPOLL_CTL_MOD, out->fd, &event);
} else if (write_len > 0) {
//puts("write a little");
out->http_request_len -= write_len;
@ -414,9 +416,9 @@ void new_client(conf *configure)
dns->http_request_len = strlen(dns->http_request);
//printf("%s\n", dns->http_request);
ev.events = EPOLLOUT | EPOLLERR | EPOLLET;
ev.data.ptr = dns;
epoll_ctl(dns_efd, EPOLL_CTL_ADD, dns->fd, &ev);
event.events = EPOLLOUT | EPOLLERR | EPOLLET;
event.data.ptr = dns;
epoll_ctl(dns_efd, EPOLL_CTL_ADD, dns->fd, &event);
}
void *httpdns_loop(void *p)
@ -430,9 +432,9 @@ void *httpdns_loop(void *p)
perror("epoll_create");
return NULL;
}
ev.data.fd = dnsListenFd;
ev.events = EPOLLIN;
epoll_ctl(dns_efd, EPOLL_CTL_ADD, dnsListenFd, &ev);
event.data.fd = dnsListenFd;
event.events = EPOLLIN;
epoll_ctl(dns_efd, EPOLL_CTL_ADD, dnsListenFd, &event);
memset(dns_list, 0, sizeof(dns_list));
while (1) {

View File

@ -43,8 +43,8 @@ struct dns_cache {
struct dns_cache *next;
};
dns_t dns_list[DNS_MAX_CONNECTION];
struct epoll_event evs[DNS_MAX_CONNECTION+1], ev;
extern dns_t dns_list[DNS_MAX_CONNECTION];
extern struct epoll_event evs[DNS_MAX_CONNECTION+1], event;
void *httpdns_loop(void *p);

11
main.c
View File

@ -14,6 +14,9 @@
struct epoll_event ev, events[MAX_CONNECTION + 1];
int epollfd, server_sock;
conn cts[MAX_CONNECTION];
int local_port;
char local_host[128];
int process;
int create_connection(char *remote_host, int remote_port)
{
@ -227,6 +230,7 @@ void _main(int argc, char *argv[])
char executable_filename[PATH_SIZE] = { 0 };
(void)get_executable_path(path, executable_filename, sizeof(path));
char *inifile = "/CProxy.conf";
struct rlimit rt;
inifile = strcat(path, inifile);
conf *configure = (struct CONF *)malloc(sizeof(struct CONF));
memset(configure, 0, sizeof(struct CONF));
@ -314,6 +318,12 @@ void _main(int argc, char *argv[])
}
}
// 设置每个进程允许打开的最大文件数
rt.rlim_max = rt.rlim_cur = MAX_CONNECTION * 2;
if (setrlimit(RLIMIT_NOFILE, &rt) == -1) {
perror("setrlimit");
}
server_ini(); // 守护进程
httpdns_initialize(configure); // 初始化http_dns
memset(cts, 0, sizeof(cts));
@ -378,4 +388,5 @@ void _main(int argc, char *argv[])
int main(int argc, char *argv[])
{
_main(argc, argv);
return 0;
}

8
main.h
View File

@ -19,15 +19,17 @@
#include <sched.h>
#include <getopt.h>
#include <netinet/in.h>
#include <sys/time.h>
#include <sys/resource.h>
#define MAX_CONNECTION 1020
#define BUFFER_SIZE 8192
#define PATH_SIZE 270
#define CACHE_SIZE 270
int local_port;
char local_host[128];
int process;
extern int local_port;
extern char local_host[128];
extern int process;
extern int epollfd;
extern struct epoll_event ev, events[MAX_CONNECTION + 1];