forked from cheekyguy/memcached
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: http://svn.facebook.com/svnroot/projects/memcached/branches/memcached-storage@86243 2c7ba8d8-a2f7-0310-a573-de162e16dcc7
- Loading branch information
ttung
committed
Mar 5, 2008
1 parent
f78bf14
commit 045594e
Showing
2 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ | ||
/** | ||
* this file defines types that are used in multiple places, yet don't belong to | ||
* any one particular module. | ||
*/ | ||
|
||
#if !defined(_generic_h_) | ||
#define _generic_h_ | ||
|
||
#ifdef HAVE_CONFIG_H | ||
#include "config.h" | ||
#endif | ||
|
||
/** Time relative to server start. Smaller than time_t on 64-bit systems. */ | ||
typedef unsigned int rel_time_t; | ||
|
||
/* Get a consistent bool type */ | ||
#if HAVE_STDBOOL_H | ||
# include <stdbool.h> | ||
#else | ||
typedef enum {false = 0, true = 1} bool; | ||
#endif | ||
|
||
#if HAVE_STDINT_H | ||
# include <stdint.h> | ||
#else | ||
typedef unsigned char uint8_t; | ||
#endif | ||
|
||
#if __WORDSIZE == 64 | ||
#define PRINTF_INT64_MODIFIER "l" | ||
#else | ||
#define PRINTF_INT64_MODIFIER "ll" | ||
#endif | ||
|
||
/* | ||
* IOV_MAX comes from stdio.h. make sure we include it before we try to define | ||
* it ourselves. | ||
*/ | ||
/* need this to get IOV_MAX on some platforms. */ | ||
#ifndef __need_IOV_MAX | ||
#define __need_IOV_MAX | ||
#endif | ||
|
||
#include <stdio.h> | ||
|
||
/* FreeBSD 4.x doesn't have IOV_MAX exposed. */ | ||
#ifndef IOV_MAX | ||
#if defined(__FreeBSD__) | ||
# define IOV_MAX 1024 | ||
#endif | ||
#endif | ||
|
||
#endif /* #if !defined(_generic_h_) */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ | ||
|
||
#if !defined(_items_support_h_) | ||
#define _items_support_h_ | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "memcached.h" | ||
#include "generic.h" | ||
|
||
#define ITEM_data(item) ((char*) &((item)->end) + (item)->nkey + 1) | ||
|
||
static inline int item_strncmp(const item* it, size_t offset, const char* ref, size_t bytes) | ||
{ | ||
return strncmp(ITEM_data(it) + offset, ref, bytes); | ||
} | ||
|
||
static inline int add_item_to_iov(conn *c, const item* it, bool send_cr_lf) | ||
{ | ||
if (send_cr_lf) { | ||
return add_iov(c, ITEM_data(it), it->nbytes, false); | ||
} else { | ||
return add_iov(c, ITEM_data(it), it->nbytes - 2, false); | ||
} | ||
} | ||
|
||
static inline unsigned int item_get_max_riov(void) | ||
{ | ||
return 1; | ||
} | ||
|
||
static inline size_t item_setup_receive(item* it, struct iovec* iov, bool expect_cr_lf) | ||
{ | ||
iov->iov_base = ITEM_data(it); | ||
if (expect_cr_lf) { | ||
iov->iov_len = it->nbytes; | ||
} else { | ||
iov->iov_len = it->nbytes - 2; | ||
} | ||
|
||
return 1; | ||
} | ||
|
||
static inline int item_strtoul(const item* it, int base) | ||
{ | ||
return strtoul(ITEM_data(it), NULL, base); | ||
} | ||
|
||
static inline void* item_memcpy_to(const item* it, size_t offset, const void* src, size_t nbytes) | ||
{ | ||
return memcpy(ITEM_data(it) + offset, src, nbytes); | ||
} | ||
|
||
static inline void* item_memset(const item* it, size_t offset, int c, size_t nbytes) | ||
{ | ||
return memset(ITEM_data(it) + offset, c, nbytes); | ||
} | ||
|
||
// undefine the macro to resist catch inappropriate use of the macro. | ||
#undef ITEM_data | ||
|
||
#endif /* #if !defined(_items_support_h_) */ |