Brian Aker 12 лет назад
Родитель
Сommit
816ed295a0

+ 5 - 1
libgearman-1.0/client.h

@@ -439,10 +439,14 @@ gearman_return_t gearman_client_job_status(gearman_client_st *client,
                                            uint32_t *numerator,
                                            uint32_t *denominator);
 
+GEARMAN_API
+gearman_status_t gearman_client_unique_status(gearman_client_st *client,
+                                              const char *unique, size_t unique_length);
+
 // This is not in the API yet, subject to change
 GEARMAN_API
 gearman_task_st *gearman_client_add_task_status_by_unique(gearman_client_st *client,
-                                                          void *context,
+                                                          gearman_task_st *task_ptr,
                                                           const char *unique_handle,
                                                           gearman_return_t *ret_ptr);
 

+ 1 - 0
libgearman-1.0/constants.h

@@ -143,6 +143,7 @@ typedef struct gearman_task_attr_t gearman_task_attr_t;
 typedef struct gearman_result_st gearman_result_st;
 typedef struct gearman_string_t gearman_string_t;
 typedef struct gearman_argument_t gearman_argument_t;
+typedef struct gearman_status_t gearman_status_t;
 
 // Custom allocators
 typedef void* (gearman_malloc_fn)(size_t size, void *context);

+ 1 - 0
libgearman-1.0/gearman.h

@@ -95,6 +95,7 @@
 #include <libgearman-1.0/result.h>
 #include <libgearman-1.0/execute.h>
 #include <libgearman-1.0/util.h>
+#include <libgearman-1.0/interface/status.h>
 
 #include <libgearman-1.0/worker.h>
 #include <libgearman-1.0/client.h>

+ 1 - 0
libgearman-1.0/include.am

@@ -4,6 +4,7 @@
 
 include libgearman-1.0/t/include.am
 
+nobase_include_HEADERS+= libgearman-1.0/interface/status.h
 nobase_include_HEADERS+= libgearman-1.0/interface/task.h
 nobase_include_HEADERS+= \
 			 libgearman-1.0/actions.h \

+ 48 - 0
libgearman-1.0/interface/status.h

@@ -0,0 +1,48 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  Gearmand client and server library.
+ *
+ *  Copyright (C) 2012 Data Differential, http://datadifferential.com/
+ *  All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ *
+ *      * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ *
+ *      * Redistributions in binary form must reproduce the above
+ *  copyright notice, this list of conditions and the following disclaimer
+ *  in the documentation and/or other materials provided with the
+ *  distribution.
+ *
+ *      * The names of its contributors may not be used to endorse or
+ *  promote products derived from this software without specific prior
+ *  written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#pragma once
+
+struct gearman_status_t
+{
+  gearman_return_t result_rc;
+  bool is_known;
+  bool is_running;
+  uint32_t numerator;
+  uint32_t denominator;
+};
+

+ 26 - 0
libgearman-1.0/ostream.hpp

@@ -38,9 +38,35 @@
 
 #include <libgearman-1.0/gearman.h>
 
+#include <ostream>
+
 static inline std::ostream& operator<<(std::ostream& output, const enum gearman_return_t &arg)
 {
   output << gearman_strerror(arg);
   return output;
 }
 
+static inline std::ostream& operator<<(std::ostream& output, const gearman_task_st &arg)
+{
+  output << std::boolalpha 
+    << "job: " << gearman_task_job_handle(&arg)
+    << " unique: " << gearman_task_unique(&arg)
+    << " complete: " << gearman_task_numerator(&arg) << "/" << gearman_task_denominator(&arg)
+    << " state: " << gearman_task_strstate(&arg)
+    << " is_known: " << gearman_task_is_known(&arg)
+    << " is_running: " << gearman_task_is_running(&arg)
+    << " ret: " << gearman_task_return(&arg);
+
+  return output;
+}
+
+static inline std::ostream& operator<<(std::ostream& output, const gearman_status_t &arg)
+{
+  output << std::boolalpha 
+    << " is_known: " << arg.is_known
+    << " is_running: " << arg.is_running
+    << " complete: " << arg.numerator << "/" << arg.denominator
+    << " ret: " << gearman_strerror(arg.result_rc);
+
+  return output;
+}

+ 3 - 0
libgearman-1.0/task.h

@@ -167,6 +167,9 @@ gearman_result_st *gearman_task_result(gearman_task_st *task);
 GEARMAN_API
 gearman_return_t gearman_task_return(const gearman_task_st *task);
 
+GEARMAN_API
+const char *gearman_task_strstate(const gearman_task_st *);
+
 /** @} */
 
 #ifdef __cplusplus

+ 0 - 1
libgearman-server/connection_plus.cc

@@ -46,7 +46,6 @@ gearman_server_con_st* build_gearman_server_con_st(void)
 
 void destroy_gearman_server_con_st(gearman_server_con_st* arg)
 {
-  gearmand_debug("delete gearman_server_con_st");
   delete arg;
 }
 

