From: Brian Aker Date: Tue, 8 Jan 2013 09:08:21 +0000 (-0500) Subject: Update local poll() implementation. X-Git-Tag: 1.0.16~15^2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=aaafc64fc6b893f50861a53f7e7a8c735827bf49;p=awesomized%2Flibmemcached Update local poll() implementation. --- diff --git a/Makefile.am b/Makefile.am index f5c63863..7f6e0386 100644 --- a/Makefile.am +++ b/Makefile.am @@ -64,7 +64,6 @@ endif include libmemcachedinternal/include.am include libmemcachedinternal/util/include.am -include poll/include.am include rpm/include.am include support/include.am include tests/include.am diff --git a/libmemcached/assert.hpp b/libmemcached/assert.hpp index b7124c91..d66b096f 100644 --- a/libmemcached/assert.hpp +++ b/libmemcached/assert.hpp @@ -37,6 +37,12 @@ #pragma once +#ifdef __cplusplus +# include +#else +# include +#endif // __cplusplus + #ifdef NDEBUG # define assert_msg(__expr, __mesg) (void)(__expr); (void)(__mesg); # define assert_vmsg(__expr, __mesg, ...) (void)(__expr); (void)(__mesg); @@ -48,7 +54,14 @@ # include # endif +#ifdef __cplusplus # include +# include +#else +# include +# include +#endif + # include # define assert_msg(__expr, __mesg) \ diff --git a/libmemcached/backtrace.hpp b/libmemcached/backtrace.hpp index 330d02c4..a83d3ea1 100644 --- a/libmemcached/backtrace.hpp +++ b/libmemcached/backtrace.hpp @@ -2,7 +2,7 @@ * * libmcachedd client library. * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2011-2013 Data Differential, http://datadifferential.com/ * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,4 +37,12 @@ #pragma once +#ifdef __cplusplus +extern "C" { +#endif + void custom_backtrace(void); + +#ifdef __cplusplus +} +#endif diff --git a/libmemcached/common.h b/libmemcached/common.h index cc71ac5f..97990588 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -119,15 +119,7 @@ #ifdef HAVE_POLL_H # include #else -# include "poll/poll.h" -#endif - -#ifndef POLLHUP -# define POLLHUP 0x0010 -#endif - -#ifndef POLLNVAL -# define POLLNVAL 0x0020 +# include "libmemcached/poll.h" #endif #ifdef __cplusplus diff --git a/libmemcached/include.am b/libmemcached/include.am index 4c826ba1..5ca9c27c 100644 --- a/libmemcached/include.am +++ b/libmemcached/include.am @@ -38,6 +38,7 @@ noinst_HEADERS+= libmemcached/memcached/vbucket.h noinst_HEADERS+= libmemcached/memory.h noinst_HEADERS+= libmemcached/namespace.h noinst_HEADERS+= libmemcached/options.hpp +noinst_HEADERS+= libmemcached/poll.h noinst_HEADERS+= libmemcached/response.h noinst_HEADERS+= libmemcached/result.h noinst_HEADERS+= libmemcached/sasl.hpp @@ -90,6 +91,7 @@ libmemcached_libmemcached_la_SOURCES+= libmemcached/encoding_key.cc libmemcached_libmemcached_la_SOURCES+= libmemcached/namespace.cc libmemcached_libmemcached_la_SOURCES+= libmemcached/options.cc libmemcached_libmemcached_la_SOURCES+= libmemcached/parse.cc +libmemcached_libmemcached_la_SOURCES+= libmemcached/poll.cc libmemcached_libmemcached_la_SOURCES+= libmemcached/purge.cc libmemcached_libmemcached_la_SOURCES+= libmemcached/quit.cc libmemcached_libmemcached_la_SOURCES+= libmemcached/quit.hpp @@ -104,9 +106,9 @@ libmemcached_libmemcached_la_SOURCES+= libmemcached/storage.cc libmemcached_libmemcached_la_SOURCES+= libmemcached/strerror.cc libmemcached_libmemcached_la_SOURCES+= libmemcached/string.cc libmemcached_libmemcached_la_SOURCES+= libmemcached/touch.cc +libmemcached_libmemcached_la_SOURCES+= libmemcached/udp.cc libmemcached_libmemcached_la_SOURCES+= libmemcached/verbosity.cc libmemcached_libmemcached_la_SOURCES+= libmemcached/version.cc -libmemcached_libmemcached_la_SOURCES+= libmemcached/udp.cc libmemcached_libmemcached_la_SOURCES+= libmemcached/virtual_bucket.c libmemcached/options.cc: libmemcached/csl/parser.h diff --git a/libmemcached/poll.cc b/libmemcached/poll.cc new file mode 100644 index 00000000..abd15d4c --- /dev/null +++ b/libmemcached/poll.cc @@ -0,0 +1,85 @@ +/* LibMemcached + * Copyright (C) 2013 Data Differential, http://datadifferential.com/ + * Copyright (C) 2010 Brian Aker, Trond Norbye + * All rights reserved. + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + * + * Summary: Implementation of poll by using select + * + */ + +#include "libmemcached/common.h" + +#if defined(WIN32) || defined(__MINGW32__) +#include "libmemcached/poll.h" + +#include +#include + +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= { .tv_sec = tmo / 1000, + .tv_usec= (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 // defined(WIN32) || defined(__MINGW32__) diff --git a/libmemcached/poll.h b/libmemcached/poll.h new file mode 100644 index 00000000..8445f009 --- /dev/null +++ b/libmemcached/poll.h @@ -0,0 +1,48 @@ +/* LibMemcached + * Copyright (C) 2013 Data Differential, http://datadifferential.com/ + * Copyright (C) 2010 Brian Aker, Trond Norbye + * All rights reserved. + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + * + * Summary: Implementation of poll by using select + * + */ + +#pragma once + +#if defined(WIN32) || defined(__MINGW32__) + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct pollfd +{ +#ifdef WIN32 + SOCKET fd; +#else + int fd; +#endif + short events; + short revents; +} pollfd_t; + +typedef int nfds_t; + +#define POLLIN 0x0001 +#define POLLOUT 0x0004 +#define POLLERR 0x0008 +#define POLLHUP 0x010 /* Hung up. */ +#define POLLNVAL 0x020 /* Invalid polling request. */ + +int poll(struct pollfd fds[], nfds_t nfds, int tmo); + +#ifdef __cplusplus +} +#endif + +#endif // defined(WIN32) || defined(__MINGW32__) diff --git a/poll/include.am b/poll/include.am deleted file mode 100644 index 00105208..00000000 --- a/poll/include.am +++ /dev/null @@ -1,8 +0,0 @@ -# vim:ft=automake -# included from Top Level Makefile.am -# All paths should be given relative to the root -noinst_HEADERS+= poll/poll.h - -if BUILD_POLL -libmemcached_libmemcached_la_SOURCES += poll/poll.c -endif diff --git a/poll/poll.c b/poll/poll.c deleted file mode 100644 index 28156d1f..00000000 --- a/poll/poll.c +++ /dev/null @@ -1,85 +0,0 @@ -/* LibMemcached - * Copyright (C) 2010 Brian Aker, Trond Norbye - * All rights reserved. - * - * Use and distribution licensed under the BSD license. See - * the COPYING file in the parent directory for full text. - * - * Summary: Implementation of poll by using select - * - */ -#include "mem_config.h" - -#if defined(WIN32) || defined(__MINGW32__) -# include -# include -#endif - -#include -#include - -#include "poll/poll.h" - -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= { .tv_sec = tmo / 1000, - .tv_usec= (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; -} diff --git a/poll/poll.h b/poll/poll.h deleted file mode 100644 index 82940ca5..00000000 --- a/poll/poll.h +++ /dev/null @@ -1,45 +0,0 @@ -/* LibMemcached - * Copyright (C) 2010 Brian Aker, Trond Norbye - * All rights reserved. - * - * Use and distribution licensed under the BSD license. See - * the COPYING file in the parent directory for full text. - * - * Summary: Implementation of poll by using select - * - */ -#ifndef POLL_POLL_H -#define POLL_POLL_H 1 - -#ifdef WIN32 -#include -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct pollfd -{ -#ifdef WIN32 - SOCKET fd; -#else - int fd; -#endif - short events; - short revents; -} pollfd_t; - -typedef int nfds_t; - -#define POLLIN 0x0001 -#define POLLOUT 0x0004 -#define POLLERR 0x0008 - -int poll(struct pollfd fds[], nfds_t nfds, int tmo); - -#ifdef __cplusplus -} -#endif - -#endif