Răsfoiți Sursa

Z991239-351 #comment 处理部分传送指针的问题;处理宽字符序列化与反序列化问题

gifur 5 ani în urmă
părinte
comite
825594d6c9

+ 1 - 1
Common/SpBase.h

@@ -1269,7 +1269,7 @@ struct CScopeLog
 
 #else//( (defined(_DEBUG) && defined(_MSC_VER)))
 #define LOG_ASSERT(f) if(!(f)) LogAssert(#f,_GetFileName(__FILE__), __LINE__)
-#define LOG_ASSERT_MSG(f,pMsg, ...) do{ if(!(f)) LogAssert(CSimpleStringA::Format(pMsg, __VA_ARGS__),_GetFileName(__FILE__), __LINE__);} while (0)
+#define LOG_ASSERT_MSG(f,pMsg, ...) do{ if(!(f)) LogAssert(CSimpleStringA::Format(pMsg, ##__VA_ARGS__),_GetFileName(__FILE__), __LINE__);} while (0)
 
 #endif// ( (defined(_DEBUG) && defined(_MSC_VER)) )
 #endif // __cplusplus

+ 11 - 6
libtoolkit/iobuffer.c

@@ -6,6 +6,8 @@
 #include <assert.h>
 #include <stdarg.h>
 
+#include <winpr/string.h>
+
 struct iobuffer_t
 {
 	struct list_head sp_entry;
@@ -273,8 +275,11 @@ TOOLKIT_API void iobuffer_write(iobuffer_t *iobuf, int t, const void *v, int n)
 		if (!v) {
 			n = 0;
 		} else {
-			if (n == -1)
-				n = wcslen(v)<<1;
+			if (n == -1) {
+				// be compatible with winpr  [4/2/2020 16:02 Gifur]
+				n = _wcslen(v) << 1;
+				//n = wcslen(v)<<1;
+			}
 		}
 		iobuffer_write_7bit_int(iobuf, n);
 		if (n > 0)
@@ -322,7 +327,7 @@ TOOLKIT_API void iobuffer_write_head(iobuffer_t *iobuf, int t, const void *v, in
 			n = 0;
 		} else {
 			if (n == -1) {
-				n = wcslen(v)<<1;
+				n = _wcslen(v)<<1;
 			}
 		}
 		if (n > 0)
@@ -385,7 +390,7 @@ TOOLKIT_API void iobuffer_read(iobuffer_t *iobuf, int t, void *v, int *n)
 			int old_rpos = iobuf->sp_rpos;
 			iobuffer_read_7bit_int(iobuf, &len);
 			if (!n || len < *n) {
-				iobuffer_read_buf(iobuf, v, len); /* wchar_t */
+				iobuffer_read_buf(iobuf, v, len); /* WCHAR */
 				*((char*)v + len) = 0; // wchar termination char is 2 byte
 				*((char*)v + len+1) = 0;
 				if (n)
@@ -481,10 +486,10 @@ TOOLKIT_API void iobuffer_format_readv(iobuffer_t *iobuf, const char *fmt, va_li
 				break;
 			case 'w': case 'W':
 				{
-					wchar_t **pstr = va_arg(arg, wchar_t**);
+					WCHAR **pstr = va_arg(arg, WCHAR**);
 					int slen;
 					iobuffer_read(iobuf, IOBUF_T_WSTR, NULL, &slen);
-					*pstr = (wchar_t*)malloc(slen+2); // null terminated is two bytes
+					*pstr = (WCHAR*)malloc(slen+2); // null terminated is two bytes
 					iobuffer_read(iobuf, IOBUF_T_WSTR, *pstr, 0);
 				}
 				break;

+ 1 - 0
spbase/SpClientSessionFunction.cpp

@@ -237,6 +237,7 @@ void SpClientSessionFunction::on_close(int error)
 void SpClientSessionFunction::on_destroy()
 {
 	if (m_pClientSessionBase) {
+		Dbg("Enter %s", __FUNCTION__);
 		m_pClientSessionBase->OnDestroy();
 	}
 }

+ 2 - 2
spbase/SpHelper.cpp

@@ -133,7 +133,7 @@ static
 #endif //_WIN32
 inline void ReadT(iobuffer_t *iobuf, CSimpleStringA &t)
 {
-	wchar_t *wt = NULL;
+	WCHAR *wt = NULL;
 	iobuffer_format_read(iobuf, "w", &wt); // string is unicode so we can compatible with silverlight
 	CSimpleStringW wStr = wt;
 	toolkit_free(wt);
@@ -146,7 +146,7 @@ static
 #endif //_WIN32
 inline void ReadT(iobuffer_t *iobuf, CSimpleStringW &t)
 {
-	wchar_t *wt = NULL;
+	WCHAR *wt = NULL;
 	iobuffer_format_read(iobuf, "w", &wt); // string is unicode so we can compatible with silverlight
 	t = wt;
 	toolkit_free(wt);

+ 2 - 2
spbase/sp_bcm.c

@@ -84,7 +84,7 @@ static void listener_on_pkt_threadpool(threadpool_t *threadpool, void *arg)
 	sp_rsn_context_t rsn_ctx;
 	sp_svc_t *svc;
 
-	iobuffer_read(pkt, IOBUF_T_I4, &listener, NULL);
+	iobuffer_read(pkt, IOBUF_T_PTR, &listener, NULL);
 	iobuffer_read(pkt, IOBUF_T_I4, &epid, NULL);
 	iobuffer_read(pkt, IOBUF_T_I4, &svc_id, NULL);
 	iobuffer_read(pkt, IOBUF_T_I4, &pkt_type, NULL);
@@ -135,7 +135,7 @@ static int listener_on_pkt(sp_svc_t *svc,int epid, int svc_id, int pkt_type, int
 		iobuffer_write_head(pkt, IOBUF_T_I4, &pkt_type, 0);
 		iobuffer_write_head(pkt, IOBUF_T_I4, &svc_id, 0);
 		iobuffer_write_head(pkt, IOBUF_T_I4, &epid, 0);
-		iobuffer_write_head(pkt, IOBUF_T_I4, &listener, 0);
+		iobuffer_write_head(pkt, IOBUF_T_PTR, &listener, 0);
 		sp_bcm_listener_inc_ref(listener);//@
 		
 		//sp_dbg_info("callback OnBroadcastEvent ", svc_id);

+ 2 - 2
spbase/sp_log.c

@@ -76,14 +76,14 @@ int sp_log_client_destroy(sp_log_client_t *client)
 	free(client);
 	return 0;
 }
-
+// TODO: param size type [4/2/2020 12:50 Gifur]
 int sp_log_client_log(sp_log_client_t *client, int type, int severity, int sys_error, int usr_error, int param_cnt, int *params, const char *format, ...)
 {
 	va_list arg;
 	va_start(arg, format);
 	return sp_log_client_logv(client, type, severity, sys_error, usr_error, param_cnt, params, format, arg);
 }
-
+// TODO: param size type [4/2/2020 12:50 Gifur]
 int sp_log_client_logv(sp_log_client_t *client, int type, int severity, int sys_error, int usr_error, int param_cnt, int *params, const char *format, va_list arg)
 {
 	int i, n;

+ 4 - 4
spbase/sp_mod.c

@@ -400,7 +400,7 @@ static void mod_entity_state_listener_process_cmd(threadpool_t *threadpool, void
 	sp_mod_entity_state_listener_t *listener;
 	iobuffer_t *pkt = arg;
 
-	iobuffer_read(pkt, IOBUF_T_I4, &listener, NULL);
+	iobuffer_read(pkt, IOBUF_T_PTR, &listener, NULL);
 
 	spinlock_enter(&listener->lock, -1);
 	if (!listener->stop) {
@@ -480,7 +480,7 @@ static int mod_entity_state_listener_on_pkt(sp_svc_t *svc, int epid, int svc_id,
 			iobuffer_write_head(pkt, IOBUF_T_I4, &pkt_type, 0);
 			iobuffer_write_head(pkt, IOBUF_T_I4, &svc_id, 0);
 			iobuffer_write_head(pkt, IOBUF_T_I4, &epid, 0);
-			iobuffer_write_head(pkt, IOBUF_T_I4, &listener, 0);
+			iobuffer_write_head(pkt, IOBUF_T_PTR, &listener, 0);
 			sp_mod_entity_state_listener_inc_ref(listener);
 			threadpool_queue_workitem(sp_svc_get_threadpool(listener->svc), listener->strand, mod_entity_state_listener_process_cmd, pkt);
 		}
@@ -555,7 +555,7 @@ static void mod_entity_life_listener_process_cmd(threadpool_t *threadpool, void
 	sp_mod_entity_life_listener_t *listener;
 	iobuffer_t *pkt = arg;
 
-	iobuffer_read(pkt, IOBUF_T_I4, &listener, NULL);
+	iobuffer_read(pkt, IOBUF_T_PTR, &listener, NULL);
 
 	spinlock_enter(&listener->lock, -1);
 	if (!listener->stop) {
@@ -618,7 +618,7 @@ static int mod_entity_life_listener_on_pkt(sp_svc_t *svc, int epid, int svc_id,
 				iobuffer_write_head(pkt, IOBUF_T_I4, &pkt_type, 0);
 				iobuffer_write_head(pkt, IOBUF_T_I4, &svc_id, 0);
 				iobuffer_write_head(pkt, IOBUF_T_I4, &epid, 0);
-				iobuffer_write_head(pkt, IOBUF_T_I4, &listener, 0);
+				iobuffer_write_head(pkt, IOBUF_T_PTR, &listener, 0);
 				sp_mod_entity_life_listener_inc_ref(listener);
 				threadpool_queue_workitem(sp_svc_get_threadpool(listener->svc), listener->strand, &mod_entity_life_listener_process_cmd, pkt);
 		}

+ 1 - 1
spbase/sp_svc.c

@@ -17,7 +17,7 @@
 
 typedef struct pkt_handler_t {
 	struct hlist_node hentry;
-	int key;
+	int key; //TODO: at 64bit arch  [4/2/2020 14:06 Gifur]
 	sp_svc_on_pkt on_pkt;
 	void *user_data;
 }pkt_handler_t;

+ 2 - 2
spbase/sp_var.c

@@ -202,7 +202,7 @@ static void listener_on_pkt_threadpool(threadpool_t *threadpool, void *arg)
 	sp_uid_t rsn;
 	sp_rsn_context_t rsn_ctx;
 
-	iobuffer_read(pkt, IOBUF_T_I4, &listener, NULL);
+	iobuffer_read(pkt, IOBUF_T_PTR, &listener, NULL);
 	iobuffer_read(pkt, IOBUF_T_I4, &epid, NULL);
 	iobuffer_read(pkt, IOBUF_T_I4, &svc_id, NULL);
 	iobuffer_read(pkt, IOBUF_T_I4, &pkt_type, NULL);
@@ -254,7 +254,7 @@ static int listener_on_pkt(sp_svc_t *svc,int epid, int svc_id, int pkt_type, int
 		iobuffer_write_head(pkt, IOBUF_T_I4, &pkt_type, 0);
 		iobuffer_write_head(pkt, IOBUF_T_I4, &svc_id, 0);
 		iobuffer_write_head(pkt, IOBUF_T_I4, &epid, 0);
-		iobuffer_write_head(pkt, IOBUF_T_I4, &listener, 0);
+		iobuffer_write_head(pkt, IOBUF_T_PTR, &listener, 0);
 		sp_var_listener_inc_ref(listener);//@
 		if (threadpool_queue_workitem(sp_svc_get_threadpool(svc), listener->strand, &listener_on_pkt_threadpool, pkt) < 0) {
 			sp_var_listener_dec_ref(listener);//@

+ 36 - 0
spbase/test/SpBufferTest.cpp

@@ -0,0 +1,36 @@
+#include "SpHelper.h"
+#include<gtest/gtest.h>
+
+
+wchar_t hello[] = L"Hello, World!\n";
+
+TEST(SpBufferTest, WideCharTest)
+{
+	wprintf(hello);
+	wprintf(L"sizeof(wchar_t): %d\n", sizeof(wchar_t));
+}
+
+TEST(SpBufferTest, TestSimpleStringA)
+{
+
+	CSimpleStringA str("Hello world 12345678 90");
+	SpBuffer buffer;
+	buffer.OpenWrite();
+	buffer = buffer & str;
+
+	CAutoBuffer buf = buffer.ToBuffer();
+	buffer.Close();
+
+	SpBuffer bufToRead;
+	ASSERT_TRUE(bufToRead.OpenRead((const char*)&buf[0], buf.GetCount()));
+	ASSERT_TRUE(bufToRead.IsRead());
+	ASSERT_FALSE(bufToRead.IsWrite());
+
+	CSimpleStringA out;
+	bufToRead & out;
+
+	ASSERT_TRUE(out.Compare(str) == 0);
+
+
+
+}

+ 4 - 5
test/module/mod_helloclient/mod_helloclient.cpp

@@ -36,7 +36,7 @@ public:
 		//pFunc->RegistSysVarEvent("HelloState", this);
 
 #if 1
-		Sleep(60 * 1000);
+		//Sleep(60 * 1000);
 		HelloService_ClientBase *client = new HelloService_ClientBase(this);
 		Dbg("before connect");
 		ErrorCodeEnum Error = client->Connect();
@@ -57,15 +57,14 @@ public:
 			Dbg("before hello");
 			Error = client->Hello(Hello_Req, Hello_Ans, -1);
 			Dbg("after hello");
-			//LOG_ASSERT(Error == Error_Succeed);
-			//LOG_TRACE((LPCSTR)Hello_Ans.txt);
-
+			LOG_ASSERT(Error == Error_Succeed);
+			LOG_TRACE((LPCSTR)Hello_Ans.txt);
 			client->GetFunction()->CloseSession();
 		}
 		else {
 			Dbg("Connect failed!");
+			client->SafeDelete();
 		}
-		client->SafeDelete();
 #endif
 
 		m_pClient = new HelloService_ClientBase(this);

+ 1 - 0
test/module/mod_helloservice/HelloService_client_g.h

@@ -22,6 +22,7 @@ public:
 		CSmartPointer<IEntityFunction> pFunc = m_pEntityBase->GetFunction();
 		ErrorCodeEnum Error = pFunc->ConnectRemoteEntity(this, "HelloService", "HelloService", spAsyncWait);
 		if (Error == Error_Succeed) {
+			Dbg("set m_bSysManaged true!");
 			m_bSysManaged = true;
 		}
 		return Error;