-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathssdb_library.h
136 lines (112 loc) · 4.62 KB
/
ssdb_library.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: xingqiba ixqbar@gmail.com |
+----------------------------------------------------------------------+
*/
#ifndef EXT_SSDB_SSDB_LIBRARY_H_
#define EXT_SSDB_SSDB_LIBRARY_H_
#define SSDB_SOCK_STATUS_FAILED 0
#define SSDB_SOCK_STATUS_DISCONNECTED 1
#define SSDB_SOCK_STATUS_UNKNOWN 2
#define SSDB_SOCK_STATUS_CONNECTED 3
#define SSDB_SERIALIZER_NONE 0
#define SSDB_SERIALIZER_PHP 1
#define SSDB_SERIALIZER_IGBINARY 2
#define SSDB_FILTER_KEY_PREFIX_NONE 0
#define SSDB_FILTER_KEY_PREFIX 1
#define SSDB_UNSERIALIZE_NONE 0
#define SSDB_UNSERIALIZE 1
#define SSDB_CONVERT_TO_STRING 0
#define SSDB_CONVERT_TO_LONG 1
#define _NL "\n"
typedef enum {SSDB_IS_DEFAULT,SSDB_IS_OK,SSDB_IS_NOT_FOUND,SSDB_IS_ERROR,SSDB_IS_FAIL,SSDB_IS_CLIENT_ERROR} ssdb_response_status;
//#define SSDB_DEBUG_LOG(fmt, args...) php_printf(fmt, ##args);
#define SSDB_DEBUG_LOG(fmt, args...)
#define SSDB_SOCKET_WRITE_COMMAND(ssdb_sock, cmd, cmd_len) if(ssdb_sock_write(ssdb_sock, cmd, cmd_len) < 0) { \
efree(cmd); \
RETURN_NULL(); \
} \
efree(cmd);
typedef struct {
php_stream *stream;
char *host;
long port;
long timeout;
long read_timeout;
char *auth;
char *prefix;
int prefix_len;
int status;
zend_bool lazy_connect;
char *err;
int err_len;
int retry_interval;
int persistent;
char *persistent_id;
int serializer;
int twin; //为支持info,可能ssdb-server某版本以后就移除了info的返回ssdb-server无用内容,fuck!!!
} SSDBSock;
typedef struct _SSDBResponseBlock {
struct _SSDBResponseBlock *prev;
struct _SSDBResponseBlock *next;
size_t len;
char *data;
} SSDBResponseBlock;
typedef struct {
ssdb_response_status status;
SSDBResponseBlock *block;
SSDBResponseBlock *tail;
int num;
} SSDBResponse;
extern zend_class_entry *ssdb_exception_ce;
SSDBSock* ssdb_create_sock(
char *host,
int host_len,
long port,
long timeout,
int persistent,
char *persistent_id,
long retry_interval,
zend_bool lazy_connect);
void ssdb_free_socket(SSDBSock *ssdb_sock);
void ssdb_stream_close(SSDBSock *ssdb_sock);
int ssdb_open_socket(SSDBSock *ssdb_sock, int force_connect);
int ssdb_connect_socket(SSDBSock *ssdb_sock);
int ssdb_disconnect_socket(SSDBSock *ssdb_sock);
int ssdb_key_prefix(SSDBSock *ssdb_sock, char **key, int *key_len);
int ssdb_cmd_format_by_str(SSDBSock *ssdb_sock, char **ret, void *params, ...);
int ssdb_cmd_format_by_zval(SSDBSock *ssdb_sock, char **ret,
char *cmd, int cmd_len,
char *key, int key_len,
zval *params,
int read_all,
int fill_prefix,
int serialize);
int ssdb_check_eof(SSDBSock *ssdb_sock);
SSDBResponse *ssdb_response_create();
void ssdb_response_free(SSDBResponse *ssdb_response);
void ssdb_response_add_block(SSDBResponse *ssdb_response, char *data, size_t len);
SSDBResponse *ssdb_sock_read(SSDBSock *ssdb_sock);
int ssdb_sock_write(SSDBSock *ssdb_sock, char *cmd, size_t sz);
int resend_auth(SSDBSock *ssdb_sock);
int ssdb_serialize(SSDBSock *ssdb_sock, zval *z, char **val, int *val_len);
int ssdb_unserialize(SSDBSock *ssdb_sock, const char *val, int val_len, zval **return_value);
void ssdb_long_number_response(INTERNAL_FUNCTION_PARAMETERS, SSDBSock *ssdb_sock);
void ssdb_double_number_response(INTERNAL_FUNCTION_PARAMETERS, SSDBSock *ssdb_sock);
void ssdb_bool_response(INTERNAL_FUNCTION_PARAMETERS, SSDBSock *ssdb_sock);
void ssdb_string_response(INTERNAL_FUNCTION_PARAMETERS, SSDBSock *ssdb_sock);
void ssdb_list_response(INTERNAL_FUNCTION_PARAMETERS, SSDBSock *ssdb_sock, int filter_prefix, int unserialize);
void ssdb_map_response(INTERNAL_FUNCTION_PARAMETERS, SSDBSock *ssdb_sock, int filter_prefix, int unserialize, int convert_type);
#endif /* EXT_SSDB_SSDB_LIBRARY_H_ */