Simulation Core
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. #ifndef __HIREDIS_ASYNC_H
  32. #define __HIREDIS_ASYNC_H
  33. #include "hiredis.h"
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. struct redisAsyncContext; /* need forward declaration of redisAsyncContext */
  38. struct dict; /* dictionary header is included in async.c */
  39. /* Reply callback prototype and container */
  40. typedef void (redisCallbackFn)(struct redisAsyncContext*, void*, void*);
  41. typedef struct redisCallback {
  42. struct redisCallback *next; /* simple singly linked list */
  43. redisCallbackFn *fn;
  44. int pending_subs;
  45. int unsubscribe_sent;
  46. void *privdata;
  47. } redisCallback;
  48. /* List of callbacks for either regular replies or pub/sub */
  49. typedef struct redisCallbackList {
  50. redisCallback *head, *tail;
  51. } redisCallbackList;
  52. /* Connection callback prototypes */
  53. typedef void (redisDisconnectCallback)(const struct redisAsyncContext*, int status);
  54. typedef void (redisConnectCallback)(const struct redisAsyncContext*, int status);
  55. typedef void (redisConnectCallbackNC)(struct redisAsyncContext *, int status);
  56. typedef void(redisTimerCallback)(void *timer, void *privdata);
  57. /* Context for an async connection to Redis */
  58. typedef struct redisAsyncContext {
  59. /* Hold the regular context, so it can be realloc'ed. */
  60. redisContext c;
  61. /* Setup error flags so they can be used directly. */
  62. int err;
  63. char *errstr;
  64. /* Not used by hiredis */
  65. void *data;
  66. void (*dataCleanup)(void *privdata);
  67. /* Event library data and hooks */
  68. struct {
  69. void *data;
  70. /* Hooks that are called when the library expects to start
  71. * reading/writing. These functions should be idempotent. */
  72. void (*addRead)(void *privdata);
  73. void (*delRead)(void *privdata);
  74. void (*addWrite)(void *privdata);
  75. void (*delWrite)(void *privdata);
  76. void (*cleanup)(void *privdata);
  77. void (*scheduleTimer)(void *privdata, struct timeval tv);
  78. } ev;
  79. /* Called when either the connection is terminated due to an error or per
  80. * user request. The status is set accordingly (REDIS_OK, REDIS_ERR). */
  81. redisDisconnectCallback *onDisconnect;
  82. /* Called when the first write event was received. */
  83. redisConnectCallback *onConnect;
  84. redisConnectCallbackNC *onConnectNC;
  85. /* Regular command callbacks */
  86. redisCallbackList replies;
  87. /* Address used for connect() */
  88. struct sockaddr *saddr;
  89. size_t addrlen;
  90. /* Subscription callbacks */
  91. struct {
  92. redisCallbackList replies;
  93. struct dict *channels;
  94. struct dict *patterns;
  95. int pending_unsubs;
  96. } sub;
  97. /* Any configured RESP3 PUSH handler */
  98. redisAsyncPushFn *push_cb;
  99. } redisAsyncContext;
  100. /* Functions that proxy to hiredis */
  101. redisAsyncContext *redisAsyncConnectWithOptions(const redisOptions *options);
  102. redisAsyncContext *redisAsyncConnect(const char *ip, int port);
  103. redisAsyncContext *redisAsyncConnectBind(const char *ip, int port, const char *source_addr);
  104. redisAsyncContext *redisAsyncConnectBindWithReuse(const char *ip, int port,
  105. const char *source_addr);
  106. redisAsyncContext *redisAsyncConnectUnix(const char *path);
  107. int redisAsyncSetConnectCallback(redisAsyncContext *ac, redisConnectCallback *fn);
  108. int redisAsyncSetConnectCallbackNC(redisAsyncContext *ac, redisConnectCallbackNC *fn);
  109. int redisAsyncSetDisconnectCallback(redisAsyncContext *ac, redisDisconnectCallback *fn);
  110. redisAsyncPushFn *redisAsyncSetPushCallback(redisAsyncContext *ac, redisAsyncPushFn *fn);
  111. int redisAsyncSetTimeout(redisAsyncContext *ac, struct timeval tv);
  112. void redisAsyncDisconnect(redisAsyncContext *ac);
  113. void redisAsyncFree(redisAsyncContext *ac);
  114. /* Handle read/write events */
  115. void redisAsyncHandleRead(redisAsyncContext *ac);
  116. void redisAsyncHandleWrite(redisAsyncContext *ac);
  117. void redisAsyncHandleTimeout(redisAsyncContext *ac);
  118. void redisAsyncRead(redisAsyncContext *ac);
  119. void redisAsyncWrite(redisAsyncContext *ac);
  120. /* Command functions for an async context. Write the command to the
  121. * output buffer and register the provided callback. */
  122. int redisvAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *format, va_list ap);
  123. int redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *format, ...);
  124. int redisAsyncCommandArgv(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, int argc, const char **argv, const size_t *argvlen);
  125. int redisAsyncFormattedCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, const char *cmd, size_t len);
  126. #ifdef __cplusplus
  127. }
  128. #endif
  129. #endif