+ 3 - 8
libgearman-server/function.cc

@@ -78,10 +78,10 @@ gearman_server_function_get(gearman_server_st *server,
     return NULL;
   }
 
-  function->function_name= (char *)malloc(function_name_size +1);
+  function->function_name= new char[function_name_size +1];
   if (function->function_name == NULL)
   {
-    gearmand_merror("malloc", char,  function_name_size +1);
+    gearmand_merror("new[]", char,  function_name_size +1);
     gearman_server_function_free(server, function);
     return NULL;
   }
@@ -95,14 +95,9 @@ gearman_server_function_get(gearman_server_st *server,
 
 void gearman_server_function_free(gearman_server_st *server, gearman_server_function_st *function)
 {
-  if (function->function_name != NULL)
-  {
-    gearmand_debug("free");
-    free(function->function_name);
-  }
+  delete function->function_name;
 
   gearmand_server_list_free(server, function);
 
-  gearmand_debug("free");
   delete function;
 }

+ 51 - 49
libgearman-server/gearmand.cc

@@ -161,7 +161,6 @@ gearmand_st *gearmand_create(const char *host_arg,
 
   if (gearman_server_create(&(gearmand->server), job_retries, worker_wakeup, round_robin) == false)
   {
-    gearmand_debug("delete gearmand_st");
     delete gearmand;
     return NULL;
   }
@@ -215,7 +214,6 @@ void gearmand_free(gearmand_st *gearmand)
 
     dcon= gearmand->free_dcon_list;
     gearmand->free_dcon_list= dcon->next;
-    gearmand_debug("free");
     free(dcon);
   }
 
@@ -230,26 +228,22 @@ void gearmand_free(gearmand_st *gearmand)
   {
     if (gearmand->port_list[x].listen_fd != NULL)
     {
-      gearmand_debug("free");
       free(gearmand->port_list[x].listen_fd);
     }
 
     if (gearmand->port_list[x].listen_event != NULL)
     {
-      gearmand_debug("free");
       free(gearmand->port_list[x].listen_event);
     }
   }
 
   if (gearmand->port_list != NULL)
   {
-    gearmand_debug("free");
     free(gearmand->port_list);
   }
 
   gearmand_info("Shutdown complete");
 
-  gearmand_debug("delete");
   delete gearmand;
 }
 
@@ -406,24 +400,25 @@ static gearmand_error_t _listen_init(gearmand_st *gearmand)
   for (uint32_t x= 0; x < gearmand->port_count; x++)
   {
     struct linger ling= {0, 0};
-    struct gearmand_port_st *port;
     struct addrinfo hints;
     struct addrinfo *addrinfo;
 
-    port= &gearmand->port_list[x];
+    gearmand_port_st *port= &gearmand->port_list[x];
 
     memset(&hints, 0, sizeof(struct addrinfo));
     hints.ai_flags= AI_PASSIVE;
     hints.ai_socktype= SOCK_STREAM;
 
-    int ret= getaddrinfo(gearmand->host, port->port, &hints, &addrinfo);
-    if (ret != 0)
     {
-      char buffer[1024];
+      int ret= getaddrinfo(gearmand->host, port->port, &hints, &addrinfo);
+      if (ret != 0)
+      {
+        char buffer[1024];
 
-      snprintf(buffer, sizeof(buffer), "%s:%s", gearmand->host ? gearmand->host : "<any>", port->port);
-      gearmand_gai_error(buffer, ret);
-      return GEARMAN_ERRNO;
+        snprintf(buffer, sizeof(buffer), "%s:%s", gearmand->host ? gearmand->host : "<any>", port->port);
+        gearmand_gai_error(buffer, ret);
+        return GEARMAN_ERRNO;
+      }
     }
 
     std::set<host_port_t> unique_hosts;
@@ -433,14 +428,16 @@ static gearmand_error_t _listen_init(gearmand_st *gearmand)
       int fd;
       char host[NI_MAXHOST];
 
-      ret= getnameinfo(addrinfo_next->ai_addr, addrinfo_next->ai_addrlen, host,
-                       NI_MAXHOST, port->port, NI_MAXSERV,
-                       NI_NUMERICHOST | NI_NUMERICSERV);
-      if (ret != 0)
       {
-        gearmand_gai_error("getaddrinfo", ret);
-        strcpy(host, "-");
-        strcpy(port->port, "-");
+        int ret= getnameinfo(addrinfo_next->ai_addr, addrinfo_next->ai_addrlen, host,
+                             NI_MAXHOST, port->port, NI_MAXSERV,
+                             NI_NUMERICHOST | NI_NUMERICSERV);
+        if (ret != 0)
+        {
+          gearmand_gai_error("getaddrinfo", ret);
+          strncpy(host, "-", sizeof(host));
+          strncpy(port->port, "-", sizeof(port->port));
+        }
       }
 
       std::string host_string(host);
@@ -469,8 +466,7 @@ static gearmand_error_t _listen_init(gearmand_st *gearmand)
       if (addrinfo_next->ai_family == AF_INET6)
       {
         flags= 1;
-        ret= setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &flags, sizeof(flags));
-        if (ret != 0)
+        if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &flags, sizeof(flags)) == -1)
         {
           gearmand_perror("setsockopt(IPV6_V6ONLY)");
           return GEARMAN_ERRNO;
@@ -478,39 +474,45 @@ static gearmand_error_t _listen_init(gearmand_st *gearmand)
       }
 #endif
 
