fix close and errno, disable log color by default on mingw

This commit is contained in:
U-DESKTOP-T772REH\wangyu 2018-06-19 21:29:03 +08:00
parent 8c21ff55ab
commit 4b02fdb4bd
6 changed files with 23 additions and 12 deletions

View File

@ -481,12 +481,12 @@ int set_buf_size(int fd,int socket_buf_size,int force_socket_buf)
{
if(setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &socket_buf_size, sizeof(socket_buf_size))<0)
{
mylog(log_fatal,"SO_SNDBUF fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
mylog(log_fatal,"SO_SNDBUF fail socket_buf_size=%d errno=%s\n",socket_buf_size,get_sock_error());
myexit(1);
}
if(setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &socket_buf_size, sizeof(socket_buf_size))<0)
{
mylog(log_fatal,"SO_RCVBUF fail socket_buf_size=%d errno=%s\n",socket_buf_size,strerror(errno));
mylog(log_fatal,"SO_RCVBUF fail socket_buf_size=%d errno=%s\n",socket_buf_size,get_sock_error());
myexit(1);
}
}
@ -772,7 +772,7 @@ int new_connected_socket(int &fd,u32_t ip,int port)
int ret = connect(fd, (struct sockaddr *) &remote_addr_in, slen);
if (ret != 0) {
mylog(log_warn, "[%s]fd connect fail\n",ip_port);
close(fd);
sock_close(fd);
return -1;
}
return 0;

View File

@ -30,7 +30,7 @@ void fd_manager_t::fd64_close(fd64_t fd64)
{
fd_info_mp.erase(fd64);
}
close(fd);
sock_close(fd);
}
void fd_manager_t::reserve(int n)
{

View File

@ -103,6 +103,8 @@ int main(int argc, char *argv[])
ev_signal signal_watcher_sigpipe;
ev_signal_init(&signal_watcher_sigpipe, sigpipe_cb, SIGPIPE);
ev_signal_start(loop, &signal_watcher_sigpipe);
#else
enable_log_color=0;
#endif
ev_signal signal_watcher_sigterm;

View File

@ -601,6 +601,7 @@ void process_arg(int argc, char *argv[])
{"log-level", required_argument, 0, 1},
{"log-position", no_argument, 0, 1},
{"disable-color", no_argument, 0, 1},
{"enable-color", no_argument, 0, 1},
{"disable-filter", no_argument, 0, 1},
{"disable-fec", no_argument, 0, 1},
{"disable-obscure", no_argument, 0, 1},
@ -654,6 +655,10 @@ void process_arg(int argc, char *argv[])
}
}
}
if(strcmp(argv[i],"--enable-color")==0)
{
enable_log_color=1;
}
if(strcmp(argv[i],"--disable-color")==0)
{
enable_log_color=0;
@ -812,6 +817,10 @@ void process_arg(int argc, char *argv[])
{
//enable_log_color=0;
}
else if(strcmp(long_options[option_index].name,"enable-color")==0)
{
//enable_log_color=0;
}
else if(strcmp(long_options[option_index].name,"disable-fec")==0)
{
disable_fec=1;

View File

@ -46,7 +46,7 @@ void data_from_local_or_fec_timeout(conn_info_t & conn_info,int is_time_out)
socklen_t udp_new_addr_len = sizeof(sockaddr_in);
if ((data_len = recvfrom(local_listen_fd, data, max_data_len, 0,
(struct sockaddr *) &udp_new_addr_in, &udp_new_addr_len)) == -1) {
mylog(log_error,"recv_from error,this shouldnt happen,err=%s,but we can try to continue\n",strerror(errno));
mylog(log_error,"recv_from error,this shouldnt happen,err=%s,but we can try to continue\n",get_sock_error());
return;
};
@ -126,12 +126,12 @@ static void remote_cb(struct ev_loop *loop, struct ev_io *watcher, int revents)
mylog(log_trace, "received data from udp fd %d, len=%d\n", remote_fd,data_len);
if(data_len<0)
{
if(errno==ECONNREFUSED)
if(get_sock_errno()==ECONNREFUSED)
{
mylog(log_debug, "recv failed %d ,udp_fd%d,errno:%s\n", data_len,remote_fd,strerror(errno));
mylog(log_debug, "recv failed %d ,udp_fd%d,errno:%s\n", data_len,remote_fd,get_sock_error());
}
mylog(log_warn, "recv failed %d ,udp_fd%d,errno:%s\n", data_len,remote_fd,strerror(errno));
mylog(log_warn, "recv failed %d ,udp_fd%d,errno:%s\n", data_len,remote_fd,get_sock_error());
return;
}
if(!disable_mtu_warn&&data_len>mtu_warn)
@ -187,7 +187,7 @@ static void fifo_cb(struct ev_loop *loop, struct ev_io *watcher, int revents)
int len=read (fifo_fd, buf, sizeof (buf));
if(len<0)
{
mylog(log_warn,"fifo read failed len=%d,errno=%s\n",len,strerror(errno));
mylog(log_warn,"fifo read failed len=%d,errno=%s\n",len,get_sock_error());
return;
}
buf[len]=0;

View File

@ -95,7 +95,7 @@ void data_from_remote_or_fec_timeout_or_conn_timer(conn_info_t & conn_info,fd64_
if(data_len<0)
{
mylog(log_debug,"udp fd,recv_len<0 continue,%s\n",strerror(errno));
mylog(log_debug,"udp fd,recv_len<0 continue,%s\n",get_sock_error());
return;
}
@ -137,7 +137,7 @@ static void local_listen_cb(struct ev_loop *loop, struct ev_io *watcher, int rev
socklen_t udp_new_addr_len = sizeof(sockaddr_in);
if ((data_len = recvfrom(local_listen_fd, data, max_data_len, 0,
(struct sockaddr *) &udp_new_addr_in, &udp_new_addr_len)) == -1) {
mylog(log_error,"recv_from error,this shouldnt happen,err=%s,but we can try to continue\n",strerror(errno));
mylog(log_error,"recv_from error,this shouldnt happen,err=%s,but we can try to continue\n",get_sock_error());
return;
};
mylog(log_trace,"Received packet from %s:%d,len: %d\n", inet_ntoa(udp_new_addr_in.sin_addr),
@ -287,7 +287,7 @@ static void fifo_cb(struct ev_loop *loop, struct ev_io *watcher, int revents)
int len=read (fifo_fd, buf, sizeof (buf));
if(len<0)
{
mylog(log_warn,"fifo read failed len=%d,errno=%s\n",len,strerror(errno));
mylog(log_warn,"fifo read failed len=%d,errno=%s\n",len,get_sock_error());
return;
}
buf[len]=0;