Эх сурвалжийг харах

Z991239-4157 #comment 解决存在坐席抓拍时连线断开问题

80274480 2 жил өмнө
parent
commit
172ee07ff3

+ 9 - 4
Module/mod_assistantchannel/mod_assistantchannel.cpp

@@ -87,13 +87,13 @@ static void __dbg(void *user_data, const char *fmt, va_list arg)
 	int n = _scprintf(fmt, arg);
 	if (n >= MAX_PATH) {
 		char* buf = (char*)malloc((size_t)(n + 1));
-		_snprintf(buf, n + 1, fmt, arg);
+		vsnprintf(buf, n + 1, fmt, arg);
 		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
 		free(buf);
 	}
 	else {
 		char strlog[MAX_PATH] = { 0 };
-		_snprintf(strlog, MAX_PATH, fmt, arg);
+		vsnprintf(strlog, MAX_PATH, fmt, arg);
 		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
 	}
 }
@@ -322,8 +322,9 @@ ErrorCodeEnum CBizChannelEntity::Send(int type, bool compress, bool encrypt, int
 {
 	if (m_eState == eChannelState_Connected) {
 		//LOG_TRACE("tx pkt, %d bytes, type = %d, compress = %d, encrypt = %d, sub_type = %d, id = %d, hash=%d", data.m_iLength, type, !!compress, !!encrypt, sub_type, id, hash32_buf(data.m_pData, data.m_iLength, 0));
-		//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("tx pkt, %d bytes, type = %d, compress = %d, encrypt = %d, sub_type = %d, id = %d, hash=%d", data.m_iLength, type, !!compress, !!encrypt, sub_type, id, hash32_buf(data.m_pData, data.m_iLength, 0));
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("tx pkt, %d bytes, type = %d, compress = %d, encrypt = %d, sub_type = %d, id = %d, hash=%d", data.m_iLength, type, !!compress, !!encrypt, sub_type, id, hash32_buf(data.m_pData, data.m_iLength, 0));
 		int rc = bizchan_post_pkt(m_pChan, type, compress, encrypt, sub_type, id, (const char*)data.m_pData, data.m_iLength);
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("bizchan_post_pkt result is %d.", rc);
 		return rc == 0 ? Error_Succeed : Error_NetBroken;
 	}
 	else 
@@ -438,7 +439,9 @@ void CBizChannelEntity::on_connect(int error, const char *remote_ip, int remote_
 				bizchan_start_close(m_pChan);
 			}
 		}
-	} else {
+	}
+	else {
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d.", __FUNCTION__, __LINE__);
 		if (m_pChan) {
 			bizchan_close(m_pChan);
 			bizchan_destroy(m_pChan);
@@ -450,6 +453,7 @@ void CBizChannelEntity::on_connect(int error, const char *remote_ip, int remote_
 
 void CBizChannelEntity::on_close()
 {
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d.", __FUNCTION__, __LINE__);
 	if (m_pChan) {
 		bizchan_close(m_pChan);
 		bizchan_destroy(m_pChan);
@@ -494,6 +498,7 @@ void CBizChannelEntity::_on_connect(int error, const char *remote_ip, int remote
 
 void CBizChannelEntity::_on_close()
 {
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d.", __FUNCTION__, __LINE__);
 	NotifyOnClose *task = new NotifyOnClose();
 	task->m_pEntity = this;
 	GetFunction()->PostEntityTaskFIFO(task);

+ 4 - 10
Module/mod_assistantchannel/mod_assistantchannel.h

@@ -37,22 +37,14 @@ public:
 	virtual void OnStarted();
 	DeviceTypeEnum RvcGetDeviceType();
 	ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError);
-
 	virtual CServerSessionBase* OnNewSession(const char* pszRemoteEntityName, const char* pszClass);
-
 	ErrorCodeEnum Connect(const char* ip, int port, const char* callno, CallingTypeEnum eType);
 	ErrorCodeEnum Close();
-
 	int GetState() { return m_eState; }
-
 	ErrorCodeEnum RegisterState(int id, SpSubscribeContext<ChannelService_BeginState_Sub, ChannelService_State_Info>::Pointer ctx);
-
 	ErrorCodeEnum RegisterRxPkt(int id, SpSubscribeContext<ChannelService_BeginRecv_Sub, ChannelService_Packet_Info>::Pointer ctx);
-
 	void UnregisterState(int id);
-
 	void UnregisterRxpkt(int id);
-
 	ErrorCodeEnum Send(int type, bool compress, bool encrypt, int sub_type, int id, CBlob& data);
 	void on_recv_pkt(int type, int sub_type, int id, CBlob &data);
 	void on_connect(int error, const char *remote_ip, int remote_video_rtp, int remote_video_desc);
@@ -62,6 +54,8 @@ public:
 	void _on_close();
 
 private:
+	void ChangeState(int new_state, const char* param = NULL);
+
 	struct NotifyOnClose : public ITaskSp
 	{
 		CBizChannelEntity* m_pEntity;
@@ -70,6 +64,7 @@ private:
 			m_pEntity->on_close();
 		}
 	};
+
 	struct NotifyOnRecvPkt : public ITaskSp
 	{
 		CBizChannelEntity* m_pEntity;
@@ -82,6 +77,7 @@ private:
 			m_pEntity->on_recv_pkt(type, sub_type, id, data);
 		}
 	};
+
 	struct NotifyOnConnect : public ITaskSp
 	{
 		CBizChannelEntity* m_pEntity;
@@ -95,8 +91,6 @@ private:
 		}
 	};
 
-	void ChangeState(int new_state, const char *param = NULL);
-
 private:
 	DeviceTypeEnum m_eDeviceType;
 	int m_eState;

+ 29 - 29
Other/libbizchan/bizchan.cpp

@@ -566,7 +566,7 @@ static int on_recv(bizchan_t *chan, SOCKET conn)
 		result = (n < 0 || (errno == EWOULDBLOCK) || (errno == EINTR) || (errno == EAGAIN)) ? 0 : -1;
 	}
 
-	bizlog(chan, 0, "on_recv n:%d, result:%d, errno:%d", n, result, errno);
+	bizlog(chan, "on_recv n:%d, result:%d, errno:%d", n, result, errno);
 	return result;
 #endif
 }
@@ -606,7 +606,7 @@ static int on_send(bizchan_t *chan, SOCKET conn)
 				t->need_encrypt = 0;
 			}
 			n = send(conn, t->buf+t->sended, t->left, 0);
