2019-06-17 08:37:47 +00:00
|
|
|
/*
|
|
|
|
* rpc_common.h
|
|
|
|
*
|
|
|
|
* Created on: 2011-3-20
|
|
|
|
* Author: yanghu
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef RPC_COMMON_H_
|
|
|
|
#define RPC_COMMON_H_
|
|
|
|
|
|
|
|
#include "rpc_types.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define WORKER_LEN 4
|
|
|
|
#define BACKLOG 5
|
|
|
|
#define BUFFER_SIZE 2048
|
|
|
|
#define RPC_VERSION "RPC/1.0"
|
|
|
|
#define TIMEOUT 120
|
2019-06-20 01:57:07 +00:00
|
|
|
#define TIMEWARN 200
|
2019-06-17 08:37:47 +00:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
/* RPC ret code */
|
|
|
|
RET_OK = 0,
|
|
|
|
RET_ERR = 1,
|
|
|
|
RET_UNKNOWN = 2,
|
|
|
|
RET_SYSERR = 3,
|
|
|
|
RET_NOTFOUND = 4,
|
|
|
|
RET_TIMEOUT = 5,
|
|
|
|
|
|
|
|
RET_NULLP = 6,
|
|
|
|
RET_NOMEM = 7,
|
|
|
|
RET_CHKERR = 8,
|
|
|
|
RET_EXCEERR = 9,
|
|
|
|
RET_SOCKERR = 10,
|
|
|
|
RET_NOTSUPPORT = 11,
|
|
|
|
RET_INPUTERR = 12,
|
|
|
|
RET_IPINVALID = 13,
|
|
|
|
} ret_code;
|
|
|
|
|
|
|
|
#define RET_ERROR_DISC \
|
|
|
|
{ \
|
|
|
|
{ RET_OK, "OK" }, \
|
|
|
|
{ RET_ERR, "Error" },\
|
|
|
|
{ RET_UNKNOWN, "Unkown" },\
|
|
|
|
{ RET_SYSERR, "SystemError" },\
|
|
|
|
{ RET_NOTFOUND, "NotFound" }, \
|
|
|
|
{ RET_TIMEOUT, "Timeout" }, \
|
|
|
|
{ RET_NULLP, "NullPointer" } ,\
|
|
|
|
{ RET_NOMEM, "NotEnoughMemery"},\
|
|
|
|
{ RET_CHKERR, "CheckError"},\
|
|
|
|
{ RET_EXCEERR, "ExecutError"},\
|
|
|
|
{ RET_SOCKERR, "SockError"},\
|
|
|
|
{ RET_NOTSUPPORT, "NotSupport"},\
|
|
|
|
{ RET_INPUTERR, "InputError"},\
|
|
|
|
{ RET_IPINVALID, "IpInvalid"}\
|
|
|
|
}
|
|
|
|
|
|
|
|
#define RET_BUFF_SIZE 256;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
RPC_Parse_OK = 0, RPC_Parse_NeedData = 1, RPC_Parse_Error = 2
|
|
|
|
} rpc_parse_result;
|
|
|
|
|
|
|
|
typedef struct _rpc_server rpc_server;
|
|
|
|
typedef struct _rpc_client rpc_client;
|
|
|
|
typedef struct _rpc_conn rpc_conn;
|
|
|
|
typedef struct _rpc_request rpc_request;
|
|
|
|
typedef struct _rpc_response rpc_response;
|
|
|
|
|
|
|
|
typedef void (*rpc_callback)(ret_code code, pointer output,
|
|
|
|
int output_len, pointer data);
|
|
|
|
|
|
|
|
|
|
|
|
typedef void* (*rpc_thread_func)(void* args);
|
|
|
|
|
|
|
|
typedef void (*rpc_function)(rpc_conn *conn, pointer input, int input_len,
|
|
|
|
pointer data);
|
|
|
|
|
|
|
|
typedef struct _rpc_dispatch_thread rpc_dispatch_thread;
|
|
|
|
|
|
|
|
typedef struct _rpc_client_thread rpc_client_thread;
|
|
|
|
|
|
|
|
typedef struct _rpc_worker_thread rpc_worker_thread;
|
|
|
|
|
|
|
|
struct _rpc_service {
|
|
|
|
char *service_name;
|
|
|
|
char *method_name;
|
|
|
|
char *data;
|
|
|
|
rpc_function cb;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _rpc_service rpc_service;
|
|
|
|
|
|
|
|
const char* rpc_code_format(const ret_code code);
|
|
|
|
|
|
|
|
ret_code rpc_str_code(const char* str);
|
|
|
|
|
|
|
|
typedef struct token_s {
|
|
|
|
char *value;
|
|
|
|
size_t length;
|
|
|
|
} token_t;
|
|
|
|
|
|
|
|
int tokenize_command(char *command, token_t *tokens, const size_t max_token);
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* RPC_COMMON_H_ */
|