Browse Source

根据日志文件分析是否存在延时重传问题;

zzj 6 years ago
parent
commit
1f07ba41bb
4 changed files with 74 additions and 72 deletions
  1. 31 54
      client.cpp
  2. 42 16
      message_file.cpp
  3. 1 0
      message_file.h
  4. 0 2
      znet.cpp

+ 31 - 54
client.cpp

@@ -1,72 +1,49 @@
 
+#include <time.h>
 #include "log.h"
-#include "zio.h"
 #include "message_file.h"
-#include "thread"
-#include "chrono"
 
-int main()
+time_t site_timestamp(const char*time)
 {
-	int sock=zio::build_stream();
-
-	if(zio::connect(sock,"127.0.0.1",9001))
-	//if(zio::connect(sock,"192.168.8.116",4000))
-	{
-		return -1;
-	}
-
-	zio::setiobuf(sock,32<<10,64<<10);
-	zio::setblocking(sock,false);
-	int len=1;
-	int count=0x400+2;
-	char buf[8192];
-	uint64_t time;
-#if 1
+	//秒、分、时、天、周、月、年, 脑残的设计
 
-	///socket.io/?EIO=4&transport=websocket&t=1551320786
+	struct tm t={0};
 
-	for(int i=0;i<8000;i++)
-	{
-		buf[i]='1';
-	}
+	t.tm_sec=time[0];
+	t.tm_min=time[1];
+	t.tm_hour=time[2];
+	t.tm_mday=time[3];
+	t.tm_mon=time[5]-1;
+	t.tm_year=time[6]+100;
 
-	buf[0]=0x04;
-	buf[1]=0x00;
+	return mktime(&t);
+}
 
-	char recv_buf[8192];
-	for(;;)
-	{
-		while(zio::read(sock,recv_buf,sizeof(recv_buf))>0);
-		if(count!=zio::writev(sock,buf,count))
-			break;
-	}
-#else
+int main()
+{
+	unsigned char b[2048];
+	char m[2048];
 	message_file mf(stdin);
-	count=0;
-	uint64_t time_tmp=0;
-	while(len>0)
+	uint64_t time=0;
+	int len;
+
+	while((len=mf.get_line(&time,(char*)b,sizeof(b),m))>0)
 	{
-		//while((len=mf.get_line(&time,&buf[count],sizeof(buf)-count)))
+		if(!((b[2]==0x84) && (b[3]==0x3b)))
+			continue;
+
+		int diff=abs(time/1000-site_timestamp((const char*)&b[10]));
+		if(diff>300)
 		{
-			std_info("......%lu",time);
-			count+=len;
-			if(count>1024)
-				break;
+			printf("%d:%s\n",diff,m);
+		}
+		else
+		{
+//			printf ("%d\n",diff);
 		}
-		len=mf.get_line(&time,&buf[count],sizeof(buf)-count);
-		if(0==time_tmp)	
-		  time_tmp =time;
-		std::this_thread::sleep_for(std::chrono::milliseconds(time-time_tmp));
-		log_info("count=%d,time=%llu buf=%s",len,time,buf);
-		if(count!=zio::writev(sock,buf,count))
-			break;
-
-		count=0;
 	}
-#endif
-
-	zio::close(sock);
 
 	return 0;
 }
 
+

+ 42 - 16
message_file.cpp

@@ -117,35 +117,61 @@ int message_file::put_line(uint64_t time,char*buf,int buflen)
 	return 0;
 }
 
+int line_type(const char*s)
+{
+	if(s[0]==0 || s[0]=='\n')
+		return 0;
+	
+	if(strncmp("2019-",s,5)==0)
+		return 1;
+	
+	return 2;
+}
+
 int message_file::get_line(uint64_t*time,char*buf,int buflen)
 {
-	const char*p;
-	while(m_last_line[0]!='[')
-	{ 
+	return get_line(time,buf,buflen,0);
+}
+
+int message_file::get_line(uint64_t*time,char*buf,int buflen,char*m)
+{
+	int type=0;
+	
+	while(1)
+	{
 		if(fgets(m_last_line,sizeof(m_last_line),m_file)==nullptr)
 			return 0;
-	}
 
-	{
-		struct tm tm;
-		memset(&tm, 0, sizeof(struct tm));
-		const char*ms=strptime(&m_last_line[1], "%Y-%m-%d %H:%M:%S", &tm);
+		type=line_type(m_last_line);
 
-		*time=1000*mktime(&tm)+atoi(ms+1);
+		if(type==0)
+			continue;
+
+		if(type==1)
+		{
+			struct tm tm;
+			memset(&tm, 0, sizeof(struct tm));
+			const char*ms=strptime(&m_last_line[0], "%Y-%m-%d %H:%M:%S", &tm);
+			*time=1000LL*mktime(&tm)+atoi(ms+1);
+
+			if(m) strcpy(m,m_last_line);
+			continue;
+		}
+
+		break;
 	}
 
 	char*o=buf;
-	for(;;)
+	while(1)
 	{
-		if(nullptr==(p=fgets(m_last_line,sizeof(m_last_line),m_file)))
-			return 0;
-
-		if(*p=='[')
+		if(line_type(m_last_line)<=1)
 			break;
 
-		o+=convert(p,o);
-	}
+		o+=convert(m_last_line,o);
 
+		if(fgets(m_last_line,sizeof(m_last_line),m_file)==nullptr)
+			return 0;
+	}
 	return o-buf;
 }
 

+ 1 - 0
message_file.h

@@ -17,6 +17,7 @@ public:
 	~message_file();
 	
 	
+	int get_line(uint64_t*time,char*buf,int buflen,char*msg);
 	int get_line(uint64_t*time,char*buf,int buflen);
 	int put_line(uint64_t time,char*buf,int buflen);
 };

+ 0 - 2
znet.cpp

@@ -381,10 +381,8 @@ struct sock_client:fd_io,client_ex
 	void close_impl()
 	{
 		m_recv_timer.stop();
-//		m_send_timer.stop();
 		fd_io::stop();
 		m_ic.on_close(shared_from_this());
-
 		logn_info(1,"socket %s closed.",m_name.c_str());
 	}