libmemcached的头文件

来源:互联网 发布:热电材料 知乎 编辑:程序博客网 时间:2024/05/17 07:39

一、第一部分

这一部分的头文件可以提供给外部client使用。

1、#include <libmemcached/memcached.h>

该文件被client包含,该文件中只是进一步#include <libmemcached-1.0/memcached.h>。

libmemcached-1.0/memcached.h:包含了libmemcached-1.0下的所有头文件,并包含libhashkit-1.0/hashkit.h。

#pragma once  //与#ifndef方式作用相同,但是#pragma once由编译器提供保障,但是如果一个文件有多个拷贝,不能保证不被重复包含。#include <inttypes.h>  //提供了各种位宽的整数类型输入输出时的转换标志宏#include <stdlib.h>#include <sys/types.h>#if !defined(__cplusplus)# include <stdbool.h>#endif#include <libmemcached-1.0/visibility.h>#include <libmemcached-1.0/configure.h>#include <libmemcached-1.0/platform.h>#include <libmemcached-1.0/limits.h>#include <libmemcached-1.0/defaults.h>#include <libmemcached-1.0/types/behavior.h>#include <libmemcached-1.0/types/callback.h>#include <libmemcached-1.0/types/connection.h>#include <libmemcached-1.0/types/hash.h>#include <libmemcached-1.0/types/return.h>#include <libmemcached-1.0/types/server_distribution.h>#include <libmemcached-1.0/return.h>#include <libmemcached-1.0/types.h>#include <libmemcached-1.0/callbacks.h>#include <libmemcached-1.0/alloc.h>#include <libmemcached-1.0/triggers.h>#include <libhashkit-1.0/hashkit.h>   //该文件包含了libhashkit-1.0下的所有头文件,并声明了一些接口#include <libmemcached-1.0/struct/callback.h>#include <libmemcached-1.0/struct/string.h>#include <libmemcached-1.0/struct/result.h>#include <libmemcached-1.0/struct/allocator.h>#include <libmemcached-1.0/struct/sasl.h>#include <libmemcached-1.0/struct/memcached.h>#include <libmemcached-1.0/struct/server.h>#include <libmemcached-1.0/struct/stat.h>#include <libmemcached-1.0/basic_string.h>#include <libmemcached-1.0/error.h>#include <libmemcached-1.0/stats.h>// Everything above this line must be in the order specified.#include <libmemcached-1.0/allocators.h>#include <libmemcached-1.0/analyze.h>#include <libmemcached-1.0/auto.h>#include <libmemcached-1.0/behavior.h>#include <libmemcached-1.0/callback.h>#include <libmemcached-1.0/delete.h>#include <libmemcached-1.0/dump.h>#include <libmemcached-1.0/exist.h>#include <libmemcached-1.0/fetch.h>#include <libmemcached-1.0/flush.h>#include <libmemcached-1.0/flush_buffers.h>#include <libmemcached-1.0/get.h>#include <libmemcached-1.0/hash.h>#include <libmemcached-1.0/options.h>#include <libmemcached-1.0/parse.h>#include <libmemcached-1.0/quit.h>#include <libmemcached-1.0/result.h>#include <libmemcached-1.0/server.h>#include <libmemcached-1.0/server_list.h>#include <libmemcached-1.0/storage.h>#include <libmemcached-1.0/strerror.h>#include <libmemcached-1.0/touch.h>#include <libmemcached-1.0/verbosity.h>#include <libmemcached-1.0/version.h>#include <libmemcached-1.0/sasl.h>#include <libmemcached-1.0/deprecated_types.h>#ifdef __cplusplusextern "C" {#endifLIBMEMCACHED_API                           //LIBMEMCACHED_API此处为空,定义于visibility.hvoid memcached_servers_reset(memcached_st *ptr);LIBMEMCACHED_APImemcached_st *memcached_create(memcached_st *ptr);         //这些接口都定义于memcached.cc中,除了memcached_server_count()LIBMEMCACHED_APImemcached_st *memcached(const char *string, size_t string_length);LIBMEMCACHED_APIvoid memcached_free(memcached_st *ptr);LIBMEMCACHED_APImemcached_return_t memcached_reset(memcached_st *ptr);LIBMEMCACHED_APIvoid memcached_reset_last_disconnected_server(memcached_st *ptr);LIBMEMCACHED_APImemcached_st *memcached_clone(memcached_st *clone, const memcached_st *ptr);LIBMEMCACHED_APIvoid *memcached_get_user_data(const memcached_st *ptr);LIBMEMCACHED_APIvoid *memcached_set_user_data(memcached_st *ptr, void *data);LIBMEMCACHED_APImemcached_return_t memcached_push(memcached_st *destination, const memcached_st *source);LIBMEMCACHED_APImemcached_server_instance_st memcached_server_instance_by_position(const memcached_st *ptr, uint32_t server_key);LIBMEMCACHED_APIuint32_t memcached_server_count(const memcached_st *);  //该接口定义于server.cc中LIBMEMCACHED_APIuint64_t memcached_query_id(const memcached_st *);#ifdef __cplusplus} // extern "C"#endif

