|
|
|
@ -9,21 +9,10 @@ |
|
|
|
|
|
|
|
#ifdef _WIN32 |
|
|
|
#include <windows.h> |
|
|
|
typedef DWORD WINAPI (*ThreadFunction)(LPVOID lpParam); |
|
|
|
#else |
|
|
|
#include <pthread.h> |
|
|
|
#endif |
|
|
|
|
|
|
|
/*
|
|
|
|
* Windows平台的线程函数包装器 |
|
|
|
*/ |
|
|
|
#ifdef _WIN32 |
|
|
|
DWORD WINAPI thread_wrapper(LPVOID lpParam) { |
|
|
|
handle_client(lpParam); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
/* 函数处理函数类型定义 */ |
|
|
|
typedef int (*rpc_handler_func_t)(rpc_param_t* params, int args_count, rpc_param_t* return_value); |
|
|
|
|
|
|
|
@ -94,7 +83,11 @@ rpc_handler_t* rpc_find_handler(const char* func_name) { |
|
|
|
/*
|
|
|
|
* 处理客户端请求 |
|
|
|
*/ |
|
|
|
#ifdef _WIN32 |
|
|
|
DWORD WINAPI handle_client(LPVOID arg) { |
|
|
|
#else |
|
|
|
void* handle_client(void* arg) { |
|
|
|
#endif |
|
|
|
rpc_transport_t* transport = (rpc_transport_t*)arg; |
|
|
|
rpc_request_t request; |
|
|
|
rpc_response_t response; |
|
|
|
@ -181,7 +174,11 @@ void* handle_client(void* arg) { |
|
|
|
rpc_transport_close(transport); |
|
|
|
free(transport); |
|
|
|
|
|
|
|
#ifdef _WIN32 |
|
|
|
return 0; |
|
|
|
#else |
|
|
|
return NULL; |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
|
@ -259,7 +256,7 @@ int main(int argc, char* argv[]) { |
|
|
|
HANDLE thread_handle = CreateThread( |
|
|
|
NULL, // 默认安全属性
|
|
|
|
0, // 默认堆栈大小
|
|
|
|
thread_wrapper, // 线程函数
|
|
|
|
handle_client, // 线程函数
|
|
|
|
client_transport, // 线程参数
|
|
|
|
0, // 默认创建标志
|
|
|
|
NULL // 线程ID(不需要)
|
|
|
|
|