Make error callback argument const

master
Pieter Noordhuis 2010-10-19 16:48:19 +02:00
parent ba42ab2ef8
commit 206868de06
2 changed files with 5 additions and 7 deletions

View File

@ -3,7 +3,7 @@
#include <hiredis.h>
/* Prototype for the error callback. */
typedef void (redisErrorCallback)(redisContext*);
typedef void (redisErrorCallback)(const redisContext*);
/* This struct enables us to pass both the events and the
* redisContext to the read and write handlers. */
@ -73,11 +73,12 @@ void redisLibEventOnFree(redisContext *c, void *privdata) {
free(e);
}
redisContext *redisLibEventConnect(const char *ip, int port, redisErrorCallback *err, struct event_base *base) {
redisContext *redisLibEventConnect(struct event_base *base, redisErrorCallback *err, const char *ip, int port) {
redisEvents *e;
redisContext *c = redisConnectNonBlock(ip, port, NULL);
if (c->error != NULL) {
err(c);
redisFree(c);
return NULL;
}

View File

@ -11,18 +11,15 @@ void getCallback(redisContext *c, redisReply *reply, const void *privdata) {
redisDisconnect(c);
}
void errorCallback(redisContext *c) {
void errorCallback(const redisContext *c) {
printf("Error: %s\n", c->error);
/* Clean up the context when there was an error */
redisFree(c);
}
int main (int argc, char **argv) {
signal(SIGPIPE, SIG_IGN);
struct event_base *base = event_base_new();
redisContext *c = redisLibEventConnect("127.0.0.1", 6379, errorCallback, base);
redisContext *c = redisLibEventConnect(base, errorCallback, "127.0.0.1", 6379);
if (c == NULL) return 1;
redisCommand(c, "SET key %b", argv[argc-1], strlen(argv[argc-1]));