Update local poll() implementation.
authorBrian Aker <brian@tangent.org>
Tue, 8 Jan 2013 09:08:21 +0000 (04:08 -0500)
committerBrian Aker <brian@tangent.org>
Tue, 8 Jan 2013 09:08:21 +0000 (04:08 -0500)
Makefile.am
libmemcached/assert.hpp
libmemcached/backtrace.hpp
libmemcached/common.h
libmemcached/include.am
libmemcached/poll.cc [new file with mode: 0644]
libmemcached/poll.h [new file with mode: 0644]
poll/include.am [deleted file]
poll/poll.c [deleted file]
poll/poll.h [deleted file]

index f5c63863b8565d7e7a31c207ea0da315ad4c928e..7f6e0386256e0cfdf359a29804e528f69ebce86d 100644 (file)
@@ -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
index b7124c91d7d70fbd12184d1548d628ef6f35ceaf..d66b096fb4f5fcfb94400d29fa65878a0a5e67bf 100644 (file)
 
 #pragma once
 
+#ifdef __cplusplus
+# include <cassert>
+#else
+# include <assert.h>
+#endif // __cplusplus
+
 #ifdef NDEBUG
 # define assert_msg(__expr, __mesg) (void)(__expr); (void)(__mesg);
 # define assert_vmsg(__expr, __mesg, ...) (void)(__expr); (void)(__mesg);
 #  include <alloca.h>
 # endif
 
+#ifdef __cplusplus
 # include <cstdarg>
+# include <cstdio>
+#else
+# include <stdarg.h>
+# include <stdio.h>
+#endif
+
 # include <libmemcached/backtrace.hpp>
 
 # define assert_msg(__expr, __mesg) \
index 330d02c4ae3c302d48be6a4fb86f54740cd1c3be..a83d3ea14ac145d95b87e4964a07e48919ed01b8 100644 (file)
@@ -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
 
 #pragma once
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 void custom_backtrace(void);
+
+#ifdef __cplusplus
+}
+#endif
index cc71ac5f8123813588832780b5e0b6052bd8d761..97990588374b2d7cbc298c340293832eba0e9acc 100644 (file)
 #ifdef HAVE_POLL_H
 # include <poll.h>
 #else
-# include "poll/poll.h"
-#endif
-
-#ifndef POLLHUP
-# define POLLHUP               0x0010
-#endif
-
-#ifndef POLLNVAL
-# define POLLNVAL      0x0020
+# include "libmemcached/poll.h"
 #endif
 
 #ifdef __cplusplus
index 4c826ba1e4d46834c9afd3884801bde04b70dab5..5ca9c27ca4aa38c36eadb2f5ad4886f9ac15f1f5 100644 (file)
@@ -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 (file)
index 0000000..abd15d4
--- /dev/null
@@ -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 <sys/time.h>
+#include <strings.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;
+}
+
+#endif // defined(WIN32) || defined(__MINGW32__)
diff --git a/libmemcached/poll.h b/libmemcached/poll.h
new file mode 100644 (file)
index 0000000..8445f00
--- /dev/null
@@ -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 <winsock2.h>
+
+#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 (file)
index 0010520..0000000
+++ /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 (file)
index 28156d1..0000000
+++ /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 <winsock2.h>
-# include <ws2tcpip.h>
-#endif
-
-#include <sys/time.h>
-#include <strings.h>
-
-#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 (file)
index 82940ca..0000000
+++ /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 <winsock2.h>
-#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