Browse Source

实现广播代码

zzj 6 years ago
parent
commit
c2fc11de08
2 changed files with 16 additions and 6 deletions
  1. 4 1
      main.cpp
  2. 12 5
      znet.cpp

+ 4 - 1
main.cpp

@@ -86,9 +86,12 @@ void cleanup()
 
 int main()
 {
-	log_init("../etc/log.ini");
+	if(log_init("../etc/log.ini"))
+		return -1;
+
 	if(config.open("../etc/config.ini"))
 		return -1;
+
 	Init_Setting is;
 	is.init();
 	

+ 12 - 5
znet.cpp

@@ -42,6 +42,15 @@ public:
 	{
 	}
 
+	void boardcast(const std::vector<char>&msg)
+	{
+		for(auto i:m_thread_clts)
+		{
+			std::vector<char> tmp(msg);
+			i->send(std::move(tmp));
+		}
+	}
+
 	void on_connect(std::shared_ptr<client> clt)
 	{
 		if(clt->handle()>=(int)m_thread_clts.size())
@@ -140,6 +149,7 @@ struct stdin_io:fd_io
 
 	virtual void operator()(ev::io &w, int)
 	{
+#if 0
 		char buf[256];
 		if(!gets(buf))
 			return;
@@ -152,6 +162,7 @@ struct stdin_io:fd_io
 			stop();
 			m_ic.stop();
 		}
+#endif
 	}
 };
 
@@ -163,8 +174,8 @@ struct sock_client:fd_io,client_ex
 	int   m_type=0;//site
 
 	char  *m_b{0};
-	int   m_size{1<<16};
 	int   m_clen{0};
+	int   m_size{1<<16};
 	int   m_max_package_size{4096};
 
 	ev::timer  m_recv_timer;
@@ -513,10 +524,6 @@ struct main_loop:io_context
 			log_errno("block signal:%d",sig);
 		}
 	}
-	void boardcast(const std::vector<char>&msg)
-	{
-	
-	}
 };