Kaynağa Gözat

分站通信异常

lixioayao 6 yıl önce
ebeveyn
işleme
05754ab0f8
4 değiştirilmiş dosya ile 13 ekleme ve 3 silme
  1. 6 2
      net-service.cpp
  2. 1 0
      net-service.h
  3. 5 1
      znet.cpp
  4. 1 0
      znet.h

+ 6 - 2
net-service.cpp

@@ -45,7 +45,10 @@ void net_service::on_timer()
 	card_list::instance()->accept(clv);
 	mine_business::inst()->run_business();
 }
-
+void net_service::on_connect(std::shared_ptr<client> clt)
+{
+     
+}
 void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t len)
 {
 	bool message_handled=true;
@@ -85,6 +88,7 @@ void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t
 
 					site_ptr->set_client(clt);
 					site_ptr->on_power_status((power&1)==0);
+                    clt->set_site_id(site_id);
 
 					struct timeval tv;
 					gettimeofday(&tv,NULL);
@@ -145,7 +149,7 @@ void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t
 	}
 	catch(const std::exception&e)
 	{
-		logn_error(1,"分站数据处理失败,将关闭分站连接:%s",clt->name().c_str());
+		logn_error(1,"分站数据处理失败,将关闭分站连接:%s [%s]",clt->name().c_str(),e.what());
 		clt->close();
 	}
 

+ 1 - 0
net-service.h

@@ -16,6 +16,7 @@ struct net_service:service_callback
 	~net_service();
 	void on_message(std::shared_ptr<client> clt,const char*data,size_t len);
 	void on_timer();
+    void on_connect(std::shared_ptr<clinet> clt);
 };
 
 #endif

+ 5 - 1
znet.cpp

@@ -202,6 +202,7 @@ struct sock_client:fd_io,client_ex
 	std::vector<char> m_obuf;
 	size_t m_opos=0;
 	bool   m_can_write{false};
+    int     m_site_id{-1};
 
 //	char m_timestamp[8];
 
@@ -334,7 +335,10 @@ struct sock_client:fd_io,client_ex
 	{
 		return m_fd;
 	}
-
+    void set_site_id(int sid)
+    {
+        m_site_id=id;
+    }
 	void grow_buf(int len)
 	{
 		if(m_size-m_clen>=len)

+ 1 - 0
znet.h

@@ -56,6 +56,7 @@ struct service_callback:service_handle
 
 	virtual void on_connect(std::shared_ptr<client> clt)
 	{
+		log_info("client(%s) connected",clt->name().c_str());
 	}
 
 	virtual void on_close(std::shared_ptr<client> clt)