1
0
mirror of https://github.com/haiwen/libsearpc.git synced 2025-06-08 21:24:41 +00:00
libsearpc/lib/searpc-named-pipe-transport.h

76 lines
2.0 KiB
C
Raw Permalink Normal View History

#ifndef SEARPC_NAMED_PIPE_TRANSPORT_H
#define SEARPC_NAMED_PIPE_TRANSPORT_H
2019-11-01 07:52:36 +00:00
#ifdef LIBSEARPC_EXPORTS
#define LIBSEARPC_API __declspec(dllexport)
#else
#define LIBSEARPC_API
#endif
#include <pthread.h>
#include <glib.h>
#include <glib-object.h>
#include <jansson.h>
#if defined(WIN32)
#include <windows.h>
#endif
// Implementatin of a searpc transport based on named pipe. It uses unix domain
// sockets on linux/osx, and named pipes on windows.
//
// On the server side, there is a thread that listens for incoming connections,
// and it would create a new thread to handle each connection. Thus the RPC
// functions on the server side may be called from different threads, and it's
// the RPC functions implementation's responsibility to guarantee thread safety
// of the RPC calls. (e.g. using mutexes).
#if defined(WIN32)
typedef HANDLE SearpcNamedPipe;
#else
typedef int SearpcNamedPipe;
#endif
// Server side interface.
struct _SearpcNamedPipeServer {
char path[4096];
pthread_t listener_thread;
SearpcNamedPipe pipe_fd;
2019-07-29 02:24:47 +00:00
GThreadPool *named_pipe_server_thread_pool;
};
2019-11-01 07:52:36 +00:00
typedef struct _SearpcNamedPipeServer LIBSEARPC_API SearpcNamedPipeServer;
2019-11-01 07:52:36 +00:00
LIBSEARPC_API
2019-10-19 06:16:32 +00:00
SearpcNamedPipeServer* searpc_create_named_pipe_server(const char *path);
2019-11-01 07:52:36 +00:00
LIBSEARPC_API
2019-10-19 06:16:32 +00:00
SearpcNamedPipeServer* searpc_create_named_pipe_server_with_threadpool(const char *path, int named_pipe_server_thread_pool_size);
2019-11-01 07:52:36 +00:00
LIBSEARPC_API
int searpc_named_pipe_server_start(SearpcNamedPipeServer *server);
// Client side interface.
struct _SearpcNamedPipeClient {
char path[4096];
SearpcNamedPipe pipe_fd;
};
2019-11-01 07:52:36 +00:00
typedef struct _SearpcNamedPipeClient LIBSEARPC_API SearpcNamedPipeClient;
2019-11-01 07:52:36 +00:00
LIBSEARPC_API
SearpcNamedPipeClient* searpc_create_named_pipe_client(const char *path);
2019-11-01 07:52:36 +00:00
LIBSEARPC_API
SearpcClient * searpc_client_with_named_pipe_transport(SearpcNamedPipeClient *client, const char *service);
2019-11-01 07:52:36 +00:00
LIBSEARPC_API
int searpc_named_pipe_client_connect(SearpcNamedPipeClient *client);
2019-11-01 07:52:36 +00:00
LIBSEARPC_API
2016-06-14 02:07:42 +00:00
void searpc_free_client_with_pipe_transport (SearpcClient *client);
#endif // SEARPC_NAMED_PIPE_TRANSPORT_H