-			bizlog(chan, 0, "on_send n:%d, t->sended:%d, t->left:%d", n, t->sended, t->left);
+			bizlog(chan, "on_send n:%d, t->sended:%d, t->left:%d", n, t->sended, t->left);
 			if (n > 0) {
 				char tmp[32];
 				sprintf(tmp, "send out %d bytes!\n", n);
@@ -960,10 +960,10 @@ static void do_shake_send(bizchan_t* chan, SOCKET conn, int* error) {
 #if ENCRYPT_CHINA
 	EncWithSM4_ECB(seed_key, (unsigned char*)&chan->local_pwd[0], KEY_LEN / 2,
 		(unsigned char*)&hdr.encrypt_key[0], &enc_length);
-	bizlog(chan, 0, "use SM4 password_crypt_type");
+	bizlog(chan, "use SM4 password_crypt_type");
 #else
 	encodefun((unsigned char*)&hdr.encrypt_key[0], sizeof(hdr.encrypt_key), (unsigned char*)&chan->local_pwd[0], sizeof(chan->local_pwd));
-	Dbg(chan, 0, "use old password_crypt_type");
+	bizlog(chan, "use old password_crypt_type");
 #endif
 	hdr.encrypt_keyhash = hash_key(chan->local_pwd, sizeof(chan->local_pwd));
 	memset(hdr.callee_id, ' ', sizeof(hdr.callee_id));
@@ -1009,23 +1009,23 @@ static void do_shake_recv(bizchan_t* chan, SOCKET conn, int* error) {
 				int result = DecWithSM4_ECB(seed_key,
 					(unsigned char*)&ack_hdr.encrypt_key[0], sizeof(ack_hdr.encrypt_key),
 					(unsigned char*)&chan->remote_pwd[0], &dec_length);
-				bizlog(chan, 0, "use SM4 Decode password result:%d", result);
+				bizlog(chan, "use SM4 Decode password result:%d", result);
 				if (result != 0) {
 					result = decodefun((unsigned char*)&chan->remote_pwd[0], sizeof(chan->remote_pwd), (unsigned char*)&ack_hdr.encrypt_key[0], sizeof(ack_hdr.encrypt_key));
-					bizlog(chan, 0, "use old Decode password result:%d", result);
+					bizlog(chan, "use old Decode password result:%d", result);
 				}
 				if (check_hash(chan->remote_pwd, sizeof(chan->remote_pwd), ack_hdr.encrypt_keyhash)) {
 					chan->remote_video_rtp_port = ack_hdr.rtp_port;
 					chan->remote_video_desc = ack_hdr.media_desc;
 					memcpy(chan->remote_client_id, ack_hdr.client_id, sizeof(chan->remote_client_id));
 					chan->remote_version = ack_hdr.version;
-					bizlog(chan, 0, "remote_acm_version:%d", chan->remote_version);
+					bizlog(chan, "remote_acm_version:%d", chan->remote_version);
 					chan->connected = TRUE;
 					break;
 				}
 				else {
 					*error = -1;
-					bizlog(chan, 0, "do_shake_recv check_hash failed");
+					bizlog(chan, "do_shake_recv check_hash failed");
 				}
 
 			}
@@ -1037,8 +1037,8 @@ static void do_shake_recv(bizchan_t* chan, SOCKET conn, int* error) {
 #else
 	if (t <= 0 && ((errno != EWOULDBLOCK) || (errno != EINTR) || (errno != EAGAIN))) {
 		*error = -1;
-		bizlog(chan, 0, "do_shake_recv errno:%d", errno);
-		bizlog(chan, 0, "do_shake_recv t<=0 failed");
+		bizlog(chan, "do_shake_recv errno:%d", errno);
+		bizlog(chan, "do_shake_recv t<=0 failed");
 	}
 #endif
 }
@@ -1094,7 +1094,7 @@ SOCKET connect_server(bizchan_t* chan, char* server, int port, int timeout)
 #else
 		close(m_hSocket);
 #endif
-		bizlog(chan, 0, "connect_server set_socket_noblock failed");
+		bizlog(chan, "connect_server set_socket_noblock failed");
 	}
 
 	addrSrv.sin_family = AF_INET;
@@ -1102,7 +1102,7 @@ SOCKET connect_server(bizchan_t* chan, char* server, int port, int timeout)
 	addrSrv.sin_port = htons(port);
 	int ret = connect(m_hSocket, (struct sockaddr*)&addrSrv, sizeof(addrSrv));
 	if (ret == 0) {
-		bizlog(chan, 0, "connect_server connect success 1.");
+		bizlog(chan, "connect_server connect success 1.");
 		return m_hSocket;
 	}
 #ifdef RVC_OS_WIN
@@ -1115,7 +1115,7 @@ SOCKET connect_server(bizchan_t* chan, char* server, int port, int timeout)
 	//linux下需要检测EINPROGRESS和EINTR  
 	if (ret < 0 && (errno != EINPROGRESS && errno != EINTR)) {
 		close(m_hSocket);
-		bizlog(chan, 0, "connect_server connect failed, errno: %d", errno);
+		bizlog(chan, "connect_server connect failed, errno: %d", errno);
 		return INVALID_SOCKET;
 	}
 #endif
@@ -1133,11 +1133,11 @@ SOCKET connect_server(bizchan_t* chan, char* server, int port, int timeout)
 #else
 		close(m_hSocket);
 #endif
-		bizlog(chan, 0, "connect_server connect timeout.");
+		bizlog(chan, "connect_server connect timeout.");
 		return INVALID_SOCKET;
 	}
 