2、libmemcached-1.0/memcached.hpp

#pragma once#include <libmemcached-1.0/memcached.h>    //其中也包含了class Memcache中会调用的函数的声明,如memcached_create()。#if 0#include <libmemcached/exception.hpp>#endif#include <string.h>#include <sstream>#include <string>#include <vector>#include <map>namespace memcache{/** * This is the core memcached library (if later, other objects * are needed, they will be created from this class). */class Memcache{public:  Memcache()  {    memc= memcached("", 0);  }  Memcache(const std::string &config)  {    memc= memcached(config.c_str(), config.size());  }  Memcache(const std::string &hostname, in_port_t port)  {    memc= memcached("", 0);    if (memc)      memcached_server_add(memc, hostname.c_str(), port);  }  Memcache(memcached_st *clone)  {    memc= memcached_clone(NULL, clone);  }  Memcache(const Memcache &rhs)  {    memc= memcached_clone(NULL, rhs.getImpl());  }  Memcache &operator=(const Memcache &rhs)  {    if (this != &rhs)    {      memcached_free(memc);      memc= memcached_clone(NULL, rhs.getImpl());    }    return *this;  }  ~Memcache()  {    memcached_free(memc);  }  ...  //多个成员函数private:  memcached_st *memc;};}

3、libhashkit-1.0/hashkit.hpp

#pragma once#include <libhashkit-1.0/hashkit.h>  //其中也包含了class Hashkit中将要调用的函数的声明,如hashkit_create()等。#include <string>class Hashkit {public:  Hashkit()  {    hashkit_create(&self);  }  Hashkit(const Hashkit& source)  {    hashkit_clone(&self, &source.self);  }  Hashkit& operator=(const Hashkit& source)  {    hashkit_free(&self);    hashkit_clone(&self, &source.self);    return *this;  }  friend bool operator==(const Hashkit &left, const Hashkit &right)  {    return hashkit_compare(&left.self, &right.self);  }  uint32_t digest(std::string& str)  {    return hashkit_digest(&self, str.c_str(), str.length());  }  uint32_t digest(const char *key, size_t key_length)  {    return hashkit_digest(&self, key, key_length);  }  hashkit_return_t set_function(hashkit_hash_algorithm_t hash_algorithm)  {    return hashkit_set_function(&self, hash_algorithm);  }  hashkit_return_t set_distribution_function(hashkit_hash_algorithm_t hash_algorithm)  {    return hashkit_set_function(&self, hash_algorithm);  }  ~Hashkit()  {    hashkit_free(&self);  }private:  hashkit_st self;};

二、第二部分

common.h都是作为内部头文件使用。

4、libmemcached/common.h

被包含于libmemcached/memcached.cc中,基本上将整个框架都包含了。

