소스 검색

fixed fifo at client side

wangyu- 7 년 전
부모
커밋
a3535364fa
2개의 변경된 파일26개의 추가작업 그리고 1개의 파일을 삭제
  1. 25 0
      client.cpp
  2. 1 1
      network.cpp

+ 25 - 0
client.cpp

@@ -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()

+ 1 - 1
network.cpp

@@ -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;