Commit 5787693b authored by lahiker42's avatar lahiker42

Add a way to support multiple threads.


git-svn-id: https://protobuf-c.googlecode.com/svn/trunk@289 00440858-1255-0410-a3e6-75ea37f81c3a
parent 75fa6665
......@@ -3,6 +3,7 @@
as packed-repeated whenever it makes sense (for all types
other than messages, strings, and bytes).
- switch to New BSD license.
- add protobuf_c_rpc_server_configure_threading()
0.15:
- make protobuf_c_message_init() into a function (Issue #49, daveb)
......
This diff is collapsed.
......@@ -26,6 +26,7 @@ typedef enum
PROTOBUF_C_ERROR_CODE_CONNECTION_REFUSED,
PROTOBUF_C_ERROR_CODE_CLIENT_TERMINATED,
PROTOBUF_C_ERROR_CODE_BAD_REQUEST,
PROTOBUF_C_ERROR_CODE_PROXY_PROBLEM
} ProtobufC_RPC_Error_Code;
typedef enum
......@@ -104,6 +105,7 @@ ProtobufC_RPC_Server *
ProtobufCService *service,
ProtobufCDispatch *dispatch /* or NULL */
);
ProtobufCService *
protobuf_c_rpc_server_destroy (ProtobufC_RPC_Server *server,
protobuf_c_boolean free_underlying_service);
......@@ -118,6 +120,15 @@ void protobuf_c_rpc_server_disable_autotimeout(ProtobufC_RPC_Server *server);
void protobuf_c_rpc_server_set_autotimeout (ProtobufC_RPC_Server *server,
unsigned timeout_millis);
typedef protobuf_c_boolean
(*ProtobufC_RPC_IsRpcThreadFunc) (ProtobufC_RPC_Server *server,
ProtobufCDispatch *dispatch,
void *is_rpc_data);
void protobuf_c_rpc_server_configure_threading (ProtobufC_RPC_Server *server,
ProtobufC_RPC_IsRpcThreadFunc func,
void *is_rpc_data);
/* Error handling */
void protobuf_c_rpc_server_set_error_handler (ProtobufC_RPC_Server *server,
ProtobufC_RPC_Error_Func func,
......
......@@ -4,6 +4,7 @@
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <signal.h>
#include "generated-code/test.pb-c.h"
#include <google/protobuf-c/protobuf-c-rpc.h>
......@@ -144,6 +145,8 @@ int main(int argc, char**argv)
if (name == NULL)
die ("missing --tcp=HOST:PORT or --unix=PATH");
signal (SIGPIPE, SIG_IGN);
service = protobuf_c_rpc_client_new (address_type, name, &foo__dir_lookup__descriptor, NULL);
if (service == NULL)
......
......@@ -3,6 +3,7 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <stdlib.h>
#include "generated-code/test.pb-c.h"
#include <google/protobuf-c/protobuf-c-rpc.h>
......@@ -254,6 +255,8 @@ int main(int argc, char**argv)
if (name == NULL)
die ("missing --port=NUM or --unix=PATH");
signal (SIGPIPE, SIG_IGN);
server = protobuf_c_rpc_server_new (address_type, name, (ProtobufCService *) &the_dir_lookup_service, NULL);
for (;;)
......
......@@ -2,6 +2,7 @@
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <signal.h>
#include "generated-code/test.pb-c.h"
#include <google/protobuf-c/protobuf-c-rpc.h>
......@@ -163,6 +164,14 @@ set_boolean_true (ProtobufCDispatch *dispatch,
* (protobuf_c_boolean *) func_data = 1;
}
static protobuf_c_boolean
pretend_we_are_in_another_thread (ProtobufC_RPC_Server *server,
ProtobufCDispatch *dispatch,
void *data)
{
return 0; /* indicate we are NOT in RPC thread */
}
int main()
{
protobuf_c_boolean is_done;
......@@ -171,6 +180,8 @@ int main()
ProtobufC_RPC_Client *client;
ProtobufC_RPC_Server *server;
signal (SIGPIPE, SIG_IGN);
message ("testing local service");
test_service (local_service);
......@@ -250,6 +261,10 @@ int main()
message ("testing client again");
test_service (remote_service);
message ("testing client again (simulating threaded environment)");
protobuf_c_rpc_server_configure_threading (server, pretend_we_are_in_another_thread, NULL);
test_service (remote_service);
/* Destroy the client */
message ("destroying client");
protobuf_c_service_destroy (remote_service);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment