Skip to content

Commit

Permalink
fixup: Use function instead of macro to set an async event engine
Browse files Browse the repository at this point in the history
Signed-off-by: Björn Svensson <[email protected]>
  • Loading branch information
bjosv committed Dec 13, 2024
1 parent 425af3f commit 8c31a25
Show file tree
Hide file tree
Showing 23 changed files with 70 additions and 138 deletions.
2 changes: 1 addition & 1 deletion examples/cluster-async-tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int main(int argc, char **argv) {
valkeyClusterSetOptionEnableTLS(&options, tls);

struct event_base *base = event_base_new();
VALKEY_CLUSTER_OPTIONS_SET_ADAPTER_LIBEVENT(&options, base);
valkeyClusterSetOptionUseLibevent(&options, base);

valkeyClusterAsyncContext *acc = valkeyClusterAsyncConnectWithOptions(&options);
if (acc == NULL || acc->err != 0) {
Expand Down
2 changes: 1 addition & 1 deletion examples/cluster-async.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int main(int argc, char **argv) {
options.initial_nodes = "127.0.0.1:7000";
options.onConnect = connectCallback;
options.onDisconnect = disconnectCallback;
VALKEY_CLUSTER_OPTIONS_SET_ADAPTER_LIBEVENT(&options, base);
valkeyClusterSetOptionUseLibevent(&options, base);

printf("Connecting...\n");
valkeyClusterAsyncContext *acc = valkeyClusterAsyncConnectWithOptions(&options);
Expand Down
2 changes: 1 addition & 1 deletion examples/cluster-clientside-caching-async.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ int main(int argc, char **argv) {
options.initial_nodes = CLUSTER_NODE;
options.onConnectNC = connectCallbackNC;
options.onDisconnect = disconnectCallback;
VALKEY_CLUSTER_OPTIONS_SET_ADAPTER_LIBEVENT(&options, base);
valkeyClusterSetOptionUseLibevent(&options, base);

valkeyClusterAsyncContext *acc = valkeyClusterAsyncContextInit(&options);
assert(acc);
Expand Down
17 changes: 5 additions & 12 deletions include/valkey/adapters/ae.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,15 @@ static int valkeyAeAttachAdapter(valkeyAsyncContext *ac, void *loop) {
}

VALKEY_UNUSED
static int valkeyClusterAeAttach(valkeyClusterAsyncContext *acc,
aeEventLoop *loop) {
if (acc == NULL || loop == NULL) {
static int valkeyClusterSetOptionUseAe(valkeyClusterOptions *options,
aeEventLoop *loop) {
if (options == NULL || loop == NULL) {
return VALKEY_ERR;
}

acc->attach_fn = valkeyAeAttachAdapter;
acc->attach_data = loop;
options->attach_fn = valkeyAeAttachAdapter;
options->attach_data = loop;
return VALKEY_OK;
}

/* Helper macro to initialize options. */
#define VALKEY_CLUSTER_OPTIONS_SET_ADAPTER_AE(opts, loop) \
do { \
(opts)->attach_fn = valkeyAeAttachAdapter; \
(opts)->attach_data = loop; \
} while (0)

#endif /* VALKEY_ADAPTERS_AE_H */
17 changes: 5 additions & 12 deletions include/valkey/adapters/glib.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,15 @@ static int valkeyGlibAttachAdapter(valkeyAsyncContext *ac, void *context) {
}

VALKEY_UNUSED
static int valkeyClusterGlibAttach(valkeyClusterAsyncContext *acc,
GMainContext *context) {
if (acc == NULL) { // A NULL context is accepted.
static int valkeyClusterSetOptionUseGlib(valkeyClusterOptions *options,
GMainContext *context) {
if (options == NULL) { // A NULL context is accepted.
return VALKEY_ERR;
}

acc->attach_fn = valkeyGlibAttachAdapter;
acc->attach_data = context;
options->attach_fn = valkeyGlibAttachAdapter;
options->attach_data = context;
return VALKEY_OK;
}

/* Helper macro to initialize options. */
#define VALKEY_CLUSTER_OPTIONS_SET_ADAPTER_GLIB(opts, context) \
do { \
(opts)->attach_fn = valkeyGlibAttachAdapter; \
(opts)->attach_data = context; \
} while (0)

#endif /* VALKEY_ADAPTERS_GLIB_H */
12 changes: 3 additions & 9 deletions include/valkey/adapters/ivykis.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,13 @@ static int valkeyIvykisAttachAdapter(valkeyAsyncContext *ac, VALKEY_UNUSED void
}

VALKEY_UNUSED
static int valkeyClusterIvykisAttach(valkeyClusterAsyncContext *acc) {
if (acc == NULL) {
static int valkeyClusterSetOptionUseIvykis(valkeyClusterOptions *options) {
if (options == NULL) {
return VALKEY_ERR;
}

acc->attach_fn = valkeyIvykisAttachAdapter;
options->attach_fn = valkeyIvykisAttachAdapter;
return VALKEY_OK;
}

/* Helper macro to initialize options. */
#define VALKEY_CLUSTER_OPTIONS_SET_ADAPTER_IVYKIS(opts) \
do { \
(opts)->attach_fn = valkeyAeAttachAdapter; \
} while (0)

#endif /* VALKEY_ADAPTERS_IVYKIS_H */
17 changes: 5 additions & 12 deletions include/valkey/adapters/libev.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,15 @@ static int valkeyLibevAttachAdapter(valkeyAsyncContext *ac, void *loop) {
}

VALKEY_UNUSED
static int valkeyClusterLibevAttach(valkeyClusterAsyncContext *acc,
struct ev_loop *loop) {
if (acc == NULL || loop == NULL) {
static int valkeyClusterSetOptionUseLibev(valkeyClusterOptions *options,
struct ev_loop *loop) {
if (options == NULL || loop == NULL) {
return VALKEY_ERR;
}

acc->attach_fn = valkeyLibevAttachAdapter;
acc->attach_data = loop;
options->attach_fn = valkeyLibevAttachAdapter;
options->attach_data = loop;
return VALKEY_OK;
}

/* Helper macro to initialize options. */
#define VALKEY_CLUSTER_OPTIONS_SET_ADAPTER_LIBEV(opts, loop) \
do { \
(opts)->attach_fn = valkeyLibevAttachAdapter; \
(opts)->attach_data = loop; \
} while (0)

#endif /* VALKEY_ADAPTERS_LIBEV_H */
17 changes: 5 additions & 12 deletions include/valkey/adapters/libevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,15 @@ static int valkeyLibeventAttachAdapter(valkeyAsyncContext *ac, void *base) {
}

VALKEY_UNUSED
static int valkeyClusterLibeventAttach(valkeyClusterAsyncContext *acc,
struct event_base *base) {
if (acc == NULL || base == NULL) {
static int valkeyClusterSetOptionUseLibevent(valkeyClusterOptions *options,
struct event_base *base) {
if (options == NULL || base == NULL) {
return VALKEY_ERR;
}

acc->attach_fn = valkeyLibeventAttachAdapter;
acc->attach_data = base;
options->attach_fn = valkeyLibeventAttachAdapter;
options->attach_data = base;
return VALKEY_OK;
}

/* Helper macro to initialize options. */
#define VALKEY_CLUSTER_OPTIONS_SET_ADAPTER_LIBEVENT(opts, event_base) \
do { \
(opts)->attach_fn = valkeyLibeventAttachAdapter; \
(opts)->attach_data = event_base; \
} while (0)

#endif /* VALKEY_ADAPTERS_LIBEVENT_H */
17 changes: 5 additions & 12 deletions include/valkey/adapters/libhv.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,15 @@ static int valkeyLibhvAttachAdapter(valkeyAsyncContext *ac, void *loop) {
}

VALKEY_UNUSED
static int valkeyClusterLibhvAttach(valkeyClusterAsyncContext *acc,
hloop_t *loop) {
if (acc == NULL || loop == NULL) {
static int valkeyClusterSetOptionUseLibhv(valkeyClusterOptions *options,
hloop_t *loop) {
if (options == NULL || loop == NULL) {
return VALKEY_ERR;
}

acc->attach_fn = valkeyLibhvAttachAdapter;
acc->attach_data = loop;
options->attach_fn = valkeyLibhvAttachAdapter;
options->attach_data = loop;
return VALKEY_OK;
}

/* Helper macro to initialize options. */
#define VALKEY_CLUSTER_OPTIONS_SET_ADAPTER_LIBHV(opts, loop) \
do { \
(opts)->attach_fn = valkeyLibhvAttachAdapter; \
(opts)->attach_data = loop; \
} while (0)

#endif /* VALKEY_ADAPTERS_LIBHV_H */
17 changes: 5 additions & 12 deletions include/valkey/adapters/libsdevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,15 @@ static int valkeyLibsdeventAttachAdapter(valkeyAsyncContext *ac, void *event) {
}

VALKEY_UNUSED
static int valkeyClusterLibsdeventAttach(valkeyClusterAsyncContext *acc,
struct sd_event *event) {
if (acc == NULL || event == NULL) {
static int valkeyClusterSetOptionUseLibsdevent(valkeyClusterOptions *options,
struct sd_event *event) {
if (options == NULL || event == NULL) {
return VALKEY_ERR;
}

acc->attach_fn = valkeyLibsdeventAttachAdapter;
acc->attach_data = event;
options->attach_fn = valkeyLibsdeventAttachAdapter;
options->attach_data = event;
return VALKEY_OK;
}

/* Helper macro to initialize options. */
#define VALKEY_CLUSTER_OPTIONS_SET_ADAPTER_LIBSDEVENT(opts, event) \
do { \
(opts)->attach_fn = valkeyLibsdeventAttachAdapter; \
(opts)->attach_data = event; \
} while (0)

#endif /* VALKEY_ADAPTERS_LIBSDEVENT_H */
17 changes: 5 additions & 12 deletions include/valkey/adapters/libuv.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,22 +203,15 @@ static int valkeyLibuvAttachAdapter(valkeyAsyncContext *ac, void *loop) {
}

VALKEY_UNUSED
static int valkeyClusterLibuvAttach(valkeyClusterAsyncContext *acc,
uv_loop_t *loop) {
if (acc == NULL || loop == NULL) {
static int valkeyClusterSetOptionUseLibuv(valkeyClusterOptions *options,
uv_loop_t *loop) {
if (options == NULL || loop == NULL) {
return VALKEY_ERR;
}

acc->attach_fn = valkeyLibuvAttachAdapter;
acc->attach_data = loop;
options->attach_fn = valkeyLibuvAttachAdapter;
options->attach_data = loop;
return VALKEY_OK;
}

/* Helper macro to initialize options. */
#define VALKEY_CLUSTER_OPTIONS_SET_ADAPTER_LIBUV(opts, loop) \
do { \
(opts)->attach_fn = valkeyLibuvAttachAdapter; \
(opts)->attach_data = loop; \
} while (0)

#endif /* VALKEY_ADAPTERS_LIBUV_H */
17 changes: 5 additions & 12 deletions include/valkey/adapters/macosx.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,15 @@ static int valkeyMacOSAttachAdapter(valkeyAsyncContext *ac, void *loop) {
}

VALKEY_UNUSED
static int valkeyClusterMacOSAttach(valkeyClusterAsyncContext *acc,
CFRunLoopRef loop) {
if (acc == NULL || loop == NULL) {
static int valkeyClusterSetOptionUseMacOS(valkeyClusterOptions *options,
CFRunLoopRef loop) {
if (options == NULL || loop == NULL) {
return VALKEY_ERR;
}

acc->attach_fn = valkeyMacOSAttachAdapter;
acc->attach_data = loop;
options->attach_fn = valkeyMacOSAttachAdapter;
options->attach_data = loop;
return VALKEY_OK;
}

/* Helper macro to initialize options. */
#define VALKEY_CLUSTER_OPTIONS_SET_ADAPTER_MACOSX(opts, loop) \
do { \
(opts)->attach_fn = valkeyMacOSAttachAdapter; \
(opts)->attach_data = loop; \
} while (0)

#endif /* VALKEY_ADAPTERS_MACOSX_H */
12 changes: 3 additions & 9 deletions include/valkey/adapters/poll.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,13 @@ static int valkeyPollAttachAdapter(valkeyAsyncContext *ac, VALKEY_UNUSED void *u
}

VALKEY_UNUSED
static int valkeyClusterPollAttach(valkeyClusterAsyncContext *acc) {
if (acc == NULL) {
static int valkeyClusterSetOptionUsePoll(valkeyClusterOptions *options) {
if (options == NULL) {
return VALKEY_ERR;
}

acc->attach_fn = valkeyPollAttachAdapter;
options->attach_fn = valkeyPollAttachAdapter;
return VALKEY_OK;
}

/* Helper macro to initialize options. */
#define VALKEY_CLUSTER_OPTIONS_SET_ADAPTER_POLL(opts) \
do { \
(opts)->attach_fn = valkeyPollAttachAdapter; \
} while (0)

#endif /* VALKEY_ADAPTERS_POLL_H */
2 changes: 1 addition & 1 deletion tests/clusterclient_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ int main(int argc, char **argv) {
options.onConnect = connectCallback;
options.onDisconnect = disconnectCallback;
}
VALKEY_CLUSTER_OPTIONS_SET_ADAPTER_LIBEVENT(&options, base);
valkeyClusterSetOptionUseLibevent(&options, base);

valkeyClusterAsyncContext *acc = valkeyClusterAsyncConnectWithOptions(&options);
if (acc == NULL || acc->err != 0) {
Expand Down
2 changes: 1 addition & 1 deletion tests/clusterclient_reconnect_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ int main(int argc, char **argv) {
options.initial_nodes = initnode;
options.options = VALKEY_OPT_USE_CLUSTER_SLOTS |
VALKEY_OPT_BLOCKING_INITIAL_UPDATE;
VALKEY_CLUSTER_OPTIONS_SET_ADAPTER_LIBEVENT(&options, base);
valkeyClusterSetOptionUseLibevent(&options, base);

valkeyClusterAsyncContext *acc = valkeyClusterAsyncContextInit(&options);
assert(acc);
Expand Down
2 changes: 1 addition & 1 deletion tests/ct_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int main(void) {
options.initial_nodes = CLUSTER_NODE;
options.onConnect = connectCallback;
options.onDisconnect = disconnectCallback;
VALKEY_CLUSTER_OPTIONS_SET_ADAPTER_LIBEVENT(&options, base);
valkeyClusterSetOptionUseLibevent(&options, base);

valkeyClusterAsyncContext *acc = valkeyClusterAsyncContextInit(&options);
assert(acc);
Expand Down
2 changes: 1 addition & 1 deletion tests/ct_async_glib.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main(int argc, char **argv) {
options.options = VALKEY_OPT_BLOCKING_INITIAL_UPDATE;
options.onConnect = connectCallback;
options.onDisconnect = disconnectCallback;
VALKEY_CLUSTER_OPTIONS_SET_ADAPTER_GLIB(&options, context);
valkeyClusterSetOptionUseGlib(&options, context);

valkeyClusterAsyncContext *acc = valkeyClusterAsyncConnectWithOptions(&options);
assert(acc);
Expand Down
2 changes: 1 addition & 1 deletion tests/ct_async_libev.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int main(int argc, char **argv) {
options.options = VALKEY_OPT_BLOCKING_INITIAL_UPDATE;
options.onConnect = connectCallback;
options.onDisconnect = disconnectCallback;
VALKEY_CLUSTER_OPTIONS_SET_ADAPTER_LIBEV(&options, EV_DEFAULT);
valkeyClusterSetOptionUseLibev(&options, EV_DEFAULT);

valkeyClusterAsyncContext *acc = valkeyClusterAsyncConnectWithOptions(&options);
assert(acc);
Expand Down
2 changes: 1 addition & 1 deletion tests/ct_async_libuv.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int main(int argc, char **argv) {
options.options = VALKEY_OPT_BLOCKING_INITIAL_UPDATE;
options.onConnect = connectCallback;
options.onDisconnect = disconnectCallback;
VALKEY_CLUSTER_OPTIONS_SET_ADAPTER_LIBUV(&options, loop);
valkeyClusterSetOptionUseLibuv(&options, loop);

valkeyClusterAsyncContext *acc = valkeyClusterAsyncConnectWithOptions(&options);
assert(acc);
Expand Down
Loading

0 comments on commit 8c31a25

Please sign in to comment.