From 7781e7d0bf9fc0d986308838a3e1e47d0df3c019 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Fri, 18 Dec 2020 14:12:38 +0100 Subject: [PATCH] consolidate --- .gitignore | 1 + src/libmemcached/CMakeLists.txt | 4 +- src/libmemcached/{array.c => array.cc} | 4 +- .../{virtual_bucket.c => virtual_bucket.cc} | 1 + src/p9y/CMakeLists.txt | 15 -- src/p9y/gettimeofday.cpp | 23 --- src/p9y/gettimeofday.hpp | 17 +- src/p9y/libgen.c | 10 -- src/p9y/libgen.hpp | 10 +- src/p9y/p9y.cpp | 149 +++++++++++++++++- src/p9y/poll.c | 56 ------- src/p9y/realpath.c | 7 - src/p9y/realpath.hpp | 11 +- src/p9y/socket.c | 50 ------ src/p9y/socket.hpp | 1 + 15 files changed, 182 insertions(+), 177 deletions(-) rename src/libmemcached/{array.c => array.cc} (98%) rename src/libmemcached/{virtual_bucket.c => virtual_bucket.cc} (98%) delete mode 100644 src/p9y/gettimeofday.cpp delete mode 100644 src/p9y/libgen.c delete mode 100644 src/p9y/poll.c delete mode 100644 src/p9y/realpath.c delete mode 100644 src/p9y/socket.c diff --git a/.gitignore b/.gitignore index 47dcabb5..e2a11407 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.output *.pop *.rej +*.bak *TAGS *patch .cproject diff --git a/src/libmemcached/CMakeLists.txt b/src/libmemcached/CMakeLists.txt index 51d2dd18..c688c7b9 100644 --- a/src/libmemcached/CMakeLists.txt +++ b/src/libmemcached/CMakeLists.txt @@ -28,7 +28,7 @@ set(LIBMEMCACHED_SOURCES ${FLEX_CSL_SCANNER_OUTPUTS} allocators.cc analyze.cc - array.c + array.cc auto.cc backtrace.cc behavior.cc @@ -72,7 +72,7 @@ set(LIBMEMCACHED_SOURCES udp.cc verbosity.cc version.cc - virtual_bucket.c) + virtual_bucket.cc) check_cxx_compiler_flag(-Wno-deprecated-register W_NO_DEPRECATED_REGISTER) diff --git a/src/libmemcached/array.c b/src/libmemcached/array.cc similarity index 98% rename from src/libmemcached/array.c rename to src/libmemcached/array.cc index a93b3071..176005cf 100644 --- a/src/libmemcached/array.c +++ b/src/libmemcached/array.cc @@ -14,8 +14,8 @@ */ #include "libmemcached/common.h" -#include -#include + +#include struct memcached_array_st { Memcached *root; diff --git a/src/libmemcached/virtual_bucket.c b/src/libmemcached/virtual_bucket.cc similarity index 98% rename from src/libmemcached/virtual_bucket.c rename to src/libmemcached/virtual_bucket.cc index 40c3fad0..2c9a3dd3 100644 --- a/src/libmemcached/virtual_bucket.c +++ b/src/libmemcached/virtual_bucket.cc @@ -14,6 +14,7 @@ */ #include "libmemcached/common.h" +#include "libmemcached/virtual_bucket.h" struct bucket_t { uint32_t master; diff --git a/src/p9y/CMakeLists.txt b/src/p9y/CMakeLists.txt index 1734f0b7..9d953ad0 100644 --- a/src/p9y/CMakeLists.txt +++ b/src/p9y/CMakeLists.txt @@ -19,18 +19,3 @@ target_include_directories(p9y PRIVATE 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() diff --git a/src/p9y/gettimeofday.cpp b/src/p9y/gettimeofday.cpp deleted file mode 100644 index 7d002ca8..00000000 --- a/src/p9y/gettimeofday.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "gettimeofday.hpp" - -#include - -#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(d); - }; - auto as_usec = [] (auto d) { - return std::chrono::duration_cast(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 diff --git a/src/p9y/gettimeofday.hpp b/src/p9y/gettimeofday.hpp index aaba58bb..93452b66 100644 --- a/src/p9y/gettimeofday.hpp +++ b/src/p9y/gettimeofday.hpp @@ -2,11 +2,26 @@ #include "libmemcached-1/platform.h" -#include +#if defined __cplusplus +# include +#else +# include +#endif + #if defined HAVE_SYS_TIME_H # include #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 diff --git a/src/p9y/libgen.c b/src/p9y/libgen.c deleted file mode 100644 index 70696eb7..00000000 --- a/src/p9y/libgen.c +++ /dev/null @@ -1,10 +0,0 @@ -#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 diff --git a/src/p9y/libgen.hpp b/src/p9y/libgen.hpp index 82976d7e..264c4624 100644 --- a/src/p9y/libgen.hpp +++ b/src/p9y/libgen.hpp @@ -1,3 +1,4 @@ +#pragma once #include "mem_config.h" @@ -10,11 +11,12 @@ #if defined HAVE_LIBGEN_H # include #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 diff --git a/src/p9y/p9y.cpp b/src/p9y/p9y.cpp index 35ee8f01..1c5c4ac9 100644 --- a/src/p9y/p9y.cpp +++ b/src/p9y/p9y.cpp @@ -1 +1,148 @@ -// 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 +int gettimeofday(struct timeval* tp, struct timezone*) { + using clock = std::chrono::system_clock; + auto as_sec = [] (auto d) { + return std::chrono::duration_cast(d); + }; + auto as_usec = [] (auto d) { + return std::chrono::duration_cast(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 diff --git a/src/p9y/poll.c b/src/p9y/poll.c deleted file mode 100644 index b745c8be..00000000 --- a/src/p9y/poll.c +++ /dev/null @@ -1,56 +0,0 @@ -#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 diff --git a/src/p9y/realpath.c b/src/p9y/realpath.c deleted file mode 100644 index cf6430a2..00000000 --- a/src/p9y/realpath.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "realpath.hpp" - -#if defined _WIN32 -char *realpath(const char *path, char real[_MAX_PATH]) { - return _fullpath(real, path, _MAX_PATH); -} -#endif diff --git a/src/p9y/realpath.hpp b/src/p9y/realpath.hpp index ed63cfac..04b6b308 100644 --- a/src/p9y/realpath.hpp +++ b/src/p9y/realpath.hpp @@ -9,13 +9,12 @@ #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 diff --git a/src/p9y/socket.c b/src/p9y/socket.c deleted file mode 100644 index 1398e1d8..00000000 --- a/src/p9y/socket.c +++ /dev/null @@ -1,50 +0,0 @@ -#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 diff --git a/src/p9y/socket.hpp b/src/p9y/socket.hpp index 23237e73..9678b39f 100644 --- a/src/p9y/socket.hpp +++ b/src/p9y/socket.hpp @@ -39,6 +39,7 @@ extern "C" { #endif # if defined _WIN32 +# define P9Y_NEED_GET_SOCKET_ERRNO int get_socket_errno(); # define SHUT_WR SD_SEND # define SHUT_RD SD_RECEIVE -- 2.30.2