make networking.c a C++ file
This commit is contained in:
parent
f5caec488d
commit
62090d0a97
@ -27,7 +27,7 @@ ifneq (,$(findstring FreeBSD,$(uname_S)))
|
|||||||
STD+=-Wno-c11-extensions
|
STD+=-Wno-c11-extensions
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
WARN=-Wall -Werror -W -Wno-missing-field-initializers
|
WARN=-Wall -Wextra -Werror -W -Wno-missing-field-initializers
|
||||||
OPT=$(OPTIMIZATION)
|
OPT=$(OPTIMIZATION)
|
||||||
|
|
||||||
PREFIX?=/usr/local
|
PREFIX?=/usr/local
|
||||||
|
@ -473,7 +473,7 @@ extern "C" void ProcessEventCore(aeEventLoop *eventLoop, aeFileEvent *fe, int ma
|
|||||||
* inverted. */
|
* inverted. */
|
||||||
if (!invert && fe->mask & mask & AE_READABLE) {
|
if (!invert && fe->mask & mask & AE_READABLE) {
|
||||||
LOCK_IF_NECESSARY(fe, AE_READ_THREADSAFE);
|
LOCK_IF_NECESSARY(fe, AE_READ_THREADSAFE);
|
||||||
fe->rfileProc(eventLoop,fd,fe->clientData,mask);
|
fe->rfileProc(eventLoop,fd,fe->clientData,mask | (fe->mask & AE_READ_THREADSAFE));
|
||||||
fired++;
|
fired++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -481,7 +481,7 @@ extern "C" void ProcessEventCore(aeEventLoop *eventLoop, aeFileEvent *fe, int ma
|
|||||||
if (fe->mask & mask & AE_WRITABLE) {
|
if (fe->mask & mask & AE_WRITABLE) {
|
||||||
if (!fired || fe->wfileProc != fe->rfileProc) {
|
if (!fired || fe->wfileProc != fe->rfileProc) {
|
||||||
LOCK_IF_NECESSARY(fe, AE_WRITE_THREADSAFE);
|
LOCK_IF_NECESSARY(fe, AE_WRITE_THREADSAFE);
|
||||||
fe->wfileProc(eventLoop,fd,fe->clientData,mask);
|
fe->wfileProc(eventLoop,fd,fe->clientData,mask | (fe->mask & AE_WRITE_THREADSAFE));
|
||||||
fired++;
|
fired++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -491,7 +491,7 @@ extern "C" void ProcessEventCore(aeEventLoop *eventLoop, aeFileEvent *fe, int ma
|
|||||||
if (invert && fe->mask & mask & AE_READABLE) {
|
if (invert && fe->mask & mask & AE_READABLE) {
|
||||||
if (!fired || fe->wfileProc != fe->rfileProc) {
|
if (!fired || fe->wfileProc != fe->rfileProc) {
|
||||||
LOCK_IF_NECESSARY(fe, AE_READ_THREADSAFE);
|
LOCK_IF_NECESSARY(fe, AE_READ_THREADSAFE);
|
||||||
fe->rfileProc(eventLoop,fd,fe->clientData,mask);
|
fe->rfileProc(eventLoop,fd,fe->clientData,mask | (fe->mask & AE_READ_THREADSAFE));
|
||||||
fired++;
|
fired++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2022,7 +2022,7 @@ void rewriteConfigClientoutputbufferlimitOption(struct rewriteConfigState *state
|
|||||||
rewriteConfigFormatMemory(soft,sizeof(soft),
|
rewriteConfigFormatMemory(soft,sizeof(soft),
|
||||||
server.client_obuf_limits[j].soft_limit_bytes);
|
server.client_obuf_limits[j].soft_limit_bytes);
|
||||||
|
|
||||||
char *typename = getClientTypeName(j);
|
const char *typename = getClientTypeName(j);
|
||||||
if (!strcmp(typename,"slave")) typename = "replica";
|
if (!strcmp(typename,"slave")) typename = "replica";
|
||||||
line = sdscatprintf(sdsempty(),"%s %s %s %s %ld",
|
line = sdscatprintf(sdsempty(),"%s %s %s %s %ld",
|
||||||
option, typename, hard, soft,
|
option, typename, hard, soft,
|
||||||
|
@ -30,13 +30,11 @@
|
|||||||
#ifndef _REDIS_FMACRO_H
|
#ifndef _REDIS_FMACRO_H
|
||||||
#define _REDIS_FMACRO_H
|
#define _REDIS_FMACRO_H
|
||||||
|
|
||||||
#define _BSD_SOURCE
|
#define _DEFAULT_SOURCE 1
|
||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
#ifndef __cplusplus
|
#define _GNU_SOURCE 1
|
||||||
#define _GNU_SOURCE
|
#define _DEFAULT_SOURCE 1
|
||||||
#define _DEFAULT_SOURCE
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_AIX)
|
#if defined(_AIX)
|
||||||
|
10
src/intset.h
10
src/intset.h
@ -32,16 +32,12 @@
|
|||||||
#define __INTSET_H
|
#define __INTSET_H
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#define ZERO_LENGTH_ARRAY_LENGTH 1
|
|
||||||
#else
|
|
||||||
#define ZERO_LENGTH_ARRAY_LENGTH
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct intset {
|
typedef struct intset {
|
||||||
uint32_t encoding;
|
uint32_t encoding;
|
||||||
uint32_t length;
|
uint32_t length;
|
||||||
int8_t contents[ZERO_LENGTH_ARRAY_LENGTH];
|
#ifndef __cplusplus
|
||||||
|
int8_t contents[];
|
||||||
|
#endif
|
||||||
} intset;
|
} intset;
|
||||||
|
|
||||||
intset *intsetNew(void);
|
intset *intsetNew(void);
|
||||||
|
2433
src/networking.c
2433
src/networking.c
File diff suppressed because it is too large
Load Diff
@ -276,7 +276,7 @@ void _addReplyProtoToList(client *c, const char *s, size_t len) {
|
|||||||
* new node */
|
* new node */
|
||||||
size_t avail = tail->size - tail->used;
|
size_t avail = tail->size - tail->used;
|
||||||
size_t copy = avail >= len? len: avail;
|
size_t copy = avail >= len? len: avail;
|
||||||
memcpy(tail->buf + tail->used, s, copy);
|
memcpy(tail->buf() + tail->used, s, copy);
|
||||||
tail->used += copy;
|
tail->used += copy;
|
||||||
s += copy;
|
s += copy;
|
||||||
len -= copy;
|
len -= copy;
|
||||||
@ -289,7 +289,7 @@ void _addReplyProtoToList(client *c, const char *s, size_t len) {
|
|||||||
/* take over the allocation's internal fragmentation */
|
/* take over the allocation's internal fragmentation */
|
||||||
tail->size = zmalloc_usable(tail) - sizeof(clientReplyBlock);
|
tail->size = zmalloc_usable(tail) - sizeof(clientReplyBlock);
|
||||||
tail->used = len;
|
tail->used = len;
|
||||||
memcpy(tail->buf, s, len);
|
memcpy(tail->buf(), s, len);
|
||||||
listAddNodeTail(c->reply, tail);
|
listAddNodeTail(c->reply, tail);
|
||||||
c->reply_bytes += tail->size;
|
c->reply_bytes += tail->size;
|
||||||
}
|
}
|
||||||
@ -458,8 +458,8 @@ void setDeferredAggregateLen(client *c, void *node, long length, char prefix) {
|
|||||||
if (ln->next != NULL && (next = (clientReplyBlock*)listNodeValue(ln->next)) &&
|
if (ln->next != NULL && (next = (clientReplyBlock*)listNodeValue(ln->next)) &&
|
||||||
next->size - next->used >= lenstr_len &&
|
next->size - next->used >= lenstr_len &&
|
||||||
next->used < PROTO_REPLY_CHUNK_BYTES * 4) {
|
next->used < PROTO_REPLY_CHUNK_BYTES * 4) {
|
||||||
memmove(next->buf + lenstr_len, next->buf, next->used);
|
memmove(next->buf() + lenstr_len, next->buf(), next->used);
|
||||||
memcpy(next->buf, lenstr, lenstr_len);
|
memcpy(next->buf(), lenstr, lenstr_len);
|
||||||
next->used += lenstr_len;
|
next->used += lenstr_len;
|
||||||
listDelNode(c->reply,ln);
|
listDelNode(c->reply,ln);
|
||||||
} else {
|
} else {
|
||||||
@ -468,7 +468,7 @@ void setDeferredAggregateLen(client *c, void *node, long length, char prefix) {
|
|||||||
/* Take over the allocation's internal fragmentation */
|
/* Take over the allocation's internal fragmentation */
|
||||||
buf->size = zmalloc_usable(buf) - sizeof(clientReplyBlock);
|
buf->size = zmalloc_usable(buf) - sizeof(clientReplyBlock);
|
||||||
buf->used = lenstr_len;
|
buf->used = lenstr_len;
|
||||||
memcpy(buf->buf, lenstr, lenstr_len);
|
memcpy(buf->buf(), lenstr, lenstr_len);
|
||||||
listNodeValue(ln) = buf;
|
listNodeValue(ln) = buf;
|
||||||
c->reply_bytes += buf->size;
|
c->reply_bytes += buf->size;
|
||||||
}
|
}
|
||||||
@ -1126,7 +1126,7 @@ int writeToClient(int fd, client *c, int handler_installed) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
nwritten = write(fd, o->buf + c->sentlen, objlen - c->sentlen);
|
nwritten = write(fd, o->buf() + c->sentlen, objlen - c->sentlen);
|
||||||
|
|
||||||
if (nwritten <= 0) break;
|
if (nwritten <= 0) break;
|
||||||
c->sentlen += nwritten;
|
c->sentlen += nwritten;
|
||||||
@ -1646,6 +1646,7 @@ void readQueryFromClient(aeEventLoop *el, int fd, void *privdata, int mask) {
|
|||||||
size_t qblen;
|
size_t qblen;
|
||||||
UNUSED(el);
|
UNUSED(el);
|
||||||
UNUSED(mask);
|
UNUSED(mask);
|
||||||
|
serverAssert(mask & AE_READ_THREADSAFE);
|
||||||
|
|
||||||
readlen = PROTO_IOBUF_LEN;
|
readlen = PROTO_IOBUF_LEN;
|
||||||
/* If this is a multi bulk request, and we are processing a bulk reply
|
/* If this is a multi bulk request, and we are processing a bulk reply
|
||||||
|
@ -31,12 +31,6 @@
|
|||||||
#ifndef __QUICKLIST_H__
|
#ifndef __QUICKLIST_H__
|
||||||
#define __QUICKLIST_H__
|
#define __QUICKLIST_H__
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#define ZERO_LENGTH_ARRAY_LENGTH 1
|
|
||||||
#else
|
|
||||||
#define ZERO_LENGTH_ARRAY_LENGTH
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Node, quicklist, and Iterator are the only data structures used currently. */
|
/* Node, quicklist, and Iterator are the only data structures used currently. */
|
||||||
|
|
||||||
/* quicklistNode is a 32 byte struct describing a ziplist for a quicklist.
|
/* quicklistNode is a 32 byte struct describing a ziplist for a quicklist.
|
||||||
@ -67,7 +61,9 @@ typedef struct quicklistNode {
|
|||||||
* When quicklistNode->zl is compressed, node->zl points to a quicklistLZF */
|
* When quicklistNode->zl is compressed, node->zl points to a quicklistLZF */
|
||||||
typedef struct quicklistLZF {
|
typedef struct quicklistLZF {
|
||||||
unsigned int sz; /* LZF size in bytes*/
|
unsigned int sz; /* LZF size in bytes*/
|
||||||
char compressed[ZERO_LENGTH_ARRAY_LENGTH];
|
#ifndef __cplusplus
|
||||||
|
char compressed[];
|
||||||
|
#endif
|
||||||
} quicklistLZF;
|
} quicklistLZF;
|
||||||
|
|
||||||
/* quicklist is a 40 byte struct (on 64-bit systems) describing a quicklist.
|
/* quicklist is a 40 byte struct (on 64-bit systems) describing a quicklist.
|
||||||
|
10
src/rax.h
10
src/rax.h
@ -31,12 +31,6 @@
|
|||||||
#ifndef RAX_H
|
#ifndef RAX_H
|
||||||
#define RAX_H
|
#define RAX_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#define ZERO_LENGTH_ARRAY_LENGTH 1
|
|
||||||
#else
|
|
||||||
#define ZERO_LENGTH_ARRAY_LENGTH
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/* Representation of a radix tree as implemented in this file, that contains
|
/* Representation of a radix tree as implemented in this file, that contains
|
||||||
@ -133,7 +127,9 @@ typedef struct raxNode {
|
|||||||
* children, an additional value pointer is present (as you can see
|
* children, an additional value pointer is present (as you can see
|
||||||
* in the representation above as "value-ptr" field).
|
* in the representation above as "value-ptr" field).
|
||||||
*/
|
*/
|
||||||
unsigned char data[ZERO_LENGTH_ARRAY_LENGTH];
|
#ifndef __cplusplus
|
||||||
|
unsigned char data[];
|
||||||
|
#endif
|
||||||
} raxNode;
|
} raxNode;
|
||||||
|
|
||||||
typedef struct rax {
|
typedef struct rax {
|
||||||
|
@ -2236,7 +2236,7 @@ void replicationResurrectCachedMaster(int newfd) {
|
|||||||
|
|
||||||
/* Re-add to the list of clients. */
|
/* Re-add to the list of clients. */
|
||||||
linkClient(server.master);
|
linkClient(server.master);
|
||||||
if (aeCreateFileEvent(server.rgel[IDX_EVENT_LOOP_MAIN], newfd, AE_READABLE,
|
if (aeCreateFileEvent(server.rgel[IDX_EVENT_LOOP_MAIN], newfd, AE_READABLE|AE_READ_THREADSAFE,
|
||||||
readQueryFromClient, server.master)) {
|
readQueryFromClient, server.master)) {
|
||||||
serverLog(LL_WARNING,"Error resurrecting the cached master, impossible to add the readable handler: %s", strerror(errno));
|
serverLog(LL_WARNING,"Error resurrecting the cached master, impossible to add the readable handler: %s", strerror(errno));
|
||||||
freeClientAsync(server.master); /* Close ASAP. */
|
freeClientAsync(server.master); /* Close ASAP. */
|
||||||
|
26
src/sds.h
26
src/sds.h
@ -40,43 +40,47 @@ extern const char *SDS_NOINIT;
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#define ZERO_LENGTH_ARRAY_LENGTH 1
|
|
||||||
#else
|
|
||||||
#define ZERO_LENGTH_ARRAY_LENGTH
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef char *sds;
|
typedef char *sds;
|
||||||
|
|
||||||
/* Note: sdshdr5 is never used, we just access the flags byte directly.
|
/* Note: sdshdr5 is never used, we just access the flags byte directly.
|
||||||
* However is here to document the layout of type 5 SDS strings. */
|
* However is here to document the layout of type 5 SDS strings. */
|
||||||
struct __attribute__ ((__packed__)) sdshdr5 {
|
struct __attribute__ ((__packed__)) sdshdr5 {
|
||||||
unsigned char flags; /* 3 lsb of type, and 5 msb of string length */
|
unsigned char flags; /* 3 lsb of type, and 5 msb of string length */
|
||||||
char buf[ZERO_LENGTH_ARRAY_LENGTH];
|
#ifndef __cplusplus
|
||||||
|
char buf[];
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
struct __attribute__ ((__packed__)) sdshdr8 {
|
struct __attribute__ ((__packed__)) sdshdr8 {
|
||||||
uint8_t len; /* used */
|
uint8_t len; /* used */
|
||||||
uint8_t alloc; /* excluding the header and null terminator */
|
uint8_t alloc; /* excluding the header and null terminator */
|
||||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||||
char buf[ZERO_LENGTH_ARRAY_LENGTH];
|
#ifndef __cplusplus
|
||||||
|
char buf[];
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
struct __attribute__ ((__packed__)) sdshdr16 {
|
struct __attribute__ ((__packed__)) sdshdr16 {
|
||||||
uint16_t len; /* used */
|
uint16_t len; /* used */
|
||||||
uint16_t alloc; /* excluding the header and null terminator */
|
uint16_t alloc; /* excluding the header and null terminator */
|
||||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||||
char buf[ZERO_LENGTH_ARRAY_LENGTH];
|
#ifndef __cplusplus
|
||||||
|
char buf[];
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
struct __attribute__ ((__packed__)) sdshdr32 {
|
struct __attribute__ ((__packed__)) sdshdr32 {
|
||||||
uint32_t len; /* used */
|
uint32_t len; /* used */
|
||||||
uint32_t alloc; /* excluding the header and null terminator */
|
uint32_t alloc; /* excluding the header and null terminator */
|
||||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||||
char buf[ZERO_LENGTH_ARRAY_LENGTH];
|
#ifndef __cplusplus
|
||||||
|
char buf[];
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
struct __attribute__ ((__packed__)) sdshdr64 {
|
struct __attribute__ ((__packed__)) sdshdr64 {
|
||||||
uint64_t len; /* used */
|
uint64_t len; /* used */
|
||||||
uint64_t alloc; /* excluding the header and null terminator */
|
uint64_t alloc; /* excluding the header and null terminator */
|
||||||
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
unsigned char flags; /* 3 lsb of type, 5 unused bits */
|
||||||
char buf[ZERO_LENGTH_ARRAY_LENGTH];
|
#ifndef __cplusplus
|
||||||
|
char buf[];
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SDS_TYPE_5 0
|
#define SDS_TYPE_5 0
|
||||||
|
17
src/server.h
17
src/server.h
@ -663,7 +663,14 @@ struct evictionPoolEntry; /* Defined in evict.c */
|
|||||||
* which is actually a linked list of blocks like that, that is: client->reply. */
|
* which is actually a linked list of blocks like that, that is: client->reply. */
|
||||||
typedef struct clientReplyBlock {
|
typedef struct clientReplyBlock {
|
||||||
size_t size, used;
|
size_t size, used;
|
||||||
char buf[ZERO_LENGTH_ARRAY_LENGTH];
|
#ifndef __cplusplus
|
||||||
|
char buf[];
|
||||||
|
#else
|
||||||
|
__attribute__((always_inline)) char *buf()
|
||||||
|
{
|
||||||
|
return reinterpret_cast<char*>(this+1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
} clientReplyBlock;
|
} clientReplyBlock;
|
||||||
|
|
||||||
/* Redis database representation. There are multiple databases identified
|
/* Redis database representation. There are multiple databases identified
|
||||||
@ -884,10 +891,12 @@ typedef struct zskiplistNode {
|
|||||||
sds ele;
|
sds ele;
|
||||||
double score;
|
double score;
|
||||||
struct zskiplistNode *backward;
|
struct zskiplistNode *backward;
|
||||||
|
#ifndef __cplusplus
|
||||||
struct zskiplistLevel {
|
struct zskiplistLevel {
|
||||||
struct zskiplistNode *forward;
|
struct zskiplistNode *forward;
|
||||||
unsigned long span;
|
unsigned long span;
|
||||||
} level[ZERO_LENGTH_ARRAY_LENGTH];
|
} level[];
|
||||||
|
#endif
|
||||||
} zskiplistNode;
|
} zskiplistNode;
|
||||||
|
|
||||||
typedef struct zskiplist {
|
typedef struct zskiplist {
|
||||||
@ -1575,8 +1584,8 @@ unsigned long getClientOutputBufferMemoryUsage(client *c);
|
|||||||
void freeClientsInAsyncFreeQueue(void);
|
void freeClientsInAsyncFreeQueue(void);
|
||||||
void asyncCloseClientOnOutputBufferLimitReached(client *c);
|
void asyncCloseClientOnOutputBufferLimitReached(client *c);
|
||||||
int getClientType(client *c);
|
int getClientType(client *c);
|
||||||
int getClientTypeByName(char *name);
|
int getClientTypeByName(const char *name);
|
||||||
char *getClientTypeName(int cclass);
|
const char *getClientTypeName(int cclass);
|
||||||
void flushSlavesOutputBuffers(void);
|
void flushSlavesOutputBuffers(void);
|
||||||
void disconnectSlaves(void);
|
void disconnectSlaves(void);
|
||||||
int listenToPort(int port, int *fds, int *count);
|
int listenToPort(int port, int *fds, int *count);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user