fixed fifo at client side

This commit is contained in:
wangyu- 2018-08-29 12:29:41 -05:00
parent 4e9000c6b5
commit a3535364fa
2 changed files with 26 additions and 1 deletions

@ -620,6 +620,31 @@ void clear_timer_cb(struct ev_loop *loop, struct ev_timer *watcher, int revents)
}
void fifo_cb(struct ev_loop *loop, struct ev_io *watcher, int revents)
{
conn_info_t & conn_info= *((conn_info_t*)watcher->data);
char buf[buf_len];
int fifo_fd=watcher->fd;
int len=read (fifo_fd, buf, sizeof (buf));
if(len<0)
{
mylog(log_warn,"fifo read failed len=%d,errno=%s\n",len,get_sock_error());
return;
}
buf[len]=0;
while(len>=1&&buf[len-1]=='\n')
buf[len-1]=0;
mylog(log_info,"got data from fifo,len=%d,s=[%s]\n",len,buf);
if(strcmp(buf,"reconnect")==0)
{
mylog(log_info,"received command: reconnect\n");
conn_info.state.client_current_state=client_idle;
conn_info.my_id=get_true_random_number_nz();
}
else
{
mylog(log_info,"unknown command\n");
}
}
int client_event_loop()

@ -2528,7 +2528,7 @@ int client_bind_to_a_new_port2(int &fd,const address_t& address)//find a free po
for(int i=0;i<1000;i++)//try 1000 times at max,this should be enough
{
tmp.set_port(raw_send_port);
printf("<%s>\n",tmp.get_str());
//printf("<%s>\n",tmp.get_str());
if (try_to_list_and_bind2(fd,tmp)==0)
{
return raw_send_port;