aboutsummaryrefslogtreecommitdiff
path: root/examples/redis-unstable/deps/hiredis/async.h
diff options
context:
space:
mode:
Diffstat (limited to 'examples/redis-unstable/deps/hiredis/async.h')
-rw-r--r--examples/redis-unstable/deps/hiredis/async.h152
1 files changed, 152 insertions, 0 deletions
diff --git a/examples/redis-unstable/deps/hiredis/async.h b/examples/redis-unstable/deps/hiredis/async.h
new file mode 100644
index 0000000..4f94660
--- /dev/null
+++ b/examples/redis-unstable/deps/hiredis/async.h
@@ -0,0 +1,152 @@
1/*
2 * Copyright (c) 2009-2011, Salvatore Sanfilippo <antirez at gmail dot com>
3 * Copyright (c) 2010-2011, Pieter Noordhuis <pcnoordhuis at gmail dot com>
4 *
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of Redis nor the names of its contributors may be used
16 * to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef __HIREDIS_ASYNC_H
33#define __HIREDIS_ASYNC_H
34#include "hiredis.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40struct redisAsyncContext; /* need forward declaration of redisAsyncContext */
41struct dict; /* dictionary header is included in async.c */
42
43/* Reply callback prototype and container */
44typedef void (redisCallbackFn)(struct redisAsyncContext*, void*, void*);
45typedef struct redisCallback {
46 struct redisCallback *next; /* simple singly linked list */
47 redisCallbackFn *fn;
48 int pending_subs;
49 int unsubscribe_sent;
50 void *privdata;
51} redisCallback;
52
53/* List of callbacks for either regular replies or pub/sub */
54typedef struct redisCallbackList {
55 redisCallback *head, *tail;
56} redisCallbackList;
57
58/* Connection callback prototypes */
59typedef void (redisDisconnectCallback)(const struct redisAsyncContext*, int status);
60typedef void (redisConnectCallback)(const struct redisAsyncContext*, int status);
61typedef void (redisConnectCallbackNC)(struct redisAsyncContext *, int status);
62typedef void(redisTimerCallback)(void *timer, void *privdata);
63
64/* Context for an async connection to Redis */
65typedef struct redisAsyncContext {
66 /* Hold the regular context, so it can be realloc'ed. */
67 redisContext c;
68
69 /* Setup error flags so they can be used directly. */
70 int err;
71 char *errstr;
72
73 /* Not used by hiredis */
74 void *data;
75 void (*dataCleanup)(void *privdata);
76
77 /* Event library data and hooks */
78 struct {
79 void *data;
80
81 /* Hooks that are called when the library expects to start
82 * reading/writing. These functions should be idempotent. */
83 void (*addRead)(void *privdata);
84 void (*delRead)(void *privdata);
85 void (*addWrite)(void *privdata);
86 void (*delWrite)(void *privdata);
87 void (*cleanup)(void *privdata);
88 void (*scheduleTimer)(void *privdata, struct timeval tv);
89 } ev;
90
91 /* Called when either the connection is terminated due to an error or per
92 * user request. The status is set accordingly (REDIS_OK, REDIS_ERR). */
93 redisDisconnectCallback *onDisconnect;
94
95 /* Called when the first write event was received. */
96 redisConnectCallback *onConnect;
97 redisConnectCallbackNC *onConnectNC;
98
99 /* Regular command callbacks */
100 redisCallbackList replies;
101
102 /* Address used for connect() */
103 struct sockaddr *saddr;
104 size_t addrlen;
105
106 /* Subscription callbacks */
107 struct {
108 redisCallbackList replies;
109 struct dict *channels;
110 struct dict *patterns;
111 int pending_unsubs;
112 } sub;
113
114 /* Any configured RESP3 PUSH handler */
115 redisAsyncPushFn *push_cb;
116} redisAsyncContext;
117
118/* Functions that proxy to hiredis */
119redisAsyncContext *redisAsyncConnectWithOptions(const redisOptions *options);
120redisAsyncContext *redisAsyncConnect(const char *ip, int port);
121redisAsyncContext *redisAsyncConnectBind(const char *ip, int port, const char *source_addr);
122redisAsyncContext *redisAsyncConnectBindWithReuse(const char *ip, int port,
123 const char *source_addr);
124redisAsyncContext *redisAsyncConnectUnix(const char *path);
125int redisAsyncSetConnectCallback(redisAsyncContext *ac, redisConnectCallback *fn);
126int redisAsyncSetConnectCallbackNC(redisAsyncContext *ac, redisConnectCallbackNC *fn);
127int redisAsyncSetDisconnectCallback(redisAsyncContext *ac, redisDisconnectCallback *fn);
128
129redisAsyncPushFn *redisAsyncSetPushCallback(redisAsyncContext *ac, redisAsyncPushFn *fn);
130int redisAsyncSetTimeout(redisAsyncContext *ac, struct timeval tv);
131void redisAsyncDisconnect(redisAsyncContext *ac);
132void redisAsyncFree(redisAsyncContext *ac);
133
134/* Handle read/write events */
135void redisAsyncHandleRead(redisAsyncContext *ac);
136void redisAsyncHandleWrite(redisAsyncContext *ac);
137void redisAsyncHandleTimeout(redisAsyncContext *ac);
138void redisAsyncRead(redisAsyncContext *ac);
139void redisAsyncWrite(redisAsyncContext *ac);
140
141/* Command functions for an async context. Write the command to the
142 * output buffer and register the provided callback. */
143int redisvAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *format, va_list ap);
144int redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *format, ...);
145int redisAsyncCommandArgv(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, int argc, const char **argv, const size_t *argvlen);
146int redisAsyncFormattedCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *cmd, size_t len);
147
148#ifdef __cplusplus
149}
150#endif
151
152#endif