-	bizlog(chan, 0, "connect_server connect success 2.");
+	bizlog(chan, "connect_server connect success 2.");
 	return m_hSocket;
 }
 
@@ -1174,7 +1174,7 @@ static void process(bizchan_t* chan) {
 #else
 		do_shake_send(chan, conn, &error);
 		if (error != 0) {
-			bizlog(chan, 0, "do_shake_send failed");
+			bizlog(chan, "do_shake_send failed");
 			goto on_error;
 		}
 		while (!chan->stop_flag && !chan->connected) {
@@ -1187,13 +1187,13 @@ static void process(bizchan_t* chan) {
 			int activity = select(maxfd + 1, &read_fds, NULL, &except_fds, &tv);
 			if (activity == -1) {
 				perror("select()");
-				bizlog(chan, 0, "process shake select -1");
+				bizlog(chan, "process shake select -1");
 				goto on_error;
 			}
 			else if (activity == 0) {
 				// timeout
 				printf("select() returns 0.\n");
-				bizlog(chan, 0, "process shake select 0");
+				bizlog(chan, "process shake select 0");
 				goto on_error;
 			}else {
 				/* All fd_set's should be checked. */
@@ -1205,7 +1205,7 @@ static void process(bizchan_t* chan) {
 					char pipe_read_buffer[4];
 					int n = read(chan->evt[0], pipe_read_buffer, 4);
 					if (n < 0) {
-						bizlog(chan, 0, "process shake pipe read < 0");
+						bizlog(chan, "process shake pipe read < 0");
 					}
 				}
 				if (FD_ISSET(conn, &except_fds)) {
@@ -1221,7 +1221,7 @@ static void process(bizchan_t* chan) {
 
 	if (chan->connected)
 	{
-		char buffer[128];
+		char buffer[128] = {0};
 		int rc;
 
 		invoke_on_connect(chan, 0);
@@ -1286,11 +1286,11 @@ static void process(bizchan_t* chan) {
 							break;
 					}
 					else {
-						bizlog(chan, 0, "pipe read < 0");
+						bizlog(chan, "pipe read < 0");
 					}
 				}
 				if (FD_ISSET(conn, &except_fds)) {
-					bizlog(chan, 0, "select() except_fds set.");
+					bizlog(chan, "select() except_fds set.");
 					error = -1;
 				}
 				if (error != 0) {
@@ -1303,7 +1303,7 @@ static void process(bizchan_t* chan) {
 
 on_error:
 	//OutputDebugStringA("on_error");
-	bizlog(chan, 0, "on_error");
+	bizlog(chan, "on_error");
 
 	if (!chan->connected) {
 		invoke_on_connect(chan, -1); // connect failed!
@@ -1311,7 +1311,7 @@ on_error:
 	else {
 		//....
 		//OutputDebugStringA("connected, and error!");
-		bizlog(chan, 0, "connected, and error!");
+		bizlog(chan, "connected, and error!");
 	}
 
 	if (conn != INVALID_SOCKET) {
@@ -1339,7 +1339,7 @@ static void* work_proc(void* arg)
 		//....
 	}
 #else
-	bizlog(chan, 0, "work_proc start");
+	bizlog(chan, "work_proc start");
 	process(chan);
 #endif
 	return 0;
@@ -1629,8 +1629,9 @@ BIZCHAN_API(int) bizchan_post_pkt(bizchan_t *chan, int type, int compress, int e
 {
 	send_buf_node *t;
 
-	if (!chan->connected)
+	if (!chan->connected) {
 		return -1;
+	}
 	
 	t = (send_buf_node *)malloc(sizeof(send_buf_node));
 
@@ -1674,7 +1675,8 @@ BIZCHAN_API(int) bizchan_post_pkt(bizchan_t *chan, int type, int compress, int e
 		hdr->hash = hash_key(pkt, pkt_size);
 		memcpy(&hdr->data[0], pkt, pkt_size);
 		t->need_encrypt = encrypt;
-	} else {
+	} 
+	else {
 		qlz_state_compress state_compress;
 		acm_hdr *hdr;
 		int new_pkt_size;
@@ -1713,8 +1715,6 @@ BIZCHAN_API(int) bizchan_post_pkt(bizchan_t *chan, int type, int compress, int e
 	write(chan->evt[1], "post", sizeof("post"));
 #endif
 
-
-
 	return 0;
 }