Skip to content

Commit

Permalink
Changes to memcached source required for compilation on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Galbraith authored and trondn committed Mar 29, 2010
1 parent 04e0609 commit 95c3be8
Show file tree
Hide file tree
Showing 22 changed files with 1,109 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Keep the entries sorted to reduce the risk for a merge conflict
*.[ao]
*.exe
*.gcda
*.gcno
*.gcov
Expand Down
5 changes: 4 additions & 1 deletion assoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
* Hash table
*
*/
#ifndef __WIN32__
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/signal.h>
#include <sys/resource.h>
#include <fcntl.h>
#include <netinet/in.h>
#endif

#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
Expand Down
13 changes: 7 additions & 6 deletions default_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <ctype.h>
#include <unistd.h>
#include <stddef.h>
#include <inttypes.h>

#include "default_engine.h"
#include "util.h"
Expand Down Expand Up @@ -252,13 +253,13 @@ static ENGINE_ERROR_CODE default_get_stats(ENGINE_HANDLE* handle,
int len;

pthread_mutex_lock(&engine->stats.lock);
len = sprintf(val, "%llu", (unsigned long long)engine->stats.evictions);
len = sprintf(val, "%"PRIu64, (uint64_t)engine->stats.evictions);
add_stat("evictions", 9, val, len, cookie);
len = sprintf(val, "%llu", (unsigned long long)engine->stats.curr_items);
len = sprintf(val, "%"PRIu64, (uint64_t)engine->stats.curr_items);
add_stat("curr_items", 10, val, len, cookie);
len = sprintf(val, "%llu", (unsigned long long)engine->stats.total_items);
len = sprintf(val, "%"PRIu64, (uint64_t)engine->stats.total_items);
add_stat("total_items", 11, val, len, cookie);
len = sprintf(val, "%llu", (unsigned long long)engine->stats.curr_bytes);
len = sprintf(val, "%"PRIu64, (uint64_t)engine->stats.curr_bytes);
add_stat("bytes", 5, val, len, cookie);
len = sprintf(val, "%"PRIu64, engine->stats.reclaimed);
add_stat("reclaimed", 9, val, len, cookie);
Expand Down Expand Up @@ -304,8 +305,8 @@ static ENGINE_ERROR_CODE default_arithmetic(ENGINE_HANDLE* handle,
return ENGINE_KEY_ENOENT;
} else {
char buffer[1023];
int len = snprintf(buffer, sizeof(buffer), "%llu\r\n",
(unsigned long long)initial);
int len = snprintf(buffer, sizeof(buffer), "%"PRIu64"\r\n",
(uint64_t)initial);

item = item_alloc(engine, key, nkey, 0, exptime, len);
if (item == NULL) {
Expand Down
3 changes: 2 additions & 1 deletion devtools/clean-whitespace.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
use strict;
use FindBin qw($Bin);
chdir "$Bin/.." or die;
my @files = (glob("*.h"), glob("*.c"), glob("*.ac"));
my @files = (glob("*.h"), glob("*.c"), glob("*.ac"), glob("./win32/*.c"), glob("./win32/*.h"), glob("./m4/*.m4"));

foreach my $f (@files) {
open(my $fh, $f) or die;
my $before = do { local $/; <$fh>; };
Expand Down
5 changes: 4 additions & 1 deletion include/memcached/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ extern "C" {
/**
* Abstract interface to an engine.
*/
#ifdef __WIN32__
#undef interface
#endif
typedef struct engine_interface {
uint64_t interface; /**< The version number on the engine structure */
} ENGINE_HANDLE;
Expand Down Expand Up @@ -217,7 +220,7 @@ extern "C" {
*
* @return the server's version number
*/
const char* (*server_version)();
const char* (*server_version)(void);

/**
* Generate a simple hash value of a piece of data.
Expand Down
4 changes: 2 additions & 2 deletions isasl.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static void store_pw(user_db_entry_t **ht, const char *u, const char *p)
ht[h] = e;
}

static void free_user_ht()
static void free_user_ht(void)
{
if (user_ht) {
for (int i = 0; i < n_uht_buckets; i++) {
Expand All @@ -79,7 +79,7 @@ static void free_user_ht()
}
}

static int load_user_db()
static int load_user_db(void)
{
const char *filename = getenv("ISASL_PWFILE");
if (!filename) {
Expand Down
2 changes: 1 addition & 1 deletion isasl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

typedef struct sasl_callback {
unsigned long id;
int (*proc)();
int (*proc)(void);
void *context;
} sasl_callback_t;

Expand Down
8 changes: 7 additions & 1 deletion items.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */

#ifdef __WIN32__
#include "win32.h"
#else
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/signal.h>
#include <sys/resource.h>
#include <fcntl.h>
#include <netinet/in.h>
#endif

#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <assert.h>
#include <inttypes.h>

#include "default_engine.h"

Expand Down
69 changes: 45 additions & 24 deletions memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
* Brad Fitzpatrick <brad@danga.com>
*/
#include "memcached.h"

#ifndef __WIN32__

#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <signal.h>
#include <sys/resource.h>
#include <sys/uio.h>
#include <ctype.h>
#include <stdarg.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <signal.h>

/* some POSIX systems need the following definition
* to get mlockall flags out of sys/mman.h. */
Expand All @@ -34,16 +37,20 @@
#endif
#include <pwd.h>
#include <sys/mman.h>
#endif /* !__WIN32__ */

#include <getopt.h>
#include <fcntl.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <assert.h>
#include <limits.h>
#include <ctype.h>
#include <stdarg.h>

#include <sysexits.h>
#include <stddef.h>
#ifdef HAVE_DLFCN_H
Expand Down Expand Up @@ -1045,10 +1052,10 @@ static void complete_incr_bin(conn *c) {
for (i = 0; i < nkey; i++) {
fprintf(stderr, "%c", key[i]);
}
fprintf(stderr, " %lld, %llu, %d\n",
(long long)req->message.body.delta,
(long long)req->message.body.initial,
req->message.body.expiration);
fprintf(stderr, " %" PRIu64 ", %" PRIu64 ", %" PRIu64 "\n",
(uint64_t)req->message.body.delta,
(uint64_t)req->message.body.initial,
(uint64_t)req->message.body.expiration);
}

ENGINE_ERROR_CODE ret;
Expand Down Expand Up @@ -2469,10 +2476,10 @@ static void server_stats(ADD_STAT add_stats, conn *c, bool aggregate) {
struct slab_stats slab_stats;
slab_stats_aggregate(&thread_stats, &slab_stats);

#ifndef WIN32
#ifndef __WIN32__
struct rusage usage;
getrusage(RUSAGE_SELF, &usage);
#endif /* !WIN32 */
#endif

STATS_LOCK();

Expand All @@ -2482,14 +2489,14 @@ static void server_stats(ADD_STAT add_stats, conn *c, bool aggregate) {
APPEND_STAT("version", "%s", VERSION);
APPEND_STAT("pointer_size", "%d", (int)(8 * sizeof(void *)));

#ifndef WIN32
#ifndef __WIN32__
append_stat("rusage_user", add_stats, c, "%ld.%06ld",
(long)usage.ru_utime.tv_sec,
(long)usage.ru_utime.tv_usec);
append_stat("rusage_system", add_stats, c, "%ld.%06ld",
(long)usage.ru_stime.tv_sec,
(long)usage.ru_stime.tv_usec);
#endif /* !WIN32 */
#endif

APPEND_STAT("curr_connections", "%u", stats.curr_conns - 1);
APPEND_STAT("total_connections", "%u", stats.total_conns);
Expand All @@ -2512,9 +2519,9 @@ static void server_stats(ADD_STAT add_stats, conn *c, bool aggregate) {
APPEND_STAT("bytes_written", "%"PRIu64, thread_stats.bytes_written);
APPEND_STAT("limit_maxbytes", "%"PRIu64, settings.maxbytes);
APPEND_STAT("accepting_conns", "%u", stats.accepting_conns);
APPEND_STAT("listen_disabled_num", "%"PRIu64, stats.listen_disabled_num);
APPEND_STAT("listen_disabled_num", "%" PRIu64, (unsigned long long)stats.listen_disabled_num);
APPEND_STAT("threads", "%d", settings.num_threads);
APPEND_STAT("conn_yields", "%"PRIu64, thread_stats.conn_yields);
APPEND_STAT("conn_yields", "%" PRIu64, (unsigned long long)thread_stats.conn_yields);
STATS_UNLOCK();
}

Expand Down Expand Up @@ -3882,7 +3889,7 @@ static void maximize_sndbuf(const int sfd) {
int old_size;

/* Start with the default size. */
if (getsockopt(sfd, SOL_SOCKET, SO_SNDBUF, &old_size, &intsize) != 0) {
if (getsockopt(sfd, SOL_SOCKET, SO_SNDBUF, (void *)&old_size, &intsize) != 0) {
if (settings.verbose > 0)
perror("getsockopt(SO_SNDBUF)");
return;
Expand Down Expand Up @@ -4062,6 +4069,7 @@ static int new_socket_unix(void) {
return sfd;
}

/* this will probably not work on windows */
static int server_socket_unix(const char *path, int access_mask) {
int sfd;
struct linger ling = {0, 0};
Expand Down Expand Up @@ -4301,6 +4309,8 @@ static void remove_pidfile(const char *pid_file) {

}

#ifndef __WIN32__

static void sig_handler(const int sig) {
printf("SIGINT handled.\n");
exit(EXIT_SUCCESS);
Expand All @@ -4315,7 +4325,9 @@ static int sigignore(int sig) {
}
return 0;
}
#endif
#endif /* !HAVE_SIGIGNORE */

#endif /* !__WIN32__ */


/*
Expand Down Expand Up @@ -4361,7 +4373,7 @@ static int enable_large_pages(void) {
#endif
}

static const char* get_server_version() {
static const char* get_server_version(void) {
return VERSION;
}

Expand Down Expand Up @@ -4544,10 +4556,10 @@ int main (int argc, char **argv) {
char old_options[1024] = { [0] = '\0' };
char *old_opts = old_options;



/* handle SIGINT */
#ifndef __WIN32__
/* handle SIGINT */
signal(SIGINT, sig_handler);
#endif

/* init settings */
settings_init();
Expand All @@ -4568,7 +4580,9 @@ int main (int argc, char **argv) {
"hi" /* help, licence info */
"r" /* maximize core file limit */
"v" /* verbose */
#ifndef __WIN32__
"d" /* daemon mode */
#endif
"l:" /* interface to listen on */
"u:" /* user identity to run as */
"P:" /* save PID in file */
Expand Down Expand Up @@ -4749,8 +4763,13 @@ int main (int argc, char **argv) {
" and will decrease your memory efficiency.\n"
);
}
#ifndef __WIN32__
old_opts += sprintf(old_opts, "item_size_max=%zu;",
settings.item_size_max);
#else
old_opts += sprintf(old_opts, "item_size_max=%lu;", (long unsigned)
settings.item_size_max);
#endif
break;
case 'E':
engine = optarg;
Expand Down Expand Up @@ -4865,6 +4884,7 @@ int main (int argc, char **argv) {
init_sasl();
}

#ifndef __WIN32__
/* daemonize if requested */
/* if we want to ensure our ability to dump core, don't chdir to / */
if (do_daemonize) {
Expand All @@ -4876,6 +4896,7 @@ int main (int argc, char **argv) {
exit(EXIT_FAILURE);
}
}
#endif

/* lock paged memory if needed */
if (lock_memory) {
Expand Down Expand Up @@ -4909,6 +4930,7 @@ int main (int argc, char **argv) {
conn_init();
default_thread_stats = new_stats();

#ifndef __WIN32__
/*
* ignore SIGPIPE signals; we can use errno == EPIPE if we
* need that information
Expand All @@ -4917,6 +4939,8 @@ int main (int argc, char **argv) {
perror("failed to ignore SIGPIPE; sigaction");
exit(EX_OSERR);
}
#endif

/* start up worker threads if MT mode */
thread_init(settings.num_threads, main_base);
/* save the PID in if we're a daemon, do this after thread_init due to
Expand All @@ -4929,7 +4953,6 @@ int main (int argc, char **argv) {

/* create unix mode sockets after dropping privileges */
if (settings.socketpath != NULL) {
errno = 0;
if (server_socket_unix(settings.socketpath,settings.access)) {
vperror("failed to listen on UNIX socket: %s", settings.socketpath);
exit(EX_OSERR);
Expand All @@ -4956,7 +4979,6 @@ int main (int argc, char **argv) {
}
}

errno = 0;
if (settings.port && server_socket(settings.port, tcp_transport,
portnumber_file)) {
vperror("failed to listen on TCP port %d", settings.port);
Expand All @@ -4972,7 +4994,6 @@ int main (int argc, char **argv) {
udp_port = settings.udpport ? settings.udpport : settings.port;

/* create the UDP listening socket and bind it */
errno = 0;
if (settings.udpport && server_socket(settings.udpport, udp_transport,
portnumber_file)) {
vperror("failed to listen on UDP port %d", settings.udpport);
Expand Down
Loading

0 comments on commit 95c3be8

Please sign in to comment.