"Fossies" - the Fresh Open Source Software Archive

Member "redis-5.0.6/deps/hiredis/adapters/ivykis.h" (25 Sep 2019, 2275 Bytes) of package /linux/misc/redis-5.0.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #ifndef __HIREDIS_IVYKIS_H__
    2 #define __HIREDIS_IVYKIS_H__
    3 #include <iv.h>
    4 #include "../hiredis.h"
    5 #include "../async.h"
    6 
    7 typedef struct redisIvykisEvents {
    8     redisAsyncContext *context;
    9     struct iv_fd fd;
   10 } redisIvykisEvents;
   11 
   12 static void redisIvykisReadEvent(void *arg) {
   13     redisAsyncContext *context = (redisAsyncContext *)arg;
   14     redisAsyncHandleRead(context);
   15 }
   16 
   17 static void redisIvykisWriteEvent(void *arg) {
   18     redisAsyncContext *context = (redisAsyncContext *)arg;
   19     redisAsyncHandleWrite(context);
   20 }
   21 
   22 static void redisIvykisAddRead(void *privdata) {
   23     redisIvykisEvents *e = (redisIvykisEvents*)privdata;
   24     iv_fd_set_handler_in(&e->fd, redisIvykisReadEvent);
   25 }
   26 
   27 static void redisIvykisDelRead(void *privdata) {
   28     redisIvykisEvents *e = (redisIvykisEvents*)privdata;
   29     iv_fd_set_handler_in(&e->fd, NULL);
   30 }
   31 
   32 static void redisIvykisAddWrite(void *privdata) {
   33     redisIvykisEvents *e = (redisIvykisEvents*)privdata;
   34     iv_fd_set_handler_out(&e->fd, redisIvykisWriteEvent);
   35 }
   36 
   37 static void redisIvykisDelWrite(void *privdata) {
   38     redisIvykisEvents *e = (redisIvykisEvents*)privdata;
   39     iv_fd_set_handler_out(&e->fd, NULL);
   40 }
   41 
   42 static void redisIvykisCleanup(void *privdata) {
   43     redisIvykisEvents *e = (redisIvykisEvents*)privdata;
   44 
   45     iv_fd_unregister(&e->fd);
   46     free(e);
   47 }
   48 
   49 static int redisIvykisAttach(redisAsyncContext *ac) {
   50     redisContext *c = &(ac->c);
   51     redisIvykisEvents *e;
   52 
   53     /* Nothing should be attached when something is already attached */
   54     if (ac->ev.data != NULL)
   55         return REDIS_ERR;
   56 
   57     /* Create container for context and r/w events */
   58     e = (redisIvykisEvents*)malloc(sizeof(*e));
   59     e->context = ac;
   60 
   61     /* Register functions to start/stop listening for events */
   62     ac->ev.addRead = redisIvykisAddRead;
   63     ac->ev.delRead = redisIvykisDelRead;
   64     ac->ev.addWrite = redisIvykisAddWrite;
   65     ac->ev.delWrite = redisIvykisDelWrite;
   66     ac->ev.cleanup = redisIvykisCleanup;
   67     ac->ev.data = e;
   68 
   69     /* Initialize and install read/write events */
   70     IV_FD_INIT(&e->fd);
   71     e->fd.fd = c->fd;
   72     e->fd.handler_in = redisIvykisReadEvent;
   73     e->fd.handler_out = redisIvykisWriteEvent;
   74     e->fd.handler_err = NULL;
   75     e->fd.cookie = e->context;
   76 
   77     iv_fd_register(&e->fd);
   78 
   79     return REDIS_OK;
   80 }
   81 #endif