Browse Source

Fixed issue with sem_t anonymous not being supported on OSX by switching to Boost thread semaphore.

Brian Aker 13 years ago
parent
commit
4b61f9cb6e

+ 1 - 0
configure.ac

@@ -52,6 +52,7 @@ AX_PTHREAD(, [AC_MSG_ERROR(could not find libpthread)])
 dnl First look for Boost, maybe for a specific minimum version:
 BOOST_REQUIRE([1.39])
 BOOST_PROGRAM_OPTIONS
+BOOST_THREADS
 
 PANDORA_CXX_CSTDINT
 PANDORA_CXX_CINTTYPES

+ 12 - 0
libgearman-1.0/connection.h

@@ -43,6 +43,18 @@
 #include <sys/socket.h>
 #include <netdb.h>
 
+#ifdef NI_MAXHOST
+#define GEARMAN_NI_MAXHOST NI_MAXHOST
+#else
+#define GEARMAN_NI_MAXHOST 1025
+#endif
+
+#ifdef NI_MAXSERV
+#define GEARMAN_NI_MAXSERV NI_MAXSERV
+#else
+#define GEARMAN_NI_MAXSERV 32
+#endif
+
 /*
   Do not define these enum in your application. There are left publically due to one client.
 */

+ 11 - 2
libgearman-1.0/kill.h

@@ -39,7 +39,8 @@
 
 struct gearman_id_t
 {
-  int fd;
+  int read_fd;
+  int write_fd;
 };
 
 #ifndef __cplusplus
@@ -51,7 +52,15 @@ extern "C" {
 #endif
 
 GEARMAN_API
-  gearman_return_t gearman_kill(gearman_id_t handle, gearman_signal_t);
+  gearman_return_t gearman_kill(const gearman_id_t handle, const gearman_signal_t);
+
+GEARMAN_API
+  bool gearman_id_valid(const gearman_id_t handle);
+
+GEARMAN_API
+  gearman_id_t gearman_id_initialize(void);
+
+#define GEARMAN_ID_INITIALIZER gearman_id_initialize()
 
 #ifdef __cplusplus
 }

+ 5 - 2
libgearman-1.0/signal.h

@@ -39,8 +39,11 @@
 
 enum gearman_signal_t
 {
-  GEARMAN_INTERRUPT,
-  GEARMAN_KILL
+  GEARMAN_SIGNAL_CHECK,
+  GEARMAN_SIGNAL_INTERRUPT,
+  GEARMAN_SIGNAL_KILL,
+  GEARMAN_INTERRUPT= GEARMAN_SIGNAL_INTERRUPT,
+  GEARMAN_KILL= GEARMAN_SIGNAL_KILL
 };
 
 #ifndef __cplusplus

+ 4 - 4
libgearman/connection.cc

@@ -341,8 +341,8 @@ void gearman_connection_st::set_host(const char *host_arg, const in_port_t port_
 {
   reset_addrinfo();
 
-  strncpy(host, host_arg == NULL ? GEARMAN_DEFAULT_TCP_HOST : host_arg, NI_MAXHOST);
-  host[NI_MAXHOST - 1]= 0;
+  strncpy(host, host_arg == NULL ? GEARMAN_DEFAULT_TCP_HOST : host_arg, GEARMAN_NI_MAXHOST);
+  host[GEARMAN_NI_MAXHOST - 1]= 0;
 
   port= in_port_t(port_arg == 0 ? GEARMAN_DEFAULT_TCP_PORT : port_arg);
 }
@@ -565,8 +565,8 @@ gearman_return_t gearman_connection_st::lookup()
     addrinfo= NULL;
   }
 
-  char port_str[NI_MAXSERV];
-  snprintf(port_str, NI_MAXSERV, "%hu", uint16_t(port));
+  char port_str[GEARMAN_NI_MAXSERV];
+  snprintf(port_str, GEARMAN_NI_MAXSERV, "%hu", uint16_t(port));
 
   struct addrinfo ai;
   memset(&ai, 0, sizeof(struct addrinfo));

+ 1 - 1
libgearman/connection.hpp

@@ -72,7 +72,7 @@ struct gearman_connection_st
   gearman_packet_st *recv_packet;
   char *recv_buffer_ptr;
   gearman_packet_st _packet;
-  char host[NI_MAXHOST];
+  char host[GEARMAN_NI_MAXHOST];
   char send_buffer[GEARMAN_SEND_BUFFER_SIZE];
   char recv_buffer[GEARMAN_RECV_BUFFER_SIZE];
 

+ 43 - 7
libgearman/kill.cc

@@ -37,30 +37,66 @@
  */
 
 #include <libgearman/common.h>
+#include <cerrno>
 #include <unistd.h>
 
