Mark the timeout parameter as const in various functions

The struct timeval argument in redisConnectWithTimeout(),
redisConnectUnixWithTimeout(), redisSetTimeout(),
redisContextSetTimeout(), redisContextConnectTcp()
and redisContextConnectUnix() is never modified and can
therefore be marked as const.

Signed-off-by: Noah Williamsson <noah.williamsson@gmail.com>
This commit is contained in:
Noah Williamsson 2012-05-30 17:33:48 +02:00 committed by Pieter Noordhuis
parent c532edc27f
commit fbf1bb648e
4 changed files with 12 additions and 12 deletions

View File

@ -1025,7 +1025,7 @@ redisContext *redisConnect(const char *ip, int port) {
return c; return c;
} }
redisContext *redisConnectWithTimeout(const char *ip, int port, struct timeval tv) { redisContext *redisConnectWithTimeout(const char *ip, int port, const struct timeval tv) {
redisContext *c; redisContext *c;
c = redisContextInit(); c = redisContextInit();
@ -1061,7 +1061,7 @@ redisContext *redisConnectUnix(const char *path) {
return c; return c;
} }
redisContext *redisConnectUnixWithTimeout(const char *path, struct timeval tv) { redisContext *redisConnectUnixWithTimeout(const char *path, const struct timeval tv) {
redisContext *c; redisContext *c;
c = redisContextInit(); c = redisContextInit();
@ -1086,7 +1086,7 @@ redisContext *redisConnectUnixNonBlock(const char *path) {
} }
/* Set read/write timeout on a blocking socket. */ /* Set read/write timeout on a blocking socket. */
int redisSetTimeout(redisContext *c, struct timeval tv) { int redisSetTimeout(redisContext *c, const struct timeval tv) {
if (c->flags & REDIS_BLOCK) if (c->flags & REDIS_BLOCK)
return redisContextSetTimeout(c,tv); return redisContextSetTimeout(c,tv);
return REDIS_ERR; return REDIS_ERR;

View File

@ -173,12 +173,12 @@ typedef struct redisContext {
} redisContext; } redisContext;
redisContext *redisConnect(const char *ip, int port); redisContext *redisConnect(const char *ip, int port);
redisContext *redisConnectWithTimeout(const char *ip, int port, struct timeval tv); redisContext *redisConnectWithTimeout(const char *ip, int port, const struct timeval tv);
redisContext *redisConnectNonBlock(const char *ip, int port); redisContext *redisConnectNonBlock(const char *ip, int port);
redisContext *redisConnectUnix(const char *path); redisContext *redisConnectUnix(const char *path);
redisContext *redisConnectUnixWithTimeout(const char *path, struct timeval tv); redisContext *redisConnectUnixWithTimeout(const char *path, const struct timeval tv);
redisContext *redisConnectUnixNonBlock(const char *path); redisContext *redisConnectUnixNonBlock(const char *path);
int redisSetTimeout(redisContext *c, struct timeval tv); int redisSetTimeout(redisContext *c, const struct timeval tv);
int redisEnableKeepAlive(redisContext *c); int redisEnableKeepAlive(redisContext *c);
void redisFree(redisContext *c); void redisFree(redisContext *c);
int redisBufferRead(redisContext *c); int redisBufferRead(redisContext *c);

6
net.c
View File

@ -232,7 +232,7 @@ int redisCheckSocketError(redisContext *c, int fd) {
return REDIS_OK; return REDIS_OK;
} }
int redisContextSetTimeout(redisContext *c, struct timeval tv) { int redisContextSetTimeout(redisContext *c, const struct timeval tv) {
if (setsockopt(c->fd,SOL_SOCKET,SO_RCVTIMEO,&tv,sizeof(tv)) == -1) { if (setsockopt(c->fd,SOL_SOCKET,SO_RCVTIMEO,&tv,sizeof(tv)) == -1) {
__redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(SO_RCVTIMEO)"); __redisSetErrorFromErrno(c,REDIS_ERR_IO,"setsockopt(SO_RCVTIMEO)");
return REDIS_ERR; return REDIS_ERR;
@ -244,7 +244,7 @@ int redisContextSetTimeout(redisContext *c, struct timeval tv) {
return REDIS_OK; return REDIS_OK;
} }
int redisContextConnectTcp(redisContext *c, const char *addr, int port, struct timeval *timeout) { int redisContextConnectTcp(redisContext *c, const char *addr, int port, const struct timeval *timeout) {
int s, rv; int s, rv;
char _port[6]; /* strlen("65535"); */ char _port[6]; /* strlen("65535"); */
struct addrinfo hints, *servinfo, *p; struct addrinfo hints, *servinfo, *p;
@ -300,7 +300,7 @@ end:
return rv; // Need to return REDIS_OK if alright return rv; // Need to return REDIS_OK if alright
} }
int redisContextConnectUnix(redisContext *c, const char *path, struct timeval *timeout) { int redisContextConnectUnix(redisContext *c, const char *path, const struct timeval *timeout) {
int s; int s;
int blocking = (c->flags & REDIS_BLOCK); int blocking = (c->flags & REDIS_BLOCK);
struct sockaddr_un sa; struct sockaddr_un sa;

6
net.h
View File

@ -40,9 +40,9 @@
#endif #endif
int redisCheckSocketError(redisContext *c, int fd); int redisCheckSocketError(redisContext *c, int fd);
int redisContextSetTimeout(redisContext *c, struct timeval tv); int redisContextSetTimeout(redisContext *c, const struct timeval tv);
int redisContextConnectTcp(redisContext *c, const char *addr, int port, struct timeval *timeout); int redisContextConnectTcp(redisContext *c, const char *addr, int port, const struct timeval *timeout);
int redisContextConnectUnix(redisContext *c, const char *path, struct timeval *timeout); int redisContextConnectUnix(redisContext *c, const char *path, const struct timeval *timeout);
int redisKeepAlive(redisContext *c, int interval); int redisKeepAlive(redisContext *c, int interval);
#endif #endif