make networking.c a C++ file

This commit is contained in:
John Sully 2019-02-15 14:11:34 -05:00
parent f5caec488d
commit 62090d0a97
12 changed files with 53 additions and 2486 deletions

View File

@ -27,7 +27,7 @@ ifneq (,$(findstring FreeBSD,$(uname_S)))
STD+=-Wno-c11-extensions
endif
endif
WARN=-Wall -Werror -W -Wno-missing-field-initializers
WARN=-Wall -Wextra -Werror -W -Wno-missing-field-initializers
OPT=$(OPTIMIZATION)
PREFIX?=/usr/local

View File

@ -473,7 +473,7 @@ extern "C" void ProcessEventCore(aeEventLoop *eventLoop, aeFileEvent *fe, int ma
* inverted. */
if (!invert && fe->mask & mask & AE_READABLE) {
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++;
}
@ -481,7 +481,7 @@ extern "C" void ProcessEventCore(aeEventLoop *eventLoop, aeFileEvent *fe, int ma
if (fe->mask & mask & AE_WRITABLE) {
if (!fired || fe->wfileProc != fe->rfileProc) {
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++;
}
}
@ -491,7 +491,7 @@ extern "C" void ProcessEventCore(aeEventLoop *eventLoop, aeFileEvent *fe, int ma
if (invert && fe->mask & mask & AE_READABLE) {
if (!fired || fe->wfileProc != fe->rfileProc) {
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++;
}
}

View File

@ -2022,7 +2022,7 @@ void rewriteConfigClientoutputbufferlimitOption(struct rewriteConfigState *state
rewriteConfigFormatMemory(soft,sizeof(soft),
server.client_obuf_limits[j].soft_limit_bytes);
char *typename = getClientTypeName(j);
const char *typename = getClientTypeName(j);
if (!strcmp(typename,"slave")) typename = "replica";
line = sdscatprintf(sdsempty(),"%s %s %s %s %ld",
option, typename, hard, soft,

View File

@ -30,13 +30,11 @@
#ifndef _REDIS_FMACRO_H
#define _REDIS_FMACRO_H
#define _BSD_SOURCE
#define _DEFAULT_SOURCE 1
#if defined(__linux__)
#ifndef __cplusplus
#define _GNU_SOURCE
#define _DEFAULT_SOURCE
#endif
#define _GNU_SOURCE 1
#define _DEFAULT_SOURCE 1
#endif
#if defined(_AIX)

View File

@ -32,16 +32,12 @@
#define __INTSET_H
#include <stdint.h>
#ifdef __cplusplus
#define ZERO_LENGTH_ARRAY_LENGTH 1
#else
#define ZERO_LENGTH_ARRAY_LENGTH
#endif
typedef struct intset {
uint32_t encoding;
uint32_t length;
int8_t contents[ZERO_LENGTH_ARRAY_LENGTH];
#ifndef __cplusplus
int8_t contents[];
#endif
} intset;
intset *intsetNew(void);

File diff suppressed because it is too large Load Diff

View File

@ -276,7 +276,7 @@ void _addReplyProtoToList(client *c, const char *s, size_t len) {
* new node */
size_t avail = tail->size - tail->used;
size_t copy = avail >= len? len: avail;
memcpy(tail->buf + tail->used, s, copy);
memcpy(tail->buf() + tail->used, s, copy);
tail->used += copy;
s += copy;
len -= copy;
@ -289,7 +289,7 @@ void _addReplyProtoToList(client *c, const char *s, size_t len) {
/* take over the allocation's internal fragmentation */
tail->size = zmalloc_usable(tail) - sizeof(clientReplyBlock);
tail->used = len;
memcpy(tail->buf, s, len);
memcpy(tail->buf(), s, len);
listAddNodeTail(c->reply, tail);
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)) &&
next->size - next->used >= lenstr_len &&
next->used < PROTO_REPLY_CHUNK_BYTES * 4) {
memmove(next->buf + lenstr_len, next->buf, next->used);
memcpy(next->buf, lenstr, lenstr_len);
memmove(next->buf() + lenstr_len, next->buf(), next->used);
memcpy(next->buf(), lenstr, lenstr_len);
next->used += lenstr_len;
listDelNode(c->reply,ln);
} else {
@ -468,7 +468,7 @@ void setDeferredAggregateLen(client *c, void *node, long length, char prefix) {
/* Take over the allocation's internal fragmentation */
buf->size = zmalloc_usable(buf) - sizeof(clientReplyBlock);
buf->used = lenstr_len;
memcpy(buf->buf, lenstr, lenstr_len);
memcpy(buf->buf(), lenstr, lenstr_len);
listNodeValue(ln) = buf;
c->reply_bytes += buf->size;
}
@ -1126,7 +1126,7 @@ int writeToClient(int fd, client *c, int handler_installed) {
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;
c->sentlen += nwritten;
@ -1646,6 +1646,7 @@ void readQueryFromClient(aeEventLoop *el, int fd, void *privdata, int mask) {
size_t qblen;
UNUSED(el);
UNUSED(mask);
serverAssert(mask & AE_READ_THREADSAFE);
readlen = PROTO_IOBUF_LEN;
/* If this is a multi bulk request, and we are processing a bulk reply

View File

@ -31,12 +31,6 @@
#ifndef __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. */
/* 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 */
typedef struct quicklistLZF {
unsigned int sz; /* LZF size in bytes*/
char compressed[ZERO_LENGTH_ARRAY_LENGTH];
#ifndef __cplusplus
char compressed[];
#endif
} quicklistLZF;
/* quicklist is a 40 byte struct (on 64-bit systems) describing a quicklist.

View File

@ -31,12 +31,6 @@
#ifndef RAX_H
#define RAX_H
#ifdef __cplusplus
#define ZERO_LENGTH_ARRAY_LENGTH 1
#else
#define ZERO_LENGTH_ARRAY_LENGTH
#endif
#include <stdint.h>
/* 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
* in the representation above as "value-ptr" field).
*/
unsigned char data[ZERO_LENGTH_ARRAY_LENGTH];
#ifndef __cplusplus
unsigned char data[];
#endif
} raxNode;
typedef struct rax {

View File

@ -2236,7 +2236,7 @@ void replicationResurrectCachedMaster(int newfd) {
/* Re-add to the list of clients. */
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)) {
serverLog(LL_WARNING,"Error resurrecting the cached master, impossible to add the readable handler: %s", strerror(errno));
freeClientAsync(server.master); /* Close ASAP. */

View File

@ -40,43 +40,47 @@ extern const char *SDS_NOINIT;
#include <stdarg.h>
#include <stdint.h>
#ifdef __cplusplus
#define ZERO_LENGTH_ARRAY_LENGTH 1
#else
#define ZERO_LENGTH_ARRAY_LENGTH
#endif
typedef char *sds;
/* Note: sdshdr5 is never used, we just access the flags byte directly.
* However is here to document the layout of type 5 SDS strings. */
struct __attribute__ ((__packed__)) sdshdr5 {
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 {
uint8_t len; /* used */
uint8_t alloc; /* excluding the header and null terminator */
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 {
uint16_t len; /* used */
uint16_t alloc; /* excluding the header and null terminator */
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 {
uint32_t len; /* used */
uint32_t alloc; /* excluding the header and null terminator */
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 {
uint64_t len; /* used */
uint64_t alloc; /* excluding the header and null terminator */
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

View File

@ -663,7 +663,14 @@ struct evictionPoolEntry; /* Defined in evict.c */
* which is actually a linked list of blocks like that, that is: client->reply. */
typedef struct clientReplyBlock {
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;
/* Redis database representation. There are multiple databases identified
@ -884,10 +891,12 @@ typedef struct zskiplistNode {
sds ele;
double score;
struct zskiplistNode *backward;
#ifndef __cplusplus
struct zskiplistLevel {
struct zskiplistNode *forward;
unsigned long span;
} level[ZERO_LENGTH_ARRAY_LENGTH];
} level[];
#endif
} zskiplistNode;
typedef struct zskiplist {
@ -1575,8 +1584,8 @@ unsigned long getClientOutputBufferMemoryUsage(client *c);
void freeClientsInAsyncFreeQueue(void);
void asyncCloseClientOnOutputBufferLimitReached(client *c);
int getClientType(client *c);
int getClientTypeByName(char *name);
char *getClientTypeName(int cclass);
int getClientTypeByName(const char *name);
const char *getClientTypeName(int cclass);
void flushSlavesOutputBuffers(void);
void disconnectSlaves(void);
int listenToPort(int port, int *fds, int *count);