Skip to content

Commit

Permalink
set non-blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu- committed Nov 11, 2017
1 parent 11f8ff0 commit 0f37155
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ int set_timer(int epollfd,int &timer_fd)
its.it_interval.tv_nsec=(timer_interval%1000)*1000ll*1000ll;
its.it_value.tv_nsec=1; //imidiately
timerfd_settime(timer_fd,0,&its,0);
setnonblocking(timer_fd);


ev.events = EPOLLIN;
Expand Down
10 changes: 8 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ int local_port = -1, remote_port = -1;
int max_pending_packet=0;
int enable_udp=0,enable_tcp=0;

const int listen_fd_buf_size=5*1024*1024;

int VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV;


Expand Down Expand Up @@ -269,7 +271,7 @@ int event_loop()
}

setsockopt(local_listen_fd_tcp, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)); //avoid annoying bind problem
set_buf_size(local_listen_fd_tcp,4*1024*1024);
set_buf_size(local_listen_fd_tcp,listen_fd_buf_size);
setnonblocking(local_listen_fd_tcp);


Expand All @@ -280,7 +282,7 @@ int event_loop()
myexit(1);
}
setsockopt(local_listen_fd_udp, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
set_buf_size(local_listen_fd_udp,4*1024*1024);
set_buf_size(local_listen_fd_udp,listen_fd_buf_size);
setnonblocking(local_listen_fd_udp);


Expand Down Expand Up @@ -380,6 +382,10 @@ int event_loop()
mylog(log_warn,"[tcp]accept failed %d %s\n", new_fd,strerror(errno));
continue;
}

set_buf_size(new_fd,socket_buf_size);
setnonblocking(new_fd);

char ip_port_s[30];
sprintf(ip_port_s,"%s:%d",my_ntoa(addr_tmp.sin_addr.s_addr),addr_tmp.sin_port);

Expand Down

0 comments on commit 0f37155

Please sign in to comment.