Windows compatibility (#57)

* Add Python and Redis submodules, and remove old third-party modules

* Update VS projects (WARNING: references files that do not exist yet)

* Update code & add shims for APIs except AF_UNIX/{send,recv}msg()

* Minor style changes.
This commit is contained in:
mehrdadn
2016-11-22 17:04:24 -08:00
committed by Robert Nishihara
parent a93c6b7596
commit 7237ec4124
65 changed files with 2233 additions and 7126 deletions
+2 -1
View File
@@ -15,7 +15,8 @@ const unique_id NIL_ID = {{255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
unique_id globally_unique_id(void) {
/* Use /dev/urandom for "real" randomness. */
int fd;
if ((fd = open("/dev/urandom", O_RDONLY)) == -1) {
int const flags = 0 /* for Windows compatibility */;
if ((fd = open("/dev/urandom", O_RDONLY, flags)) == -1) {
LOG_ERROR("Could not generate random number");
}
unique_id result;
+10 -1
View File
@@ -7,7 +7,9 @@
#include <string.h>
#include <errno.h>
#include <inttypes.h>
#ifndef _WIN32
#include <execinfo.h>
#endif
#include "utarray.h"
@@ -53,7 +55,7 @@
#if (RAY_COMMON_LOG_LEVEL > RAY_COMMON_FATAL)
#define LOG_FATAL(M, ...)
#else
#elif defined(_EXECINFO_H) || !defined(_WIN32)
#define LOG_FATAL(M, ...) \
do { \
fprintf(stderr, "[FATAL] (%s:%d) " M "\n", __FILE__, __LINE__, \
@@ -63,6 +65,13 @@
backtrace_symbols_fd(buffer, calls, 1); \
exit(-1); \
} while (0);
#else
#define LOG_FATAL(M, ...) \
do { \
fprintf(stderr, "[FATAL] (%s:%d) " M "\n", __FILE__, __LINE__, \
##__VA_ARGS__); \
exit(-1); \
} while (0);
#endif
#define CHECKM(COND, M, ...) \
+7
View File
@@ -2,7 +2,14 @@
#define EVENT_LOOP_H
#include <stdint.h>
#ifdef _WIN32
/* Quirks mean that Windows version needs to be included differently */
#include <hiredis/hiredis.h>
#include <ae.h>
#else
#include "ae/ae.h"
#endif
/* Unique timer ID that will be generated when the timer is added to the
* event loop. Will not be reused later on in another call
+2 -1
View File
@@ -46,7 +46,8 @@ int bind_inet_sock(const int port, bool shall_listen) {
close(socket_fd);
return -1;
}
if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0) {
int *const pon = (char const *) &on;
if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, pon, sizeof(on)) < 0) {
LOG_ERROR("setsockopt failed for port %d", port);
close(socket_fd);
return -1;
+1 -1
View File
@@ -99,7 +99,7 @@ static long PyObjectID_hash(PyObjectID *self) {
}
static PyObject *PyObjectID_repr(PyObjectID *self) {
int hex_length = 2 * UNIQUE_ID_SIZE + 1;
enum { hex_length = 2 * UNIQUE_ID_SIZE + 1 };
char hex_id[hex_length];
sha1_to_hex(self->object_id.id, hex_id);
UT_string *repr;
+3 -1
View File
@@ -1,7 +1,9 @@
#include "logging.h"
#include <stdint.h>
#include <inttypes.h>
#include <stdint.h>
#include <sys/time.h>
#include <hiredis/hiredis.h>
#include <utstring.h>
+69
View File
@@ -0,0 +1,69 @@
/* http://stackoverflow.com/a/17195644/541686 */
#include <string.h>
#include <stdio.h>
int opterr = 1, /* if error message should be printed */
optind = 1, /* index into parent argv vector */
optopt, /* character checked for validity */
optreset; /* reset getopt */
char *optarg; /* argument associated with option */
#define BADCH (int) '?'
#define BADARG (int) ':'
#define EMSG ""
/*
* getopt --
* Parse argc/argv argument vector.
*/
int getopt(int nargc, char *const nargv[], const char *ostr) {
static char *place = EMSG; /* option letter processing */
const char *oli; /* option letter list index */
if (optreset || !*place) { /* update scanning pointer */
optreset = 0;
if (optind >= nargc || *(place = nargv[optind]) != '-') {
place = EMSG;
return (-1);
}
if (place[1] && *++place == '-') { /* found "--" */
++optind;
place = EMSG;
return (-1);
}
} /* option letter okay? */
if ((optopt = (int) *place++) == (int) ':' || !(oli = strchr(ostr, optopt))) {
/*
* if the user didn't specify '-' as an option,
* assume it means -1.
*/
if (optopt == (int) '-')
return (-1);
if (!*place)
++optind;
if (opterr && *ostr != ':')
(void) printf("illegal option -- %c\n", optopt);
return (BADCH);
}
if (*++oli != ':') { /* don't need argument */
optarg = NULL;
if (!*place)
++optind;
} else { /* need an argument */
if (*place) /* no white space */
optarg = place;
else if (nargc <= ++optind) { /* no arg */
place = EMSG;
if (*ostr == ':')
return (BADARG);
if (opterr)
(void) printf("option requires an argument -- %c\n", optopt);
return (BADCH);
} else /* white space */
optarg = nargv[optind];
place = EMSG;
++optind;
}
return (optopt); /* dump back option letter */
}
+4
View File
@@ -0,0 +1,4 @@
#ifndef GETOPT_H
#define GETOPT_H
#endif /* GETOPT_H */
+208
View File
@@ -0,0 +1,208 @@
#include <sys/socket.h>
int socketpair(int domain, int type, int protocol, int sv[2]) {
if ((domain != AF_UNIX && domain != AF_INET) || type != SOCK_STREAM) {
return INVALID_SOCKET;
}
SOCKET sockets[2];
int r = dumb_socketpair(sockets);
sv[0] = (int) sockets[0];
sv[1] = (int) sockets[1];
return r;
}
#pragma comment(lib, "IPHlpAPI.lib")
struct _MIB_TCPROW2 {
DWORD dwState, dwLocalAddr, dwLocalPort, dwRemoteAddr, dwRemotePort,
dwOwningPid;
enum _TCP_CONNECTION_OFFLOAD_STATE dwOffloadState;
};
struct _MIB_TCPTABLE2 {
DWORD dwNumEntries;
struct _MIB_TCPROW2 table[1];
};
DECLSPEC_IMPORT ULONG WINAPI GetTcpTable2(struct _MIB_TCPTABLE2 *TcpTable,
PULONG SizePointer,
BOOL Order);
static DWORD getsockpid(SOCKET client) {
/* http://stackoverflow.com/a/25431340 */
DWORD pid = 0;
struct sockaddr_in Server = {0};
int ServerSize = sizeof(Server);
struct sockaddr_in Client = {0};
int ClientSize = sizeof(Client);
if ((getsockname(client, (struct sockaddr *) &Server, &ServerSize) == 0) &&
(getpeername(client, (struct sockaddr *) &Client, &ClientSize) == 0)) {
struct _MIB_TCPTABLE2 *TcpTable = NULL;
ULONG TcpTableSize = 0;
ULONG result;
do {
result = GetTcpTable2(TcpTable, &TcpTableSize, TRUE);
if (result != ERROR_INSUFFICIENT_BUFFER) {
break;
}
free(TcpTable);
TcpTable = (struct _MIB_TCPTABLE2 *) malloc(TcpTableSize);
} while (TcpTable != NULL);
if (result == NO_ERROR) {
for (DWORD dw = 0; dw < TcpTable->dwNumEntries; ++dw) {
struct _MIB_TCPROW2 *row = &(TcpTable->table[dw]);
if ((row->dwState == 5 /* MIB_TCP_STATE_ESTAB */) &&
(row->dwLocalAddr == Client.sin_addr.s_addr) &&
((row->dwLocalPort & 0xFFFF) == Client.sin_port) &&
(row->dwRemoteAddr == Server.sin_addr.s_addr) &&
((row->dwRemotePort & 0xFFFF) == Server.sin_port)) {
pid = row->dwOwningPid;
break;
}
}
}
free(TcpTable);
}
return pid;
}
ssize_t sendmsg(int sockfd, struct msghdr *msg, int flags) {
ssize_t result = -1;
struct cmsghdr *header = CMSG_FIRSTHDR(msg);
if (header->cmsg_level == SOL_SOCKET && header->cmsg_type == SCM_RIGHTS) {
/* We're trying to send over a handle of some kind.
* We have to look up which process we're communicating with,
* open a handle to it, and then duplicate our handle into it.
* However, the first two steps cannot be done atomically.
* Therefore, this code HAS A RACE CONDITIONS and is therefore NOT SECURE.
* In the absense of a malicious actor, though, it is exceedingly unlikely
* that the child process closes AND that its process ID is reassigned
* to another existing process.
*/
struct msghdr const old_msg = *msg;
int *const pfd = (int *) CMSG_DATA(header);
msg->msg_control = NULL;
msg->msg_controllen = 0;
WSAPROTOCOL_INFO protocol_info = {0};
BOOL const is_socket = !!FDAPI_GetSocketStatePtr(*pfd);
DWORD const target_pid = getsockpid(sockfd);
HANDLE target_process = NULL;
if (target_pid) {
if (!is_socket) {
/* This is a regular handle... fit it into the same struct */
target_process = OpenProcess(PROCESS_DUP_HANDLE, FALSE, target_pid);
if (target_process) {
if (DuplicateHandle(GetCurrentProcess(), (HANDLE)(intptr_t) *pfd,
target_process, (HANDLE *) &protocol_info, 0,
TRUE, DUPLICATE_SAME_ACCESS)) {
result = 0;
}
}
} else {
/* This is a socket... */
result = FDAPI_WSADuplicateSocket(*pfd, target_pid, &protocol_info);
}
}
if (result == 0) {
int const nbufs = msg->dwBufferCount + 1;
WSABUF *const bufs =
(struct _WSABUF *) _alloca(sizeof(*msg->lpBuffers) * nbufs);
bufs[0].buf = (char *) &protocol_info;
bufs[0].len = sizeof(protocol_info);
memcpy(&bufs[1], msg->lpBuffers,
msg->dwBufferCount * sizeof(*msg->lpBuffers));
DWORD nb;
msg->lpBuffers = bufs;
msg->dwBufferCount = nbufs;
GUID const wsaid_WSASendMsg = {
0xa441e712,
0x754f,
0x43ca,
{0x84, 0xa7, 0x0d, 0xee, 0x44, 0xcf, 0x60, 0x6d}};
typedef INT PASCAL WSASendMsg_t(
SOCKET s, LPWSAMSG lpMsg, DWORD dwFlags, LPDWORD lpNumberOfBytesSent,
LPWSAOVERLAPPED lpOverlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine);
WSASendMsg_t *WSASendMsg = NULL;
result = FDAPI_WSAIoctl(sockfd, SIO_GET_EXTENSION_FUNCTION_POINTER,
&wsaid_WSASendMsg, sizeof(wsaid_WSASendMsg),
&WSASendMsg, sizeof(WSASendMsg), &nb, NULL, 0);
if (result == 0) {
result = (*WSASendMsg)(sockfd, msg, flags, &nb, NULL, NULL) == 0
? (ssize_t)(nb - sizeof(protocol_info))
: 0;
}
}
if (result != 0 && target_process && !is_socket) {
/* we failed to send the handle, and it needs cleaning up! */
HANDLE duplicated_back = NULL;
if (DuplicateHandle(target_process, *(HANDLE *) &protocol_info,
GetCurrentProcess(), &duplicated_back, 0, FALSE,
DUPLICATE_CLOSE_SOURCE)) {
CloseHandle(duplicated_back);
}
}
if (target_process) {
CloseHandle(target_process);
}
*msg = old_msg;
}
return result;
}
ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags) {
int result = -1;
struct cmsghdr *header = CMSG_FIRSTHDR(msg);
if (msg->msg_controllen &&
flags == 0 /* We can't send flags on Windows... */) {
struct msghdr const old_msg = *msg;
msg->msg_control = NULL;
msg->msg_controllen = 0;
WSAPROTOCOL_INFO protocol_info = {0};
int const nbufs = msg->dwBufferCount + 1;
WSABUF *const bufs =
(struct _WSABUF *) _alloca(sizeof(*msg->lpBuffers) * nbufs);
bufs[0].buf = (char *) &protocol_info;
bufs[0].len = sizeof(protocol_info);
memcpy(&bufs[1], msg->lpBuffers,
msg->dwBufferCount * sizeof(*msg->lpBuffers));
typedef INT PASCAL WSARecvMsg_t(
SOCKET s, LPWSAMSG lpMsg, LPDWORD lpNumberOfBytesRecvd,
LPWSAOVERLAPPED lpOverlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine);
WSARecvMsg_t *WSARecvMsg = NULL;
DWORD nb;
GUID const wsaid_WSARecvMsg = {
0xf689d7c8,
0x6f1f,
0x436b,
{0x8a, 0x53, 0xe5, 0x4f, 0xe3, 0x51, 0xc3, 0x22}};
result = FDAPI_WSAIoctl(sockfd, SIO_GET_EXTENSION_FUNCTION_POINTER,
&wsaid_WSARecvMsg, sizeof(wsaid_WSARecvMsg),
&WSARecvMsg, sizeof(WSARecvMsg), &nb, NULL, 0);
if (result == 0) {
result = (*WSARecvMsg)(sockfd, msg, &nb, NULL, NULL) == 0
? (ssize_t)(nb - sizeof(protocol_info))
: 0;
}
if (result == 0) {
int *const pfd = (int *) CMSG_DATA(header);
if (protocol_info.iSocketType == 0 && protocol_info.iProtocol == 0) {
*pfd = *(int *) &protocol_info;
} else {
*pfd = FDAPI_WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO,
FROM_PROTOCOL_INFO, &protocol_info, 0, 0);
}
header->cmsg_level = SOL_SOCKET;
header->cmsg_type = SCM_RIGHTS;
}
*msg = old_msg;
}
return result;
}
+4
View File
@@ -0,0 +1,4 @@
#ifndef NETDB_H
#define NETDB_H
#endif /* NETDB_H */
+4
View File
@@ -0,0 +1,4 @@
#ifndef IN_H
#define IN_H
#endif /* IN_H */
+4
View File
@@ -0,0 +1,4 @@
#ifndef POLL_H
#define POLL_H
#endif /* POLL_H */
+150
View File
@@ -0,0 +1,150 @@
/* socketpair.c
Copyright 2007, 2010 by Nathan C. Myers <ncm@cantrip.org>
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
The name of the author must not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* Changes:
* 2014-02-12: merge David Woodhouse, Ger Hobbelt improvements
* git.infradead.org/users/dwmw2/openconnect.git/commitdiff/bdeefa54
* github.com/GerHobbelt/selectable-socketpair
* always init the socks[] to -1/INVALID_SOCKET on error, both on Win32/64
* and UNIX/other platforms
* 2013-07-18: Change to BSD 3-clause license
* 2010-03-31:
* set addr to 127.0.0.1 because win32 getsockname does not always set it.
* 2010-02-25:
* set SO_REUSEADDR option to avoid leaking some windows resource.
* Windows System Error 10049, "Event ID 4226 TCP/IP has reached
* the security limit imposed on the number of concurrent TCP connect
* attempts." Bleah.
* 2007-04-25:
* preserve value of WSAGetLastError() on all error returns.
* 2007-04-22: (Thanks to Matthew Gregan <kinetik@flim.org>)
* s/EINVAL/WSAEINVAL/ fix trivial compile failure
* s/socket/WSASocket/ enable creation of sockets suitable as stdin/stdout
* of a child process.
* add argument make_overlapped
*/
#include <string.h>
#ifdef WIN32
#include <ws2tcpip.h> /* socklen_t, et al (MSVC20xx) */
#include <windows.h>
#include <io.h>
#else
#ifdef _WIN32
#include <Win32_Interop/win32_types.h>
#include <Win32_Interop/Win32_FDAPI.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <errno.h>
#endif
#ifdef WIN32
/* dumb_socketpair:
* If make_overlapped is nonzero, both sockets created will be usable for
* "overlapped" operations via WSASend etc. If make_overlapped is zero,
* socks[0] (only) will be usable with regular ReadFile etc., and thus
* suitable for use as stdin or stdout of a child process. Note that the
* sockets must be closed with closesocket() regardless.
*/
int dumb_socketpair(SOCKET socks[2]) {
union {
struct sockaddr_in inaddr;
struct sockaddr addr;
} a;
SOCKET listener;
int e;
socklen_t addrlen = sizeof(a.inaddr);
int reuse = 1;
if (socks == 0) {
return SOCKET_ERROR;
}
socks[0] = socks[1] = -1;
listener = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (listener == -1)
return SOCKET_ERROR;
memset(&a, 0, sizeof(a));
a.inaddr.sin_family = AF_INET;
a.inaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
a.inaddr.sin_port = 0;
for (;;) {
if (setsockopt(listener, SOL_SOCKET, SO_REUSEADDR, (char *) &reuse,
(socklen_t) sizeof(reuse)) == -1)
break;
if (bind(listener, &a.addr, sizeof(a.inaddr)) == SOCKET_ERROR)
break;
memset(&a, 0, sizeof(a));
if (getsockname(listener, &a.addr, &addrlen) == SOCKET_ERROR)
break;
// win32 getsockname may only set the port number, p=0.0005.
// ( http://msdn.microsoft.com/library/ms738543.aspx ):
a.inaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
a.inaddr.sin_family = AF_INET;
if (listen(listener, 1) == SOCKET_ERROR)
break;
socks[0] = FDAPI_WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0, 0);
if (socks[0] == -1)
break;
if (connect(socks[0], &a.addr, sizeof(a.inaddr)) == SOCKET_ERROR)
break;
socks[1] = accept(listener, NULL, NULL);
if (socks[1] == -1)
break;
FDAPI_close(listener);
return 0;
}
FDAPI_close(listener);
FDAPI_close(socks[0]);
FDAPI_close(socks[1]);
socks[0] = socks[1] = -1;
return SOCKET_ERROR;
}
#else
int dumb_socketpair(int socks[2], int dummy) {
if (socks == 0) {
errno = EINVAL;
return -1;
}
dummy = socketpair(AF_LOCAL, SOCK_STREAM, 0, socks);
if (dummy)
socks[0] = socks[1] = -1;
return dummy;
}
#endif
+4
View File
@@ -0,0 +1,4 @@
#ifndef STRINGS_H
#define STRINGS_H
#endif /* STRINGS_H */
+4
View File
@@ -0,0 +1,4 @@
#ifndef IOCTL_H
#define IOCTL_H
#endif /* IOCTL_H */
+36
View File
@@ -0,0 +1,36 @@
#ifndef MMAN_H
#define MMAN_H
#include <unistd.h>
#define MAP_SHARED 0x0010 /* share changes */
#define MAP_FAILED ((void *) -1)
#define PROT_READ 0x04 /* pages can be read */
#define PROT_WRITE 0x02 /* pages can be written */
#define PROT_EXEC 0x01 /* pages can be executed */
static void *mmap(void *addr,
size_t len,
int prot,
int flags,
int fd,
off_t off) {
void *result = (void *) (-1);
if (!addr && prot == MAP_SHARED) {
/* HACK: we're assuming handle sizes can't exceed 32 bits, which is wrong...
* but works for now. */
void *ptr = MapViewOfFile((HANDLE)(intptr_t) fd, FILE_MAP_ALL_ACCESS,
(DWORD)(off >> (CHAR_BIT * sizeof(DWORD))),
(DWORD) off, (SIZE_T) len);
if (ptr) {
result = ptr;
}
}
return result;
}
static int munmap(void *addr, size_t length) {
(void) length;
return UnmapViewOfFile(addr) ? 0 : -1;
}
#endif /* MMAN_H */
+4
View File
@@ -0,0 +1,4 @@
#ifndef SELECT_H
#define SELECT_H
#endif /* SELECT_H */
+36
View File
@@ -0,0 +1,36 @@
#ifndef SOCKET_H
#define SOCKET_H
typedef unsigned short sa_family_t;
#include "../../src/Win32_Interop/Win32_FDAPI.h"
#include "../../src/Win32_Interop/Win32_APIs.h"
#define cmsghdr _WSACMSGHDR
#undef CMSG_DATA
#define CMSG_DATA WSA_CMSG_DATA
#define CMSG_SPACE WSA_CMSG_SPACE
#define CMSG_FIRSTHDR WSA_CMSG_FIRSTHDR
#define CMSG_LEN WSA_CMSG_LEN
#define CMSG_NXTHDR WSA_CMSG_NXTHDR
#define SCM_RIGHTS 1
#define iovec _WSABUF
#define iov_base buf
#define iov_len len
#define msghdr _WSAMSG
#define msg_name name
#define msg_namelen namelen
#define msg_iov lpBuffers
#define msg_iovlen dwBufferCount
#define msg_control Control.buf
#define msg_controllen Control.len
#define msg_flags dwFlags
int dumb_socketpair(SOCKET socks[2]);
ssize_t sendmsg(int sockfd, struct msghdr *msg, int flags);
ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags);
int socketpair(int domain, int type, int protocol, int sv[2]);
#endif /* SOCKET_H */
+12
View File
@@ -0,0 +1,12 @@
#ifndef TIME_H
#define TIME_H
#include <WinSock2.h> /* timeval */
int gettimeofday_highres(struct timeval *tv, struct timezone *tz);
static int gettimeofday(struct timeval *tv, struct timezone *tz) {
return gettimeofday_highres(tv, tz);
}
#endif /* TIME_H */
+13
View File
@@ -0,0 +1,13 @@
#ifndef UN_H
#define UN_H
#include <sys/socket.h>
struct sockaddr_un {
/** AF_UNIX. */
sa_family_t sun_family;
/** The pathname. */
char sun_path[108];
};
#endif /* UN_H */
+4
View File
@@ -0,0 +1,4 @@
#ifndef WAIT_H
#define WAIT_H
#endif /* WAIT_H */
+11
View File
@@ -0,0 +1,11 @@
#ifndef UNISTD_H
#define UNISTD_H
extern char *optarg;
extern int optind, opterr, optopt;
int getopt(int nargc, char *const nargv[], const char *ostr);
#include "../../src/Win32_Interop/Win32_FDAPI.h"
#define close(...) FDAPI_close(__VA_ARGS__)
#endif /* UNISTD_H */
+2
View File
@@ -4,6 +4,8 @@
#include <stdbool.h>
#include <stdlib.h>
/* Including hiredis here is necessary on Windows for typedefs used in ae.h. */
#include "hiredis/hiredis.h"
#include "hiredis/adapters/ae.h"
#include "utstring.h"
+1 -1
View File
@@ -114,7 +114,7 @@ task_id compute_task_id(task_spec *spec) {
object_id compute_return_id(task_id task_id, int64_t return_index) {
/* TODO(rkn): This line requires object and task IDs to be the same size. */
object_id return_id = (object_id) task_id;
object_id return_id = task_id;
int64_t *first_bytes = (int64_t *) &return_id;
/* XOR the first bytes of the object ID with the return index. We add one so
* the first return ID is not the same as the task ID. */
+1 -1
View File
@@ -201,7 +201,7 @@ TEST task_table_all_test(void) {
}
TEST unique_client_id_test(void) {
const int num_conns = 100;
enum { num_conns = 100 };
db_client_id ids[num_conns];
db_handle *db;
+4 -1
View File
@@ -10,6 +10,7 @@
SUITE(io_tests);
TEST ipc_socket_test(void) {
#ifndef _WIN32
const char *socket_pathname = "test-socket";
int socket_fd = bind_ipc_sock(socket_pathname, true);
ASSERT(socket_fd >= 0);
@@ -44,11 +45,12 @@ TEST ipc_socket_test(void) {
close(socket_fd);
unlink(socket_pathname);
}
#endif
PASS();
}
TEST long_ipc_socket_test(void) {
#ifndef _WIN32
const char *socket_pathname = "long-test-socket";
int socket_fd = bind_ipc_sock(socket_pathname, true);
ASSERT(socket_fd >= 0);
@@ -89,6 +91,7 @@ TEST long_ipc_socket_test(void) {
}
utstring_free(test_string);
#endif
PASS();
}
+3 -3
View File
@@ -5,7 +5,7 @@
#include "task.h"
task_spec *example_task_spec(void) {
static task_spec *example_task_spec(void) {
task_id parent_task_id = globally_unique_id();
function_id func_id = globally_unique_id();
task_spec *task =
@@ -16,7 +16,7 @@ task_spec *example_task_spec(void) {
return task;
}
task *example_task(void) {
static task *example_task(void) {
task_spec *spec = example_task_spec();
task *instance = alloc_task(spec, TASK_STATUS_WAITING, NIL_ID);
free_task_spec(spec);
@@ -24,7 +24,7 @@ task *example_task(void) {
}
/* Flush redis. */
void flushall_redis() {
static void flushall_redis() {
redisContext *context = redisConnect("127.0.0.1", 6379);
freeReplyObject(redisCommand(context, "FLUSHALL"));
redisFree(context);
+15
View File
@@ -0,0 +1,15 @@
@SetLocal
@Echo Off
@PushD "%~dp0"
git submodule update --init --jobs="%NUMBER_OF_PROCESSORS%"
@If Not Exist "python\.git" git clone "https://github.com/austinsc/python.git"
Call :GitApply "python" "%CD%/patches/windows/python-pyconfig.patch"
Call :GitApply "redis-windows" "%CD%/patches/windows/redis.patch"
@PopD
@EndLocal
@GoTo :EOF
:GitApply <ChangeToFolder> <Patch>
@REM Check if patch already applied by attempting to apply it in reverse; if not, then force-reapply it
git -C "%~1" apply "%~2" -R --check 2> NUL || git -C "%~1" apply "%~2" --3way 2> NUL || git -C "%~1" reset --hard && git -C "%~1" apply "%~2" --3way
@GoTo :EOF
@@ -0,0 +1 @@
*.patch text eol=lf
@@ -0,0 +1,25 @@
diff --git a/inc/Windows/pyconfig.h b/inc/Windows/pyconfig.h
index 1cfc59b..d4861cb
--- a/inc/Windows/pyconfig.h
+++ b/inc/Windows/pyconfig.h
@@ -1,6 +1,11 @@
#ifndef Py_CONFIG_H
#define Py_CONFIG_H
+#ifdef _MSC_VER
+#pragma push_macro("_DEBUG")
+#undef _DEBUG
+#endif
+
/* pyconfig.h. NOT Generated automatically by configure.
This is a manually maintained version used for the Watcom,
@@ -756,4 +761,8 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
least significant byte first */
#define DOUBLE_IS_LITTLE_ENDIAN_IEEE754 1
+#ifdef _MSC_VER
+#pragma pop_macro("_DEBUG")
+#endif
+
#endif /* !Py_CONFIG_H */
+772
View File
@@ -0,0 +1,772 @@
diff --git a/msvs/RedisServer.vcxproj b/msvs/RedisServer.vcxproj
index 115ce90..68afb44
--- a/msvs/RedisServer.vcxproj
+++ b/msvs/RedisServer.vcxproj
@@ -24,26 +24,26 @@
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
- <ConfigurationType>Application</ConfigurationType>
+ <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
- <PlatformToolset>v120</PlatformToolset>
+ <PlatformToolset>v140_xp</PlatformToolset>
<CLRSupport>false</CLRSupport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
- <ConfigurationType>Application</ConfigurationType>
+ <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
- <PlatformToolset>v120</PlatformToolset>
+ <PlatformToolset>v140_xp</PlatformToolset>
<CLRSupport>false</CLRSupport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
- <ConfigurationType>Application</ConfigurationType>
+ <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
- <PlatformToolset>v120</PlatformToolset>
+ <PlatformToolset>v140_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
- <ConfigurationType>Application</ConfigurationType>
+ <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
- <PlatformToolset>v120</PlatformToolset>
+ <PlatformToolset>v140_xp</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
@@ -61,41 +61,23 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <PropertyGroup>
<LinkIncremental>false</LinkIncremental>
<TargetName>redis-server</TargetName>
<GenerateManifest>false</GenerateManifest>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <LinkIncremental>false</LinkIncremental>
- <TargetName>redis-server</TargetName>
- <GenerateManifest>false</GenerateManifest>
- <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
- <IntDir>$(Platform)\$(Configuration)\</IntDir>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
- <LinkIncremental>false</LinkIncremental>
- <TargetName>redis-server</TargetName>
- <GenerateManifest>false</GenerateManifest>
- <CustomBuildAfterTargets>Build</CustomBuildAfterTargets>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <LinkIncremental>false</LinkIncremental>
- <TargetName>redis-server</TargetName>
- <GenerateManifest>false</GenerateManifest>
- <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
- <IntDir>$(Platform)\$(Configuration)\</IntDir>
+ <OutDir>$(SolutionDir)build\$(Platform)\$(Configuration)\</OutDir>
+ <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(MSBuildProjectName)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
- <PreprocessorDefinitions>USE_JEMALLOC;_OFF_T_DEFINED;WIN32;LACKS_STDLIB_H;_DEBUG;_CONSOLE;__x86_64__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <AdditionalIncludeDirectories>$(SolutionDir)..\deps\lua\src;$(SolutionDir)..\deps\hiredis;$(SolutionDir)..\deps\jemalloc-win\include</AdditionalIncludeDirectories>
- <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+ <PreprocessorDefinitions>_WIN32_WINNT=0x0502;_OFF_T_DEFINED;WIN32;LACKS_STDLIB_H;_DEBUG;_CONSOLE;__x86_64__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>$(ProjectDir)..\deps\lua\src;$(ProjectDir)..\deps\hiredis;$(ProjectDir)..\deps\jemalloc-win\include</AdditionalIncludeDirectories>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<DisableSpecificWarnings>4996;4146</DisableSpecificWarnings>
- <WholeProgramOptimization>true</WholeProgramOptimization>
+ <MinimalRebuild>false</MinimalRebuild>
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
@@ -109,14 +91,14 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
- <PreprocessorDefinitions>USE_JEMALLOC;_OFF_T_DEFINED;WIN32;LACKS_STDLIB_H;_DEBUG;_CONSOLE;__x86_64__;%(PreprocessorDefinitions);_WIN32_WINNT=0x0501</PreprocessorDefinitions>
- <AdditionalIncludeDirectories>$(SolutionDir)..\deps\lua\src;$(SolutionDir)..\deps\hiredis;$(SolutionDir)..\deps\jemalloc-win\include</AdditionalIncludeDirectories>
- <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+ <PreprocessorDefinitions>_WIN32_WINNT=0x0502;_OFF_T_DEFINED;WIN32;LACKS_STDLIB_H;_DEBUG;_CONSOLE;__x86_64__;%(PreprocessorDefinitions);_WIN32_WINNT=0x0501</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>$(ProjectDir)..\deps\lua\src;$(ProjectDir)..\deps\hiredis;$(ProjectDir)..\deps\jemalloc-win\include</AdditionalIncludeDirectories>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<DisableSpecificWarnings>4996;4146</DisableSpecificWarnings>
- <WholeProgramOptimization>true</WholeProgramOptimization>
+ <MinimalRebuild>false</MinimalRebuild>
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
@@ -130,14 +112,13 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
- <PreprocessorDefinitions>USE_JEMALLOC;_OFF_T_DEFINED;WIN32;LACKS_STDLIB_H;NDEBUG;_CONSOLE;__x86_64__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <AdditionalIncludeDirectories>$(SolutionDir)..\deps\lua\src;$(SolutionDir)..\deps\hiredis;$(SolutionDir)..\deps\jemalloc-win\include</AdditionalIncludeDirectories>
- <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <PreprocessorDefinitions>_WIN32_WINNT=0x0502;_OFF_T_DEFINED;WIN32;LACKS_STDLIB_H;NDEBUG;_CONSOLE;__x86_64__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>$(ProjectDir)..\deps\lua\src;$(ProjectDir)..\deps\hiredis;$(ProjectDir)..\deps\jemalloc-win\include</AdditionalIncludeDirectories>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<DisableSpecificWarnings>4996;4146</DisableSpecificWarnings>
- <WholeProgramOptimization>true</WholeProgramOptimization>
<Optimization>Full</Optimization>
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
@@ -162,13 +143,12 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
- <PreprocessorDefinitions>USE_JEMALLOC;_OFF_T_DEFINED;_WIN32;LACKS_STDLIB_H;NDEBUG;_CONSOLE;__x86_64__;%(PreprocessorDefinitions);_WIN32_WINNT=0x0501</PreprocessorDefinitions>
- <AdditionalIncludeDirectories>$(SolutionDir)..\deps\lua\src;$(SolutionDir)..\deps\hiredis;$(SolutionDir)..\deps\jemalloc-win\include</AdditionalIncludeDirectories>
- <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <PreprocessorDefinitions>_WIN32_WINNT=0x0502;_OFF_T_DEFINED;_WIN32;LACKS_STDLIB_H;NDEBUG;_CONSOLE;__x86_64__;%(PreprocessorDefinitions);_WIN32_WINNT=0x0501</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>$(ProjectDir)..\deps\lua\src;$(ProjectDir)..\deps\hiredis;$(ProjectDir)..\deps\jemalloc-win\include</AdditionalIncludeDirectories>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<DisableSpecificWarnings>4996;4146</DisableSpecificWarnings>
- <WholeProgramOptimization>true</WholeProgramOptimization>
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
@@ -271,9 +251,6 @@
<ClInclude Include="..\src\zmalloc.h" />
</ItemGroup>
<ItemGroup>
- <ProjectReference Include="..\deps\jemalloc-win\projects\jemalloc\proj.win32\vc2013\jemalloc.vcxproj">
- <Project>{8b897e33-6428-4254-8335-4911d179bad1}</Project>
- </ProjectReference>
<ProjectReference Include="..\src\Win32_Interop\Win32_Interop.vcxproj">
<Project>{8c07f811-c81c-432c-b334-1ae6faecf951}</Project>
</ProjectReference>
diff --git a/msvs/hiredis/hiredis.vcxproj b/msvs/hiredis/hiredis.vcxproj
index 0622958..efaedae
--- a/msvs/hiredis/hiredis.vcxproj
+++ b/msvs/hiredis/hiredis.vcxproj
@@ -28,27 +28,25 @@
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
- <PlatformToolset>v120</PlatformToolset>
+ <PlatformToolset>v140_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
- <PlatformToolset>v120</PlatformToolset>
+ <PlatformToolset>v140_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
- <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
- <PlatformToolset>v120</PlatformToolset>
+ <PlatformToolset>v140_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
- <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
- <PlatformToolset>v120</PlatformToolset>
+ <PlatformToolset>v140_xp</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
@@ -66,30 +64,20 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <PropertyGroup>
<TargetName>hiredis</TargetName>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <TargetName>hiredis</TargetName>
- <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
- <IntDir>$(Platform)\$(Configuration)\</IntDir>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
- <TargetName>hiredis</TargetName>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <TargetName>hiredis</TargetName>
- <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
- <IntDir>$(Platform)\$(Configuration)\</IntDir>
+ <OutDir>$(ProjectDir)..\$(Platform)\$(Configuration)\</OutDir>
+ <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(MSBuildProjectName)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
- <PreprocessorDefinitions>_OFF_T_DEFINED;WIN32;_LIB;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+ <PreprocessorDefinitions>_WIN32_WINNT=0x0502;_OFF_T_DEFINED;WIN32;_LIB;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
+ <MinimalRebuild>false</MinimalRebuild>
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@@ -101,9 +89,10 @@
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
- <PreprocessorDefinitions>_OFF_T_DEFINED;WIN32;_LIB;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+ <PreprocessorDefinitions>_WIN32_WINNT=0x0502;_OFF_T_DEFINED;WIN32;_LIB;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
+ <MinimalRebuild>false</MinimalRebuild>
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@@ -117,10 +106,9 @@
<Optimization>Full</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
- <PreprocessorDefinitions>_OFF_T_DEFINED;WIN32;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <PreprocessorDefinitions>_WIN32_WINNT=0x0502;_OFF_T_DEFINED;WIN32;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
- <WholeProgramOptimization>true</WholeProgramOptimization>
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@@ -136,10 +124,9 @@
<Optimization>Full</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
- <PreprocessorDefinitions>_OFF_T_DEFINED;WIN32;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <PreprocessorDefinitions>_WIN32_WINNT=0x0502;_OFF_T_DEFINED;WIN32;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
- <WholeProgramOptimization>true</WholeProgramOptimization>
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
diff --git a/msvs/lua/lua/lua.vcxproj b/msvs/lua/lua/lua.vcxproj
index b187130..adef07b
--- a/msvs/lua/lua/lua.vcxproj
+++ b/msvs/lua/lua/lua.vcxproj
@@ -30,28 +30,28 @@
<UseDebugLibraries>true</UseDebugLibraries>
<CLRSupport>false</CLRSupport>
<CharacterSet>MultiByte</CharacterSet>
- <PlatformToolset>v120</PlatformToolset>
+ <PlatformToolset>v140_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CLRSupport>false</CLRSupport>
<CharacterSet>MultiByte</CharacterSet>
- <PlatformToolset>v120</PlatformToolset>
+ <PlatformToolset>v140_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<CLRSupport>false</CLRSupport>
<CharacterSet>MultiByte</CharacterSet>
- <PlatformToolset>v120</PlatformToolset>
+ <PlatformToolset>v140_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<CLRSupport>false</CLRSupport>
<CharacterSet>MultiByte</CharacterSet>
- <PlatformToolset>v120</PlatformToolset>
+ <PlatformToolset>v140_xp</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
@@ -69,25 +69,16 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <PropertyGroup Condition="'$(Configuration)'=='Debug'">
<LinkIncremental>true</LinkIncremental>
- <TargetExt>.lib</TargetExt>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <LinkIncremental>true</LinkIncremental>
- <TargetExt>.lib</TargetExt>
- <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
- <IntDir>$(Platform)\$(Configuration)\</IntDir>
</PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <PropertyGroup Condition="'$(Configuration)'=='Release'">
<LinkIncremental>false</LinkIncremental>
- <TargetExt>.lib</TargetExt>
</PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <LinkIncremental>false</LinkIncremental>
+ <PropertyGroup>
<TargetExt>.lib</TargetExt>
- <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
- <IntDir>$(Platform)\$(Configuration)\</IntDir>
+ <OutDir>$(SolutionDir)build\$(Platform)\$(Configuration)\</OutDir>
+ <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(MSBuildProjectName)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
@@ -95,8 +86,9 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_OFF_T_DEFINED;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions);LUA_ANSI;ENABLE_CJSON_GLOBAL</PreprocessorDefinitions>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
- <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<DisableSpecificWarnings>4244;4018</DisableSpecificWarnings>
+ <MinimalRebuild>false</MinimalRebuild>
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
@@ -110,8 +102,9 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_OFF_T_DEFINED;WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions);_WIN32_WINNT=0x0501;LUA_ANSI;ENABLE_CJSON_GLOBAL</PreprocessorDefinitions>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
- <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<DisableSpecificWarnings>4244;4018</DisableSpecificWarnings>
+ <MinimalRebuild>false</MinimalRebuild>
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
@@ -124,10 +117,10 @@
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>_OFF_T_DEFINED;WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions);LUA_ANSI;ENABLE_CJSON_GLOBAL</PreprocessorDefinitions>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
- <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<DisableSpecificWarnings>4244;4018</DisableSpecificWarnings>
<Optimization>Full</Optimization>
<WholeProgramOptimization>true</WholeProgramOptimization>
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
@@ -140,8 +133,8 @@
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>_OFF_T_DEFINED;WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions);_WIN32_WINNT=0x0501;LUA_ANSI;ENABLE_CJSON_GLOBAL</PreprocessorDefinitions>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
- <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<DisableSpecificWarnings>4244;4018</DisableSpecificWarnings>
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
diff --git a/src/Win32_Interop/Win32_ANSI.c b/src/Win32_Interop/Win32_ANSI.c
index 404b84f..e7c55d2
--- a/src/Win32_Interop/Win32_ANSI.c
+++ b/src/Win32_Interop/Win32_ANSI.c
@@ -737,7 +737,7 @@ void ANSI_printf(char *format, ...) {
memset(buffer, 0, cBufLen);
va_start(args, format);
- retVal = vsprintf_s(buffer, cBufLen, format, args);
+ retVal = vsnprintf(buffer, cBufLen - 1, format, args);
va_end(args);
if (retVal > 0) {
diff --git a/src/Win32_Interop/Win32_EventLog.cpp b/src/Win32_Interop/Win32_EventLog.cpp
index 1856540..3db4ddd
--- a/src/Win32_Interop/Win32_EventLog.cpp
+++ b/src/Win32_Interop/Win32_EventLog.cpp
@@ -30,7 +30,6 @@ using namespace std;
#include "Win32_EventLog.h"
#include "Win32_SmartHandle.h"
-#include "EventLog.h"
static bool eventLogEnabled = true;
static string eventLogIdentity = "redis";
@@ -129,17 +128,17 @@ void RedisEventLog::LogMessage(LPCSTR msg, const WORD type) {
DWORD eventID;
switch (type) {
case EVENTLOG_ERROR_TYPE:
- eventID = MSG_ERROR_1;
+ eventID = 0x2;
break;
case EVENTLOG_WARNING_TYPE:
- eventID = MSG_WARNING_1;
+ eventID = 0x1;
break;
case EVENTLOG_INFORMATION_TYPE:
- eventID = MSG_INFO_1;
+ eventID = 0x0;
break;
default:
std::cerr << "Unrecognized type: " << type << "\n";
- eventID = MSG_INFO_1;
+ eventID = 0x0;
break;
}
diff --git a/src/Win32_Interop/Win32_FDAPI.cpp b/src/Win32_Interop/Win32_FDAPI.cpp
index 3df9af1..f60e3d4
--- a/src/Win32_Interop/Win32_FDAPI.cpp
+++ b/src/Win32_Interop/Win32_FDAPI.cpp
@@ -46,11 +46,13 @@ fdapi_access access = NULL;
fdapi_bind bind = NULL;
fdapi_connect connect = NULL;
fdapi_fcntl fcntl = NULL;
+fdapi_ioctl ioctl = NULL;
fdapi_fstat fdapi_fstat64 = NULL;
fdapi_fsync fsync = NULL;
fdapi_ftruncate ftruncate = NULL;
fdapi_freeaddrinfo freeaddrinfo = NULL;
fdapi_getaddrinfo getaddrinfo = NULL;
+fdapi_gethostbyname gethostbyname = NULL;
fdapi_getpeername getpeername = NULL;
fdapi_getsockname getsockname = NULL;
fdapi_getsockopt getsockopt = NULL;
@@ -67,7 +69,9 @@ fdapi_open open = NULL;
fdapi_pipe pipe = NULL;
fdapi_poll poll = NULL;
fdapi_read read = NULL;
+fdapi_recv recv = NULL;
fdapi_select select = NULL;
+fdapi_send send = NULL;
fdapi_setsockopt setsockopt = NULL;
fdapi_socket socket = NULL;
fdapi_write write = NULL;
@@ -622,6 +626,23 @@ int FDAPI_fcntl(int rfd, int cmd, int flags = 0 ) {
return -1;
}
+int FDAPI_ioctl(int rfd, int cmd, char *buf) {
+ try {
+ SocketInfo* socket_info = RFDMap::getInstance().lookupSocketInfo(rfd);
+ if (socket_info != NULL && socket_info->socket != INVALID_SOCKET) {
+ if (f_ioctlsocket(socket_info->socket, cmd, (u_long *)buf) != SOCKET_ERROR) {
+ return 0;
+ } else {
+ errno = f_WSAGetLastError();
+ return -1;
+ }
+ }
+ } CATCH_AND_REPORT();
+
+ errno = EBADF;
+ return -1;
+}
+
int FDAPI_poll(struct pollfd *fds, nfds_t nfds, int timeout) {
try {
struct pollfd* pollCopy = new struct pollfd[nfds];
@@ -777,6 +798,42 @@ ssize_t FDAPI_read(int rfd, void *buf, size_t count) {
return -1;
}
+ssize_t FDAPI_recv(int rfd, void *buf, size_t count, int flags) {
+ try {
+ SOCKET socket = RFDMap::getInstance().lookupSocket(rfd);
+ if (socket != INVALID_SOCKET) {
+ int retval = f_recv(socket, (char*) buf, (unsigned int) count, flags);
+ if (retval == -1) {
+ errno = GetLastError();
+ if (errno == WSAEWOULDBLOCK) {
+ errno = EAGAIN;
+ }
+ }
+ return retval;
+ }
+ } CATCH_AND_REPORT();
+ errno = EBADF;
+ return -1;
+}
+
+ssize_t FDAPI_send(int rfd, const void *buf, size_t count, int flags) {
+ try {
+ SOCKET socket = RFDMap::getInstance().lookupSocket(rfd);
+ if (socket != INVALID_SOCKET) {
+ int retval = f_send(socket, (const char*) buf, (unsigned int) count, flags);
+ if (retval == -1) {
+ errno = GetLastError();
+ if (errno == WSAEWOULDBLOCK) {
+ errno = EAGAIN;
+ }
+ }
+ return retval;
+ }
+ } CATCH_AND_REPORT();
+ errno = EBADF;
+ return -1;
+}
+
ssize_t FDAPI_write(int rfd, const void *buf, size_t count) {
try {
SOCKET socket = RFDMap::getInstance().lookupSocket(rfd);
@@ -1195,12 +1252,14 @@ private:
bind = FDAPI_bind;
connect = FDAPI_connect;
fcntl = FDAPI_fcntl;
+ ioctl = FDAPI_ioctl;
fdapi_fstat64 = (fdapi_fstat) FDAPI_fstat64;
freeaddrinfo = FDAPI_freeaddrinfo;
fsync = FDAPI_fsync;
ftruncate = FDAPI_ftruncate;
getaddrinfo = FDAPI_getaddrinfo;
getsockopt = FDAPI_getsockopt;
+ gethostbyname = FDAPI_gethostbyname;
getpeername = FDAPI_getpeername;
getsockname = FDAPI_getsockname;
htonl = FDAPI_htonl;
@@ -1216,9 +1275,11 @@ private:
pipe = FDAPI_pipe;
poll = FDAPI_poll;
read = FDAPI_read;
+ recv = FDAPI_recv;
select = FDAPI_select;
setsockopt = FDAPI_setsockopt;
socket = FDAPI_socket;
+ send = FDAPI_send;
write = FDAPI_write;
}
diff --git a/src/Win32_Interop/Win32_FDAPI.h b/src/Win32_Interop/Win32_FDAPI.h
index 8fae9c7..6e09596
--- a/src/Win32_Interop/Win32_FDAPI.h
+++ b/src/Win32_Interop/Win32_FDAPI.h
@@ -116,9 +116,12 @@ typedef int (*fdapi_open)(const char * _Filename, int _OpenFlag, int flags);
typedef int (*fdapi_accept)(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
typedef int (*fdapi_setsockopt)(int sockfd, int level, int optname,const void *optval, socklen_t optlen);
typedef int (*fdapi_fcntl)(int fd, int cmd, int flags);
+typedef int (*fdapi_ioctl)(int fd, int cmd, char *buf);
typedef int (*fdapi_poll)(struct pollfd *fds, nfds_t nfds, int timeout);
typedef int (*fdapi_getsockopt)(int sockfd, int level, int optname, void *optval, socklen_t *optlen);
typedef int (*fdapi_connect)(int sockfd, const struct sockaddr *addr, size_t addrlen);
+typedef ssize_t (*fdapi_recv)(int fd, void *buf, size_t count, int flags);
+typedef ssize_t (*fdapi_send)(int rfd, void const *buf, size_t count, int flags);
typedef ssize_t (*fdapi_read)(int fd, void *buf, size_t count);
typedef ssize_t (*fdapi_write)(int fd, const void *buf, size_t count);
typedef int (*fdapi_fsync)(int fd);
@@ -128,6 +131,7 @@ typedef int (*fdapi_bind)(int sockfd, const struct sockaddr *addr, socklen_t add
typedef u_short (*fdapi_htons)(u_short hostshort);
typedef u_long (*fdapi_htonl)(u_long hostlong);
typedef u_short (*fdapi_ntohs)(u_short netshort);
+typedef struct hostent* (*fdapi_gethostbyname)(const char *name);
typedef int (*fdapi_getpeername)(int sockfd, struct sockaddr *addr, socklen_t * addrlen);
typedef int (*fdapi_getsockname)(int sockfd, struct sockaddr* addrsock, int* addrlen );
typedef void (*fdapi_freeaddrinfo)(struct addrinfo *ai);
@@ -159,12 +163,14 @@ extern fdapi_access access;
extern fdapi_bind bind;
extern fdapi_connect connect;
extern fdapi_fcntl fcntl;
+extern fdapi_ioctl ioctl;
extern fdapi_fstat fdapi_fstat64;
extern fdapi_freeaddrinfo freeaddrinfo;
extern fdapi_fsync fsync;
extern fdapi_ftruncate ftruncate;
extern fdapi_getaddrinfo getaddrinfo;
extern fdapi_getsockopt getsockopt;
+extern fdapi_gethostbyname gethostbyname;
extern fdapi_getpeername getpeername;
extern fdapi_getsockname getsockname;
extern fdapi_htonl htonl;
@@ -180,7 +186,9 @@ extern fdapi_open open;
extern fdapi_pipe pipe;
extern fdapi_poll poll;
extern fdapi_read read;
+extern fdapi_recv recv;
extern fdapi_select select;
+extern fdapi_send send;
extern fdapi_setsockopt setsockopt;
extern fdapi_socket socket;
extern fdapi_write write;
diff --git a/src/Win32_Interop/Win32_Interop.vcxproj b/src/Win32_Interop/Win32_Interop.vcxproj
index 93fc44b..b75d89b
--- a/src/Win32_Interop/Win32_Interop.vcxproj
+++ b/src/Win32_Interop/Win32_Interop.vcxproj
@@ -74,35 +74,6 @@
<ClInclude Include="win32_wsiocp2.h" />
<ClInclude Include="WS2tcpip.h" />
</ItemGroup>
- <ItemGroup>
- <CustomBuild Include="EventLog.mc">
- <FileType>Document</FileType>
- <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">md resources
-mc.exe -A -b -c -h . -r resources EventLog.mc
-rc.exe -foresources/EventLog.res resources/EventLog.rc
-link.exe -dll -noentry resources/EventLog.res -out:$(TargetDir)EventLog.dll
-</Command>
- <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">md resources
-mc.exe -A -b -c -h . -r resources EventLog.mc
-rc.exe -foresources/EventLog.res resources/EventLog.rc
-link.exe -dll -noentry resources/EventLog.res -out:$(TargetDir)EventLog.dll
-</Command>
- <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">EventLog.h</Outputs>
- <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">EventLog.h</Outputs>
- <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">md resources
-mc.exe -A -b -c -h . -r resources EventLog.mc
-rc.exe -foresources/EventLog.res resources/EventLog.rc
-link.exe -dll -noentry resources/EventLog.res -out:$(TargetDir)EventLog.dll
-</Command>
- <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">md resources
-mc.exe -A -b -c -h . -r resources EventLog.mc
-rc.exe -foresources/EventLog.res resources/EventLog.rc
-link.exe -dll -noentry resources/EventLog.res -out:$(TargetDir)EventLog.dll
-</Command>
- <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">EventLog.h</Outputs>
- <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">EventLog.h</Outputs>
- </CustomBuild>
- </ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{8C07F811-C81C-432C-B334-1AE6FAECF951}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
@@ -113,27 +84,25 @@ link.exe -dll -noentry resources/EventLog.res -out:$(TargetDir)EventLog.dll
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
- <PlatformToolset>v120</PlatformToolset>
+ <PlatformToolset>v140_xp</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
- <PlatformToolset>v120</PlatformToolset>
+ <PlatformToolset>v140_xp</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
- <PlatformToolset>v120</PlatformToolset>
- <WholeProgramOptimization>true</WholeProgramOptimization>
+ <PlatformToolset>v140_xp</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
- <PlatformToolset>v120</PlatformToolset>
- <WholeProgramOptimization>true</WholeProgramOptimization>
+ <PlatformToolset>v140_xp</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
@@ -152,13 +121,9 @@ link.exe -dll -noentry resources/EventLog.res -out:$(TargetDir)EventLog.dll
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
- <IntDir>$(Platform)\$(Configuration)\</IntDir>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
- <IntDir>$(Platform)\$(Configuration)\</IntDir>
+ <PropertyGroup>
+ <OutDir>$(SolutionDir)build\$(Platform)\$(Configuration)\</OutDir>
+ <IntDir>$(SolutionDir)build\$(Platform)\$(Configuration)\$(MSBuildProjectName)\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
@@ -166,9 +131,10 @@ link.exe -dll -noentry resources/EventLog.res -out:$(TargetDir)EventLog.dll
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
- <PreprocessorDefinitions>USE_STATIC;USE_JEMALLOC;_OFF_T_DEFINED;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);LACKS_STDLIB_H;_CRT_SECURE_NO_WARNINGS;PSAPI_VERSION=1</PreprocessorDefinitions>
+ <PreprocessorDefinitions>_WIN32_WINNT=0x0502;USE_STATIC;USE_JEMALLOC;_OFF_T_DEFINED;_NO_CRT_STDIO_INLINE;_CRT_SECURE_NO_DEPRECATE;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);LACKS_STDLIB_H;_CRT_SECURE_NO_WARNINGS;PSAPI_VERSION=1</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(ProjectDir)..\..\deps\lua\src;$(ProjectDir)..\..\deps\jemalloc-win\include</AdditionalIncludeDirectories>
- <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+ <MinimalRebuild>false</MinimalRebuild>
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@@ -186,9 +152,10 @@ link.exe -dll -noentry resources/EventLog.res -out:$(TargetDir)EventLog.dll
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
- <PreprocessorDefinitions>USE_STATIC;USE_JEMALLOC;_OFF_T_DEFINED;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);LACKS_STDLIB_H;_CRT_SECURE_NO_WARNINGS;PSAPI_VERSION=1;_WIN32_WINNT=0x0501</PreprocessorDefinitions>
+ <PreprocessorDefinitions>_WIN32_WINNT=0x0502;USE_STATIC;USE_JEMALLOC;_OFF_T_DEFINED;_NO_CRT_STDIO_INLINE;_CRT_SECURE_NO_DEPRECATE;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions);LACKS_STDLIB_H;_CRT_SECURE_NO_WARNINGS;PSAPI_VERSION=1;_WIN32_WINNT=0x0501</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(ProjectDir)..\..\deps\lua\src;$(ProjectDir)..\..\deps\jemalloc-win\include</AdditionalIncludeDirectories>
- <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+ <MinimalRebuild>false</MinimalRebuild>
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@@ -211,10 +178,9 @@ link.exe -dll -noentry resources/EventLog.res -out:$(TargetDir)EventLog.dll
<Optimization>Full</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
- <PreprocessorDefinitions>USE_STATIC;USE_JEMALLOC;_OFF_T_DEFINED;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);LACKS_STDLIB_H;_CRT_SECURE_NO_WARNINGS;PSAPI_VERSION=1</PreprocessorDefinitions>
+ <PreprocessorDefinitions>_WIN32_WINNT=0x0502;USE_STATIC;USE_JEMALLOC;_OFF_T_DEFINED;_NO_CRT_STDIO_INLINE;_CRT_SECURE_NO_DEPRECATE;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);LACKS_STDLIB_H;_CRT_SECURE_NO_WARNINGS;PSAPI_VERSION=1</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(ProjectDir)..\..\deps\lua\src;$(ProjectDir)..\..\deps\jemalloc-win\include</AdditionalIncludeDirectories>
- <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
- <WholeProgramOptimization>true</WholeProgramOptimization>
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@@ -235,9 +201,9 @@ link.exe -dll -noentry resources/EventLog.res -out:$(TargetDir)EventLog.dll
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
- <PreprocessorDefinitions>USE_STATIC;USE_JEMALLOC;_OFF_T_DEFINED;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);LACKS_STDLIB_H;_CRT_SECURE_NO_WARNINGS;PSAPI_VERSION=1;_WIN32_WINNT=0x0501</PreprocessorDefinitions>
+ <PreprocessorDefinitions>_WIN32_WINNT=0x0502;USE_STATIC;USE_JEMALLOC;_OFF_T_DEFINED;_NO_CRT_STDIO_INLINE;_CRT_SECURE_NO_DEPRECATE;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions);LACKS_STDLIB_H;_CRT_SECURE_NO_WARNINGS;PSAPI_VERSION=1;_WIN32_WINNT=0x0501</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(ProjectDir)..\..\deps\lua\src;$(ProjectDir)..\..\deps\jemalloc-win\include</AdditionalIncludeDirectories>
- <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
diff --git a/src/Win32_Interop/Win32_service.cpp b/src/Win32_Interop/Win32_service.cpp
index 488538e..1c33f53
--- a/src/Win32_Interop/Win32_service.cpp
+++ b/src/Win32_Interop/Win32_service.cpp
@@ -59,7 +59,6 @@ this should preceed the other arguments passed to redis. For instance:
#include <windowsx.h>
#include <shlobj.h>
#include <tchar.h>
-#include <strsafe.h>
#include <aclapi.h>
#include "Win32_EventLog.h"
#include <algorithm>
diff --git a/src/ziplist.c b/src/ziplist.c
index 24b0a7c..29d445d
--- a/src/ziplist.c
+++ b/src/ziplist.c
@@ -920,7 +920,7 @@ void ziplistRepr(unsigned char *zl) {
entry = zipEntry(p);
printf(
"{"
- "addr 0x%08lx, " /* TODO" verify 0x%08lx */
+ "addr %p, "
"index %2d, "
"offset %5ld, "
"rl: %5u, "
@@ -929,9 +929,9 @@ void ziplistRepr(unsigned char *zl) {
"pls: %2u, "
"payload %5u"
"} ",
- (PORT_ULONG)p,
+ (void *)p,
index,
- (PORT_ULONG)(p-zl),
+ (long)(p-zl),
entry.headersize+entry.len,
entry.headersize,
entry.prevrawlen,
+4 -2
View File
@@ -133,7 +133,7 @@ void process_plasma_notification(event_loop *loop,
local_scheduler_state *s = context;
/* Read the notification from Plasma. */
object_id obj_id;
recv(client_sock, &obj_id, sizeof(obj_id), 0);
recv(client_sock, (char *) &obj_id, sizeof(obj_id), 0);
handle_object_available(s->scheduler_info, s->scheduler_state, obj_id);
}
@@ -183,7 +183,9 @@ void new_client_connection(event_loop *loop, int listener_sock, void *context,
new_worker_index->sock = new_socket;
new_worker_index->worker_index = utarray_len(s->scheduler_info->workers);
HASH_ADD_INT(s->worker_index, sock, new_worker_index);
worker worker = {.sock = new_socket};
worker worker;
memset(&worker, 0, sizeof(worker));
worker.sock = new_socket;
utarray_push_back(s->scheduler_info->workers, &worker);
}
+32 -7
View File
@@ -46,13 +46,33 @@ struct mmap_record *records_by_pointer = NULL;
const int GRANULARITY_MULTIPLIER = 2;
static void *pointer_advance(void *p, ptrdiff_t n) {
return (unsigned char *) p + n;
}
static void *pointer_retreat(void *p, ptrdiff_t n) {
return (unsigned char *) p - n;
}
static ptrdiff_t pointer_distance(void const *pfrom, void const *pto) {
return (unsigned char const *) pto - (unsigned char const *) pfrom;
}
/* Create a buffer. This is creating a temporary file and then
* immediately unlinking it so we do not leave traces in the system. */
int create_buffer(int64_t size) {
int fd;
#ifdef _WIN32
if (!CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
(DWORD)((uint64_t) size >> (CHAR_BIT * sizeof(DWORD))),
(DWORD)(uint64_t) size, NULL)) {
fd = -1;
}
#else
static char template[] = "/tmp/plasmaXXXXXX";
char file_name[32];
strncpy(file_name, template, 32);
int fd = mkstemp(file_name);
fd = mkstemp(file_name);
if (fd < 0)
return -1;
FILE *file = fdopen(fd, "a+");
@@ -68,6 +88,7 @@ int create_buffer(int64_t size) {
LOG_ERROR("ftruncate error");
return -1;
}
#endif
return fd;
}
@@ -95,14 +116,14 @@ void *fake_mmap(size_t size) {
HASH_ADD(hh_pointer, records_by_pointer, pointer, sizeof(pointer), record);
/* We lie to dlmalloc about where mapped memory actually lives. */
pointer += sizeof(size_t);
pointer = pointer_advance(pointer, sizeof(size_t));
LOG_DEBUG("%p = fake_mmap(%lu)", pointer, size);
return pointer;
}
int fake_munmap(void *addr, size_t size) {
LOG_DEBUG("fake_munmap(%p, %lu)", addr, size);
addr -= sizeof(size_t);
addr = pointer_retreat(addr, sizeof(size_t));
size += sizeof(size_t);
struct mmap_record *record;
@@ -113,12 +134,15 @@ int fake_munmap(void *addr, size_t size) {
* calls to mmap, to prevent dlmalloc from trimming. */
return -1;
}
close(record->fd);
HASH_DELETE(hh_fd, records_by_fd, record);
HASH_DELETE(hh_pointer, records_by_pointer, record);
return munmap(addr, size);
int r = munmap(addr, size);
if (r == 0) {
close(record->fd);
}
return r;
}
void get_malloc_mapinfo(void *addr,
@@ -128,10 +152,11 @@ void get_malloc_mapinfo(void *addr,
struct mmap_record *record;
/* TODO(rshin): Implement a more efficient search through records_by_fd. */
for (record = records_by_fd; record != NULL; record = record->hh_fd.next) {
if (addr >= record->pointer && addr < record->pointer + record->size) {
if (addr >= record->pointer &&
addr < pointer_advance(record->pointer, record->size)) {
*fd = record->fd;
*map_size = record->size;
*offset = addr - record->pointer;
*offset = pointer_distance(record->pointer, addr);
return;
}
}
+1
View File
@@ -6,6 +6,7 @@
#include <errno.h>
#include <stddef.h>
#include <string.h>
#include <unistd.h> /* pid_t */
#include "common.h"
+14 -3
View File
@@ -1,5 +1,9 @@
/* PLASMA CLIENT: Client library for using the plasma store and manager */
#ifdef _WIN32
#include <Win32_Interop/win32_types.h>
#endif
#include <assert.h>
#include <fcntl.h>
#include <stdlib.h>
@@ -103,7 +107,10 @@ void plasma_send_request(int fd, int type, plasma_request *req) {
}
plasma_request make_plasma_request(object_id object_id) {
plasma_request req = {.num_object_ids = 1, .object_ids = {object_id}};
plasma_request req;
memset(&req, 0, sizeof(req));
req.num_object_ids = 1;
req.object_ids[0] = object_id;
return req;
}
@@ -326,7 +333,9 @@ void plasma_delete(plasma_connection *conn, object_id object_id) {
int64_t plasma_evict(plasma_connection *conn, int64_t num_bytes) {
/* Send a request to the store to evict objects. */
plasma_request req = {.num_bytes = num_bytes};
plasma_request req;
memset(&req, 0, sizeof(req));
req.num_bytes = num_bytes;
plasma_send_request(conn->store_conn, PLASMA_EVICT, &req);
/* Wait for a response with the number of bytes actually evicted. */
plasma_reply reply;
@@ -338,6 +347,8 @@ int64_t plasma_evict(plasma_connection *conn, int64_t num_bytes) {
int plasma_subscribe(plasma_connection *conn) {
int fd[2];
/* TODO: Just create 1 socket, bind it to port 0 to find a free port, and
* send the port number instead, and let the client connect. */
/* Create a non-blocking socket pair. This will only be used to send
* notifications from the Plasma store to the client. */
socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
@@ -345,7 +356,7 @@ int plasma_subscribe(plasma_connection *conn) {
int flags = fcntl(fd[1], F_GETFL, 0);
CHECK(fcntl(fd[1], F_SETFL, flags | O_NONBLOCK) == 0);
/* Tell the Plasma store about the subscription. */
plasma_request req = {};
plasma_request req = {0};
plasma_send_request(conn->store_conn, PLASMA_SUBSCRIBE, &req);
/* Send the file descriptor that the Plasma store should use to push
* notifications about sealed objects to this client. We include a one byte
+20 -9
View File
@@ -156,8 +156,11 @@ int send_client_reply(client_connection *conn, plasma_reply *reply) {
}
int send_client_failure_reply(object_id object_id, client_connection *conn) {
plasma_reply reply = {
.object_ids = {object_id}, .num_object_ids = 1, .has_object = 0};
plasma_reply reply;
memset(&reply, 0, sizeof(reply));
reply.object_ids[0] = object_id;
reply.num_object_ids = 1;
reply.has_object = 0;
return send_client_reply(conn, &reply);
}
@@ -584,9 +587,11 @@ int manager_timeout_handler(event_loop *loop, timer_id id, void *context) {
object_conn->num_retries--;
return MANAGER_TIMEOUT;
}
plasma_reply reply = {.object_ids = {object_conn->object_id},
.num_object_ids = 1,
.has_object = 0};
plasma_reply reply;
memset(&reply, 0, sizeof(reply));
reply.object_ids[0] = object_conn->object_id;
reply.num_object_ids = 1;
reply.has_object = 0;
send_client_reply(client_conn, &reply);
remove_object_connection(client_conn, object_conn);
return EVENT_LOOP_TIMER_DONE;
@@ -647,7 +652,10 @@ void process_fetch_request(client_connection *client_conn,
object_id object_id) {
client_conn->is_wait = false;
client_conn->wait_reply = NULL;
plasma_reply reply = {.object_ids = {object_id}, .num_object_ids = 1};
plasma_reply reply;
memset(&reply, 0, sizeof(reply));
reply.object_ids[0] = object_id;
reply.num_object_ids = 1;
if (client_conn->manager_state->db == NULL) {
reply.has_object = 0;
send_client_reply(client_conn, &reply);
@@ -747,7 +755,7 @@ void process_object_notification(event_loop *loop,
plasma_manager_state *state = context;
object_id obj_id;
/* Read the notification from Plasma. */
int n = recv(client_sock, &obj_id, sizeof(object_id), MSG_WAITALL);
int n = recv(client_sock, (char *) &obj_id, sizeof(object_id), MSG_WAITALL);
if (n == 0) {
/* The store has closed the socket. */
LOG_DEBUG("The plasma store has closed the object notification socket.");
@@ -769,8 +777,11 @@ void process_object_notification(event_loop *loop,
client_connection *client_conn;
HASH_FIND(fetch_hh, state->fetch_connections, &obj_id, sizeof(object_id),
object_conn);
plasma_reply reply = {
.object_ids = {obj_id}, .num_object_ids = 1, .has_object = 1};
plasma_reply reply;
memset(&reply, 0, sizeof(reply));
reply.object_ids[0] = obj_id;
reply.num_object_ids = 1;
reply.has_object = 1;
while (object_conn) {
next = object_conn->next;
client_conn = object_conn->client_conn;
+1 -1
View File
@@ -380,7 +380,7 @@ void send_notifications(event_loop *loop,
for (int i = 0; i < utarray_len(queue->object_ids); ++i) {
object_id *obj_id = (object_id *) utarray_eltptr(queue->object_ids, i);
/* Attempt to send a notification about this object ID. */
int nbytes = send(client_sock, obj_id, sizeof(*obj_id), 0);
int nbytes = send(client_sock, (char const *) obj_id, sizeof(*obj_id), 0);
if (nbytes >= 0) {
CHECK(nbytes == sizeof(*obj_id));
} else if (nbytes == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {