*.output
*.pop
*.rej
+*.bak
*TAGS
*patch
.cproject
${FLEX_CSL_SCANNER_OUTPUTS}
allocators.cc
analyze.cc
- array.c
+ array.cc
auto.cc
backtrace.cc
behavior.cc
udp.cc
verbosity.cc
version.cc
- virtual_bucket.c)
+ virtual_bucket.cc)
check_cxx_compiler_flag(-Wno-deprecated-register W_NO_DEPRECATED_REGISTER)
+++ /dev/null
-/*
- +--------------------------------------------------------------------+
- | libmemcached - C/C++ Client Library for memcached |
- +--------------------------------------------------------------------+
- | Redistribution and use in source and binary forms, with or without |
- | modification, are permitted under the terms of the BSD license. |
- | You should have received a copy of the license in a bundled file |
- | named LICENSE; in case you did not receive a copy you can review |
- | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
- +--------------------------------------------------------------------+
- | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
- | Copyright (c) 2020 Michael Wallner <mike@php.net> |
- +--------------------------------------------------------------------+
-*/
-
-#include "libmemcached/common.h"
-#include <assert.h>
-#include <iso646.h>
-
-struct memcached_array_st {
- Memcached *root;
- size_t size;
- char c_str[];
-};
-
-memcached_array_st *memcached_array_clone(Memcached *memc, const memcached_array_st *original) {
- if (original) {
- return memcached_strcpy(memc, original->c_str, original->size);
- }
-
- return NULL;
-}
-
-memcached_array_st *memcached_strcpy(Memcached *memc, const char *str, size_t str_length) {
- assert(memc);
- assert(str);
- assert(str_length);
-
- memcached_array_st *array = (struct memcached_array_st *) libmemcached_malloc(
- memc, sizeof(struct memcached_array_st) + str_length + 1);
-
- if (array) {
- array->root = memc;
- array->size = str_length; // We don't count the NULL ending
- memcpy(array->c_str, str, str_length);
- array->c_str[str_length] = 0;
- }
-
- return array;
-}
-
-bool memcached_array_is_null(memcached_array_st *array) {
- if (array) {
- return false;
- }
-
- return true;
-}
-
-memcached_string_t memcached_array_to_string(memcached_array_st *array) {
- assert(array);
- assert(array->c_str);
- assert(array->size);
- memcached_string_t tmp;
- tmp.c_str = array->c_str;
- tmp.size = array->size;
-
- return tmp;
-}
-
-void memcached_array_free(memcached_array_st *array) {
- if (array) {
- WATCHPOINT_ASSERT(array->root);
- libmemcached_free(array->root, array);
- }
-}
-
-size_t memcached_array_size(memcached_array_st *array) {
- if (array) {
- return array->size;
- }
-
- return 0;
-}
-
-const char *memcached_array_string(memcached_array_st *array) {
- if (array) {
- return array->c_str;
- }
-
- return NULL;
-}
--- /dev/null
+/*
+ +--------------------------------------------------------------------+
+ | libmemcached - C/C++ Client Library for memcached |
+ +--------------------------------------------------------------------+
+ | Redistribution and use in source and binary forms, with or without |
+ | modification, are permitted under the terms of the BSD license. |
+ | You should have received a copy of the license in a bundled file |
+ | named LICENSE; in case you did not receive a copy you can review |
+ | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
+ +--------------------------------------------------------------------+
+ | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
+ | Copyright (c) 2020 Michael Wallner <mike@php.net> |
+ +--------------------------------------------------------------------+
+*/
+
+#include "libmemcached/common.h"
+
+#include <cassert>
+
+struct memcached_array_st {
+ Memcached *root;
+ size_t size;
+ char c_str[];
+};
+
+memcached_array_st *memcached_array_clone(Memcached *memc, const memcached_array_st *original) {
+ if (original) {
+ return memcached_strcpy(memc, original->c_str, original->size);
+ }
+
+ return NULL;
+}
+
+memcached_array_st *memcached_strcpy(Memcached *memc, const char *str, size_t str_length) {
+ assert(memc);
+ assert(str);
+ assert(str_length);
+
+ memcached_array_st *array = (struct memcached_array_st *) libmemcached_malloc(
+ memc, sizeof(struct memcached_array_st) + str_length + 1);
+
+ if (array) {
+ array->root = memc;
+ array->size = str_length; // We don't count the NULL ending
+ memcpy(array->c_str, str, str_length);
+ array->c_str[str_length] = 0;
+ }
+
+ return array;
+}
+
+bool memcached_array_is_null(memcached_array_st *array) {
+ if (array) {
+ return false;
+ }
+
+ return true;
+}
+
+memcached_string_t memcached_array_to_string(memcached_array_st *array) {
+ assert(array);
+ assert(array->c_str);
+ assert(array->size);
+ memcached_string_t tmp;
+ tmp.c_str = array->c_str;
+ tmp.size = array->size;
+
+ return tmp;
+}
+
+void memcached_array_free(memcached_array_st *array) {
+ if (array) {
+ WATCHPOINT_ASSERT(array->root);
+ libmemcached_free(array->root, array);
+ }
+}
+
+size_t memcached_array_size(memcached_array_st *array) {
+ if (array) {
+ return array->size;
+ }
+
+ return 0;
+}
+
+const char *memcached_array_string(memcached_array_st *array) {
+ if (array) {
+ return array->c_str;
+ }
+
+ return NULL;
+}
+++ /dev/null
-/*
- +--------------------------------------------------------------------+
- | libmemcached - C/C++ Client Library for memcached |
- +--------------------------------------------------------------------+
- | Redistribution and use in source and binary forms, with or without |
- | modification, are permitted under the terms of the BSD license. |
- | You should have received a copy of the license in a bundled file |
- | named LICENSE; in case you did not receive a copy you can review |
- | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
- +--------------------------------------------------------------------+
- | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
- | Copyright (c) 2020 Michael Wallner <mike@php.net> |
- +--------------------------------------------------------------------+
-*/
-
-#include "libmemcached/common.h"
-
-struct bucket_t {
- uint32_t master;
- uint32_t forward;
-};
-
-struct memcached_virtual_bucket_t {
- bool has_forward;
- uint32_t size;
- uint32_t replicas;
- struct bucket_t buckets[];
-};
-
-memcached_return_t memcached_virtual_bucket_create(memcached_st *self, const uint32_t *host_map,
- const uint32_t *forward_map,
- const uint32_t buckets,
- const uint32_t replicas) {
- if (self == NULL || host_map == NULL || buckets == 0U) {
- return MEMCACHED_INVALID_ARGUMENTS;
- }
-
- memcached_virtual_bucket_free(self);
-
- struct memcached_virtual_bucket_t *virtual_bucket = (struct memcached_virtual_bucket_t *) malloc(
- sizeof(struct memcached_virtual_bucket_t) + sizeof(struct bucket_t) * buckets);
-
- if (virtual_bucket == NULL) {
- return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
- }
-
- virtual_bucket->size = buckets;
- virtual_bucket->replicas = replicas;
- self->virtual_bucket = virtual_bucket;
-
- uint32_t x = 0;
- for (; x < buckets; x++) {
- virtual_bucket->buckets[x].master = host_map[x];
- if (forward_map) {
- virtual_bucket->buckets[x].forward = forward_map[x];
- } else {
- virtual_bucket->buckets[x].forward = 0;
- }
- }
-
- return MEMCACHED_SUCCESS;
-}
-
-void memcached_virtual_bucket_free(memcached_st *self) {
- if (self) {
- if (self->virtual_bucket) {
- free(self->virtual_bucket);
- self->virtual_bucket = NULL;
- }
- }
-}
-
-uint32_t memcached_virtual_bucket_get(const memcached_st *self, uint32_t digest) {
- if (self) {
- if (self->virtual_bucket) {
- uint32_t result = (uint32_t)(digest & (self->virtual_bucket->size - 1));
- return self->virtual_bucket->buckets[result].master;
- }
-
- return (uint32_t)(digest & (self->number_of_hosts - 1));
- }
-
- return 0;
-}
--- /dev/null
+/*
+ +--------------------------------------------------------------------+
+ | libmemcached - C/C++ Client Library for memcached |
+ +--------------------------------------------------------------------+
+ | Redistribution and use in source and binary forms, with or without |
+ | modification, are permitted under the terms of the BSD license. |
+ | You should have received a copy of the license in a bundled file |
+ | named LICENSE; in case you did not receive a copy you can review |
+ | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
+ +--------------------------------------------------------------------+
+ | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
+ | Copyright (c) 2020 Michael Wallner <mike@php.net> |
+ +--------------------------------------------------------------------+
+*/
+
+#include "libmemcached/common.h"
+#include "libmemcached/virtual_bucket.h"
+
+struct bucket_t {
+ uint32_t master;
+ uint32_t forward;
+};
+
+struct memcached_virtual_bucket_t {
+ bool has_forward;
+ uint32_t size;
+ uint32_t replicas;
+ struct bucket_t buckets[];
+};
+
+memcached_return_t memcached_virtual_bucket_create(memcached_st *self, const uint32_t *host_map,
+ const uint32_t *forward_map,
+ const uint32_t buckets,
+ const uint32_t replicas) {
+ if (self == NULL || host_map == NULL || buckets == 0U) {
+ return MEMCACHED_INVALID_ARGUMENTS;
+ }
+
+ memcached_virtual_bucket_free(self);
+
+ struct memcached_virtual_bucket_t *virtual_bucket = (struct memcached_virtual_bucket_t *) malloc(
+ sizeof(struct memcached_virtual_bucket_t) + sizeof(struct bucket_t) * buckets);
+
+ if (virtual_bucket == NULL) {
+ return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
+ }
+
+ virtual_bucket->size = buckets;
+ virtual_bucket->replicas = replicas;
+ self->virtual_bucket = virtual_bucket;
+
+ uint32_t x = 0;
+ for (; x < buckets; x++) {
+ virtual_bucket->buckets[x].master = host_map[x];
+ if (forward_map) {
+ virtual_bucket->buckets[x].forward = forward_map[x];
+ } else {
+ virtual_bucket->buckets[x].forward = 0;
+ }
+ }
+
+ return MEMCACHED_SUCCESS;
+}
+
+void memcached_virtual_bucket_free(memcached_st *self) {
+ if (self) {
+ if (self->virtual_bucket) {
+ free(self->virtual_bucket);
+ self->virtual_bucket = NULL;
+ }
+ }
+}
+
+uint32_t memcached_virtual_bucket_get(const memcached_st *self, uint32_t digest) {
+ if (self) {
+ if (self->virtual_bucket) {
+ uint32_t result = (uint32_t)(digest & (self->virtual_bucket->size - 1));
+ return self->virtual_bucket->buckets[result].master;
+ }
+
+ return (uint32_t)(digest & (self->number_of_hosts - 1));
+ }
+
+ return 0;
+}
if(NOT HAVE_GETOPT_H)
target_sources(p9y PRIVATE getopt.c)
endif()
-if(NOT HAVE_LIBGEN_H)
- target_sources(p9y PRIVATE libgen.c)
-endif()
-if(NOT HAVE_REALPATH)
- target_sources(p9y PRIVATE realpath.c)
-endif()
-if(WIN32)
- target_sources(p9y PRIVATE socket.c)
-endif()
-if(NOT HAVE_POLL_H AND NOT HAVE_SYS_POLL_H AND NOT WIN32)
- target_sources(p9y PRIVATE poll.c)
-endif()
-if(NOT HAVE_GETTIMEOFDAY)
- target_sources(p9y PRIVATE gettimeofday.cpp)
-endif()
+++ /dev/null
-#include "gettimeofday.hpp"
-
-#include <chrono>
-
-#if !defined HAVE_GETTIMEOFDAY
-int gettimeofday(struct timeval* tp, struct timezone*) {
- using clock = std::chrono::system_clock;
- auto as_sec = [] (auto d) {
- return std::chrono::duration_cast<std::chrono::seconds>(d);
- };
- auto as_usec = [] (auto d) {
- return std::chrono::duration_cast<std::chrono::microseconds>(d);
- };
-
- auto now = clock::now().time_since_epoch();
- auto sec = as_sec(now);
- auto usec = as_usec(now - sec);
-
- tp->tv_sec = sec.count();
- tp->tv_usec = usec.count();
- return 0;
-}
-#endif
#include "libmemcached-1/platform.h"
-#include <time.h>
+#if defined __cplusplus
+# include <ctime>
+#else
+# include <time.h>
+#endif
+
#if defined HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
#if !defined HAVE_GETTIMEOFDAY
+# define P9Y_NEED_GETTIMEOFDAY
+#endif
+
+#if defined P9Y_NEED_GETTIMEOFDAY
+# if defined __cplusplus
+extern "C" {
+# endif
int gettimeofday(struct timeval* tp, struct timezone* tzp);
+# if defined __cplusplus
+};
+#endif
#endif
+++ /dev/null
-#include "libgen.hpp"
-
-#if defined _WIN32
-char *basename(const char *filename) {
- static char base[_MAX_PATH * 2], ext[_MAX_PATH], *ptr;
- (void) _splitpath_s(filename, NULL, 0, NULL, 0, base, _MAX_PATH, ext, _MAX_PATH);
- strcat_s(base, _MAX_PATH * 2 - 1, ext);
- return base;
-}
-#endif
+#pragma once
#include "mem_config.h"
#if defined HAVE_LIBGEN_H
# include <libgen.h>
#elif defined _WIN32
-# if defined __cplusplus
+# if defined __cplusplus
extern "C" {
-# endif
+# endif
+# define P9Y_NEED_BASENAME
char *basename(const char *filename);
-# if defined __cplusplus
+# if defined __cplusplus
}
-# endif
+# endif
#endif // HAVE_LIBGEN_H
-// empty stub
+#include "libgen.hpp"
+#if defined P9Y_NEED_BASENAME
+# if defined _WIN32
+char *basename(const char *filename) {
+ static char base[_MAX_PATH * 2], ext[_MAX_PATH], *ptr;
+ (void) _splitpath_s(filename, NULL, 0, NULL, 0, base, _MAX_PATH, ext, _MAX_PATH);
+ strcat_s(base, _MAX_PATH * 2 - 1, ext);
+ return base;
+}
+# endif // _WIN32
+#endif // P9Y_NEED_BASENAME
+
+#include "realpath.hpp"
+#if defined P9Y_NEED_REALPATH
+# if defined _WIN32
+char *realpath(const char *path, char real[_MAX_PATH]) {
+ return _fullpath(real, path, _MAX_PATH);
+}
+# endif // _WIN32
+#endif // P9Y_NEED_REALPATH
+
+#include "gettimeofday.hpp"
+#if defined P9Y_NEED_GETTIMEOFDAY
+# include <chrono>
+int gettimeofday(struct timeval* tp, struct timezone*) {
+ using clock = std::chrono::system_clock;
+ auto as_sec = [] (auto d) {
+ return std::chrono::duration_cast<std::chrono::seconds>(d);
+ };
+ auto as_usec = [] (auto d) {
+ return std::chrono::duration_cast<std::chrono::microseconds>(d);
+ };
+
+ auto now = clock::now().time_since_epoch();
+ auto sec = as_sec(now);
+ auto usec = as_usec(now - sec);
+
+ tp->tv_sec = sec.count();
+ tp->tv_usec = usec.count();
+ return 0;
+}
+#endif // P9Y_NEED_GETTIMEOFDAY
+
+#include "socket.hpp"
+#if defined P9Y_NEED_GET_SOCKET_ERRNO
+# if defined _WIN32
+int get_socket_errno() {
+ int local_errno = WSAGetLastError();
+
+ switch (local_errno) {
+ case WSAEINVAL:
+ local_errno = EINPROGRESS;
+ break;
+ case WSAEALREADY:
+ case WSAEWOULDBLOCK:
+ local_errno = EAGAIN;
+ break;
+
+ case WSAECONNREFUSED:
+ local_errno = ECONNREFUSED;
+ break;
+
+ case WSAENETUNREACH:
+ local_errno = ENETUNREACH;
+ break;
+
+ case WSAETIMEDOUT:
+ local_errno = ETIMEDOUT;
+ break;
+
+ case WSAECONNRESET:
+ local_errno = ECONNRESET;
+ break;
+
+ case WSAEADDRINUSE:
+ local_errno = EADDRINUSE;
+ break;
+
+ case WSAEOPNOTSUPP:
+ local_errno = EOPNOTSUPP;
+ break;
+
+ case WSAENOPROTOOPT:
+ local_errno = ENOPROTOOPT;
+ break;
+
+ default:
+ break;
+ }
+
+ return local_errno;
+}
+# endif // _WIN32
+#endif // P9Y_NEED_GET_SOCKET_ERRNO
+
+#include "poll.hpp"
+#if defined P9Y_NEED_POLL
+int poll(struct pollfd fds[], nfds_t nfds, int tmo) {
+ fd_set readfds, writefds, errorfds;
+ FD_ZERO(&readfds);
+ FD_ZERO(&writefds);
+ FD_ZERO(&errorfds);
+
+ int maxfd = 0;
+
+ for (nfds_t x = 0; x < nfds; ++x) {
+ if (fds[x].events & (POLLIN | POLLOUT)) {
+# ifndef _WIN32
+ if (fds[x].fd > maxfd) {
+ maxfd = fds[x].fd;
+ }
+# endif
+ if (fds[x].events & POLLIN) {
+ FD_SET(fds[x].fd, &readfds);
+ }
+ if (fds[x].events & POLLOUT) {
+ FD_SET(fds[x].fd, &writefds);
+ }
+ }
+ }
+
+ struct timeval timeout = {tmo / 1000, (tmo % 1000) * 1000};
+ struct timeval *tp = &timeout;
+ if (tmo == -1) {
+ tp = NULL;
+ }
+ int ret = select(maxfd + 1, &readfds, &writefds, &errorfds, tp);
+ if (ret <= 0) {
+ return ret;
+ }
+
+ /* Iterate through all of them because I need to clear the revent map */
+ for (nfds_t x = 0; x < nfds; ++x) {
+ fds[x].revents = 0;
+ if (FD_ISSET(fds[x].fd, &readfds)) {
+ fds[x].revents |= POLLIN;
+ }
+ if (FD_ISSET(fds[x].fd, &writefds)) {
+ fds[x].revents |= POLLOUT;
+ }
+ if (FD_ISSET(fds[x].fd, &errorfds)) {
+ fds[x].revents |= POLLERR;
+ }
+ }
+
+ return ret;
+}
+#endif // P9Y_NEED_POLL
+++ /dev/null
-#include "poll.hpp"
-
-#if defined P9Y_NEED_POLL
-
-int poll(struct pollfd fds[], nfds_t nfds, int tmo) {
- fd_set readfds, writefds, errorfds;
- FD_ZERO(&readfds);
- FD_ZERO(&writefds);
- FD_ZERO(&errorfds);
-
- int maxfd = 0;
-
- for (nfds_t x = 0; x < nfds; ++x) {
- if (fds[x].events & (POLLIN | POLLOUT)) {
-# ifndef _WIN32
- if (fds[x].fd > maxfd) {
- maxfd = fds[x].fd;
- }
-# endif
- if (fds[x].events & POLLIN) {
- FD_SET(fds[x].fd, &readfds);
- }
- if (fds[x].events & POLLOUT) {
- FD_SET(fds[x].fd, &writefds);
- }
- }
- }
-
- struct timeval timeout = {tmo / 1000, (tmo % 1000) * 1000};
- struct timeval *tp = &timeout;
- if (tmo == -1) {
- tp = NULL;
- }
- int ret = select(maxfd + 1, &readfds, &writefds, &errorfds, tp);
- if (ret <= 0) {
- return ret;
- }
-
- /* Iterate through all of them because I need to clear the revent map */
- for (nfds_t x = 0; x < nfds; ++x) {
- fds[x].revents = 0;
- if (FD_ISSET(fds[x].fd, &readfds)) {
- fds[x].revents |= POLLIN;
- }
- if (FD_ISSET(fds[x].fd, &writefds)) {
- fds[x].revents |= POLLOUT;
- }
- if (FD_ISSET(fds[x].fd, &errorfds)) {
- fds[x].revents |= POLLERR;
- }
- }
-
- return ret;
-}
-
-#endif // P9Y_NEED_POLL
+++ /dev/null
-#include "realpath.hpp"
-
-#if defined _WIN32
-char *realpath(const char *path, char real[_MAX_PATH]) {
- return _fullpath(real, path, _MAX_PATH);
-}
-#endif
#endif
#if !defined HAVE_REALPATH
-# if defined _WIN32
-# if defined __cplusplus
+# define P9Y_NEED_REALPATH
+# if defined __cplusplus
extern "C" {
-# endif
+# endif
char *realpath(const char *path, char real[_MAX_PATH]);
-# if defined __cplusplus
+# if defined __cplusplus
}
-# endif
-# endif // _WIN32
+# endif
#endif // HAVE_REALPATH
+++ /dev/null
-#include "socket.hpp"
-
-#if defined _WIN32
-int get_socket_errno() {
- int local_errno = WSAGetLastError();
-
- switch (local_errno) {
- case WSAEINVAL:
- local_errno = EINPROGRESS;
- break;
- case WSAEALREADY:
- case WSAEWOULDBLOCK:
- local_errno = EAGAIN;
- break;
-
- case WSAECONNREFUSED:
- local_errno = ECONNREFUSED;
- break;
-
- case WSAENETUNREACH:
- local_errno = ENETUNREACH;
- break;
-
- case WSAETIMEDOUT:
- local_errno = ETIMEDOUT;
- break;
-
- case WSAECONNRESET:
- local_errno = ECONNRESET;
- break;
-
- case WSAEADDRINUSE:
- local_errno = EADDRINUSE;
- break;
-
- case WSAEOPNOTSUPP:
- local_errno = EOPNOTSUPP;
- break;
-
- case WSAENOPROTOOPT:
- local_errno = ENOPROTOOPT;
- break;
-
- default:
- break;
- }
-
- return local_errno;
-}
-#endif // _WIN32
#endif
# if defined _WIN32
+# define P9Y_NEED_GET_SOCKET_ERRNO
int get_socket_errno();
# define SHUT_WR SD_SEND
# define SHUT_RD SD_RECEIVE