-gearman_return_t gearman_kill(gearman_id_t handle, gearman_signal_t sig)
+gearman_id_t gearman_id_initialize(void)
 {
-  if (handle.fd == INVALID_SOCKET)
+  static gearman_id_t tmp= { -1, -1 };
+
+  return tmp;
+}
+
+bool gearman_id_valid(const gearman_id_t handle)
+{
+  if (handle.write_fd <= 0 and handle.read_fd <= 0)
+  {
+    return false;
+  }
+
+  return true;
+}
+
+gearman_return_t gearman_kill(const gearman_id_t handle, const gearman_signal_t sig)
+{
+  if (handle.write_fd <= 0 or handle.read_fd <= 0)
   {
-    return GEARMAN_INVALID_ARGUMENT;
+    return GEARMAN_COULD_NOT_CONNECT;
   }
 
   switch (sig)
   {
-  case GEARMAN_INTERRUPT:
-    if (write(handle.fd, "1", 1) == 1);
+  case GEARMAN_SIGNAL_INTERRUPT:
+    if (write(handle.write_fd, "1", 1) == 1);
     {
       return GEARMAN_SUCCESS;
     }
     break;
 
-  case GEARMAN_KILL:
-    if (close(handle.fd) == 0)
+  case GEARMAN_SIGNAL_KILL:
+    if (close(handle.write_fd) == 0)
     {
       return GEARMAN_SUCCESS;
     }
     break;
+
+  case GEARMAN_SIGNAL_CHECK:
+    {
+      struct pollfd pfds[1];
+      pfds[0].fd= handle.read_fd;
+      pfds[0].events= POLLIN;
+      pfds[0].revents= 0;
+      char buffer[1];
+
+      int ret= ::poll(pfds, sizeof(pfds), 1500);
+
+      if (ret >= 0)
+      {
+        return GEARMAN_SUCCESS;
+      }
+
+      return GEARMAN_COULD_NOT_CONNECT;
+    }
   }
 
   return GEARMAN_COULD_NOT_CONNECT;

+ 1 - 1
libgearman/parse.cc

@@ -44,7 +44,7 @@ gearman_return_t gearman_parse_servers(const char *servers,
                                        void *context)
 {
   const char *ptr= servers;
-  char host[NI_MAXHOST];
+  char host[GEARMAN_NI_MAXHOST];
   char port[NI_MAXSERV];
 
   if (not ptr)

+ 12 - 8
libgearman/universal.cc

@@ -515,27 +515,31 @@ bool gearman_request_option(gearman_universal_st &universal,
       goto exit;
     }
 
-    con->options.packet_in_use= true;
-    gearman_packet_st *packet_ptr= con->receiving(con->_packet, ret, true);
-    if (gearman_failed(ret))
+    gearman_packet_st recv_packet;
+    assert(con->recv_state == GEARMAN_CON_RECV_UNIVERSAL_NONE);
+    gearman_packet_st *packet_ptr= con->receiving(recv_packet, ret, true);
+    if (ret == GEARMAN_NOT_CONNECTED)
+    {
+      goto exit;
+    }
+    else if (gearman_failed(ret))
     {
-      con->free_private_packet();
       con->recv_packet= NULL;
+      gearman_packet_free(&recv_packet);
       goto exit;
     }
     assert(packet_ptr);
 
     if (packet_ptr->command == GEARMAN_COMMAND_ERROR)
     {
-      con->free_private_packet();
       con->recv_packet= NULL;
+      gearman_packet_free(&recv_packet);
       ret= gearman_error(universal, GEARMAN_INVALID_ARGUMENT, "invalid server option");
 
       goto exit;
     }
 
-    con->recv_packet= NULL;
-    con->free_private_packet();
+    gearman_packet_free(&recv_packet);
   }
 
   ret= GEARMAN_SUCCESS;
@@ -557,7 +561,7 @@ void gearman_free_all_packets(gearman_universal_st &universal)
 
 gearman_id_t gearman_universal_id(gearman_universal_st &universal)
 {
-  gearman_id_t handle= { universal.wakeup_fd[1] };
+  gearman_id_t handle= { universal.wakeup_fd[0], universal.wakeup_fd[1] };
 
   return handle;
 }

+ 2 - 1
tests/include.am

@@ -31,7 +31,9 @@ noinst_HEADERS+= \
 noinst_LTLIBRARIES+= tests/libstartworker.la
 tests_libstartworker_la_CXXFLAGS=
 tests_libstartworker_la_CXXFLAGS+= $(PTHREAD_CFLAGS)
+tests_libstartworker_la_CXXFLAGS+= $(BOOST_CPPFLAGS)
 tests_libstartworker_la_LIBADD= $(PTHREAD_LIBS)
+tests_libstartworker_la_LIBADD+= $(BOOST_THREAD_LIBS)
 tests_libstartworker_la_SOURCES= tests/start_worker.cc
 tests_libstartworker_la_SOURCES+= util/instance.cc
 tests_libstartworker_la_SOURCES+= util/operation.cc
@@ -60,7 +62,6 @@ noinst_PROGRAMS+= tests/blobslap_client
 
 tests_cli_SOURCES= tests/cli.cc
 tests_cli_SOURCES+= tests/libgearman-1.0/workers.cc
-tests_cli_SOURCES+= tests/start_worker.cc
 tests_cli_DEPENDENCIES= ${CLIENT_LDADD} gearmand/gearmand bin/gearman bin/gearadmin
 tests_cli_LDADD= ${CLIENT_LDADD}
 check_PROGRAMS+= tests/cli

Some files were not shown because too many files changed in this diff