#pragma once#include <config.h>   #ifdef __cplusplus#include <cstdio>#include <cstdlib>#include <cstring>#include <ctime>#include <ctype.h>#else#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#endif#include <errno.h>#include <fcntl.h>#include <limits.h>#include <sys/types.h>#include <unistd.h>#ifdef HAVE_STRINGS_H#include <strings.h>#endif#include <libmemcached-1.0/memcached.h>    //对外可见的头文件#include <libmemcached/watchpoint.h>#include <libmemcached/is.h>#include <libmemcached/server_instance.h>#ifdef HAVE_POLL_H#include <poll.h>#else#include "poll/poll.h"#endif#ifdef __cplusplusextern "C" {#endiftypedef memcached_return_t (*memcached_server_execute_fn)(memcached_st *ptr, memcached_server_write_instance_st server, void *context);LIBMEMCACHED_LOCALmemcached_server_write_instance_st memcached_server_instance_fetch(memcached_st *ptr, uint32_t server_key);LIBMEMCACHED_LOCALmemcached_return_t memcached_server_execute(memcached_st *ptr,                                            memcached_server_execute_fn callback,                                            void *context);#ifdef __cplusplus} // extern "C"#endif/* These are private not to be installed headers */#include <libmemcached/error.hpp>#include <libmemcached/memory.h>#include <libmemcached/io.h>#ifdef __cplusplus#include <libmemcached/string.hpp>#include <libmemcached/io.hpp>#include <libmemcached/udp.hpp>#include <libmemcached/do.hpp>#include <libmemcached/close_socket.hpp>#include <libmemcached/connect.hpp>#include <libmemcached/allocators.hpp>#include <libmemcached/hash.hpp>#include <libmemcached/quit.hpp>#include <libmemcached/server.hpp>#include <libmemcached/behavior.hpp>#include <libmemcached/sasl.hpp>#include <libmemcached/server_list.hpp>#endif#include <libmemcached/internal.h>#include <libmemcached/array.h>#include <libmemcached/libmemcached_probes.h>#include <libmemcached/memcached/protocol_binary.h>#include <libmemcached/byteorder.h>#include <libmemcached/initialize_query.h>#ifdef __cplusplus#include <libmemcached/response.h>#endif#include <libmemcached/namespace.h>#include <libmemcached/virtual_bucket.h>#ifdef __cplusplus#include <libmemcached/backtrace.hpp>#include <libmemcached/assert.hpp>#include <libmemcached/server.hpp>#include <libmemcached/key.hpp>#endif#include <libmemcached/continuum.hpp>#if !defined(__GNUC__) || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)#define likely(x)       if((x))#define unlikely(x)     if((x))#else#define likely(x)       if(__builtin_expect((x) != 0, 1))#define unlikely(x)     if(__builtin_expect((x) != 0, 0))#endif#define MEMCACHED_BLOCK_SIZE 1024#define MEMCACHED_DEFAULT_COMMAND_SIZE 350#define SMALL_STRING_LEN 1024#define HUGE_STRING_LEN 8196...                           //若干接口

5、libhashkit/common.h

#pragma once#include <config.h>#include <assert.h>#include <errno.h>#include <stdio.h>#include <stdlib.h>#include <math.h>#include <libhashkit-1.0/hashkit.h> //该文件包含了文件夹libhashkit-1.0下的所有头文件,并声明了一些接口#include <libhashkit/is.h>#ifdef __cplusplusextern "C" {#endifHASHKIT_LOCALvoid md5_signature(const unsigned char *key, unsigned int length, unsigned char *result);HASHKIT_LOCALint update_continuum(hashkit_st *hashkit);#ifdef __cplusplus}#endif

三、其他

1、libmemcached/util.h(作为对外头文件)

该头文件只是包含libmemcachedutil-1.0/util.h,这一点与libmemcached/memcached.h的作用类似。

#pragma once                          //可以看出util.h这个文件可以给client提供一些函数接口#include <libmemcached-1.0/memcached.h>#include <libmemcachedutil-1.0/pid.h>     //这些头文件都是包含了一些函数声明#include <libmemcachedutil-1.0/flush.h>#include <libmemcachedutil-1.0/ping.h>#include <libmemcachedutil-1.0/pool.h>#include <libmemcachedutil-1.0/version.h>
libmemcachedutil-1.0文件夹下还有一个ostream.hpp:

#pragma oncestatic inline std::ostream& operator<<(std::ostream& output, const enum memcached_return_t &arg){  output << memcached_strerror(NULL, arg);  return output;}

2、libmemcachedutil/common.h(内部使用)

#pragma once#include <config.h>#include <libmemcachedutil-1.0/util.h>#include <libmemcached/assert.hpp>#include <libmemcached/backtrace.hpp>