-      ret= fcntl(fd, F_SETFD, FD_CLOEXEC);
-      if (ret != 0 || !(fcntl(fd, F_GETFD, 0) & FD_CLOEXEC))
       {
-        gearmand_perror("fcntl(FD_CLOEXEC)");
-        return GEARMAN_ERRNO;
+        int ret= fcntl(fd, F_SETFD, FD_CLOEXEC);
+        if (ret != 0 || !(fcntl(fd, F_GETFD, 0) & FD_CLOEXEC))
+        {
+          gearmand_perror("fcntl(FD_CLOEXEC)");
+          return GEARMAN_ERRNO;
+        }
       }
 
-      ret= setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &flags, sizeof(flags));
-      if (ret != 0)
       {
-        gearmand_perror("setsockopt(SO_REUSEADDR)");
-        return GEARMAN_ERRNO;
+        if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &flags, sizeof(flags)) == -1)
+        {
+          gearmand_perror("setsockopt(SO_REUSEADDR)");
+          return GEARMAN_ERRNO;
+        }
       }
 
-      ret= setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &flags, sizeof(flags));
-      if (ret != 0)
       {
-        gearmand_perror("setsockopt(SO_KEEPALIVE)");
-        return GEARMAN_ERRNO;
+        if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &flags, sizeof(flags)) == -1)
+        {
+          gearmand_perror("setsockopt(SO_KEEPALIVE)");
+          return GEARMAN_ERRNO;
+        }
       }
 
-      ret= setsockopt(fd, SOL_SOCKET, SO_LINGER, &ling, sizeof(ling));
-      if (ret != 0)
       {
-        gearmand_perror("setsockopt(SO_LINGER)");
-        return GEARMAN_ERRNO;
+        if (setsockopt(fd, SOL_SOCKET, SO_LINGER, &ling, sizeof(ling)) == -1)
+        {
+          gearmand_perror("setsockopt(SO_LINGER)");
+          return GEARMAN_ERRNO;
+        }
       }
 
-      ret= setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flags, sizeof(flags));
-      if (ret != 0)
       {
-        gearmand_perror("setsockopt(TCP_NODELAY)");
-        return GEARMAN_ERRNO;
+        if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flags, sizeof(flags)) == -1)
+        {
+          gearmand_perror("setsockopt(TCP_NODELAY)");
+          return GEARMAN_ERRNO;
+        }
       }
 
       /*
@@ -526,6 +528,7 @@ static gearmand_error_t _listen_init(gearmand_st *gearmand)
       uint32_t waited;
       uint32_t this_wait;
       uint32_t retry;
+      int ret= -1;
       for (waited= 0, retry= 1; ; retry++, waited+= this_wait)
       {
         if (((ret= bind(fd, addrinfo_next->ai_addr, addrinfo_next->ai_addrlen)) == 0) or
@@ -694,11 +697,8 @@ static void _listen_event(int fd, short events __attribute__ ((unused)), void *a
 {
   gearmand_port_st *port= (gearmand_port_st *)arg;
   struct sockaddr sa;
-  socklen_t sa_len;
-  char host[NI_MAXHOST];
-  char port_str[NI_MAXSERV];
 
-  sa_len= sizeof(sa);
+  socklen_t sa_len= sizeof(sa);
   fd= accept(fd, &sa, &sa_len);
   if (fd == -1)
   {
@@ -726,13 +726,15 @@ static void _listen_event(int fd, short events __attribute__ ((unused)), void *a
   /* 
     Since this is numeric, it should never fail. Even if it did we don't want to really error from it.
   */
+  char host[NI_MAXHOST];
+  char port_str[NI_MAXSERV];
   int error= getnameinfo(&sa, sa_len, host, NI_MAXHOST, port_str, NI_MAXSERV,
                          NI_NUMERICHOST | NI_NUMERICSERV);
   if (error != 0)
   {
     gearmand_gai_error("getnameinfo", error);
-    strcpy(host, "-");
-    strcpy(port_str, "-");
+    strncpy(host, "-", sizeof(host));
+    strncpy(port_str, "-", sizeof(port_str));
   }
 
   gearmand_log_info(GEARMAN_DEFAULT_LOG_PARAM, "Accepted connection from %s:%s", host, port_str);

Некоторые файлы не были показаны из-за большого количества измененных файлов