Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

start of the incr fix, rearranges a bunch, adds util, tests, etc

  • Loading branch information...
commit 420aa2d992093b78c1bba6cbb3577d5b53a19ec8 1 parent 9791d32
Brad Fitzpatrick authored dustin committed
1  .gitignore
@@ -33,3 +33,4 @@ memcached-*.tar.gz
33 33 doc/protocol-binary-range.txt
34 34 doc/protocol-binary.txt
35 35 /sizes
  36 +/internal_tests
8 Makefile.am
... ... @@ -1,4 +1,4 @@
1   -bin_PROGRAMS = memcached memcached-debug sizes
  1 +bin_PROGRAMS = memcached memcached-debug sizes internal_tests
2 2 pkginclude_HEADERS = protocol_binary.h
3 3
4 4 BUILT_SOURCES=
@@ -10,6 +10,7 @@ memcached_SOURCES = memcached.c memcached.h \
10 10 assoc.c assoc.h \
11 11 thread.c daemon.c \
12 12 stats.c stats.h \
  13 + util.c util.h \
13 14 trace.h
14 15
15 16 if BUILD_SOLARIS_PRIVS
@@ -26,6 +27,8 @@ memcached_DEPENDENCIES =
26 27 memcached_debug_DEPENDENCIES =
27 28 CLEANFILES=
28 29
  30 +internal_tests_SOURCES = internal_tests.c util.c
  31 +
29 32 if BUILD_DTRACE
30 33 BUILT_SOURCES += memcached_dtrace.h
31 34 CLEANFILES += memcached_dtrace.h
@@ -58,8 +61,9 @@ EXTRA_DIST = doc scripts TODO t memcached.spec memcached_dtrace.d
58 61
59 62 MOSTLYCLEANFILES = *.gcov *.gcno *.gcda *.tcov
60 63
61   -test: memcached-debug sizes
  64 +test: memcached-debug internal_tests sizes
62 65 $(srcdir)/sizes
  66 + $(srcdir)/internal_tests
63 67 prove $(srcdir)/t
64 68 @if test `basename $(PROFILER)` = "gcov"; then \
65 69 for file in memcached_debug-*.gc??; do \
23 globals.c
... ... @@ -0,0 +1,23 @@
  1 +#include "memcached.h"
  2 +
  3 +/*
  4 + * This file contains global variables shared across the rest of the
  5 + * memcached codebase. These were originally in memcached.c but had
  6 + * to be removed to make the rest of the object files linkable into
  7 + * the test infrastructure.
  8 + *
  9 + */
  10 +
  11 +/*
  12 + * We keep the current time of day in a global variable that's updated by a
  13 + * timer event. This saves us a bunch of time() system calls (we really only
  14 + * need to get the time once a second, whereas there can be tens of thousands
  15 + * of requests a second) and allows us to use server-start-relative timestamps
  16 + * rather than absolute UNIX timestamps, a space savings on systems where
  17 + * sizeof(time_t) > sizeof(unsigned int).
  18 + */
  19 +volatile rel_time_t current_time;
  20 +
  21 +/** exported globals **/
  22 +struct stats stats;
  23 +struct settings settings;
22 internal_tests.c
... ... @@ -0,0 +1,22 @@
  1 +/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
  2 +
  3 +#include <assert.h>
  4 +#include <stdio.h>
  5 +#include <stdlib.h>
  6 +
  7 +#include "memcached.h"
  8 +
  9 +int main(int argc, char **argv) {
  10 + unsigned long long ull;
  11 + assert(safe_strtoull("123", &ull));
  12 + assert(ull == 123);
  13 +
  14 + // Empty:
  15 + assert(!safe_strtoull("", &ull));
  16 +
  17 + // Bogus:
  18 + assert(!safe_strtoull("123BOGUS", &ull));
  19 +
  20 + printf("OK.\n");
  21 + return 0;
  22 +}
4 memcached.h
@@ -24,7 +24,7 @@
24 24 #define UDP_MAX_PAYLOAD_SIZE 1400
25 25 #define UDP_HEADER_SIZE 8
26 26 #define MAX_SENDBUF_SIZE (256 * 1024 * 1024)
27   -/* I'm told the max legnth of a 64-bit num converted to string is 20 bytes.
  27 +/* I'm told the max length of a 64-bit num converted to string is 20 bytes.
28 28 * Plus a few for spaces, \r\n, \0 */
29 29 #define SUFFIX_SIZE 24
30 30
@@ -337,7 +337,7 @@ extern int daemonize(int nochdir, int noclose);
337 337 #include "items.h"
338 338 #include "trace.h"
339 339 #include "hash.h"
340   -
  340 +#include "util.h"
341 341
342 342 /*
343 343 * Functions such as the libevent-related calls that need to do cross-thread
16 util.c
... ... @@ -0,0 +1,16 @@
  1 +#include <stdlib.h>
  2 +#include <assert.h>
  3 +
  4 +#include "memcached.h"
  5 +
  6 +bool safe_strtoull(const char *str, unsigned long long *out) {
  7 + assert(out != NULL);
  8 + *out = 0;
  9 + char *endptr;
  10 + unsigned long long ull = strtoull(str, &endptr, 10);
  11 + if (*endptr == '\0' && endptr != str) {
  12 + *out = ull;
  13 + return true;
  14 + }
  15 + return false;
  16 +}
8 util.h
... ... @@ -0,0 +1,8 @@
  1 +/*
  2 + * str a NULL-terminated base decimal 10 unsigned integer
  3 + * out out parameter, if conversion succeeded
  4 + *
  5 + * returns true if conversion succeeded.
  6 + */
  7 +bool safe_strtoull(const char *str, unsigned long long *out);
  8 +

0 comments on commit 420aa2d

Please sign in to comment.
Something went wrong with that request. Please try again.