Browse Source

Add SSL support to gearman CLI command.

David Shrewsbury 11 years ago
parent
commit
a364311a66
3 changed files with 23 additions and 1 deletions
  1. 6 1
      bin/arguments.cc
  2. 6 0
      bin/arguments.h
  3. 11 0
      bin/gearman.cc

+ 6 - 1
bin/arguments.cc

@@ -71,6 +71,7 @@ Args::Args(int p_argc, char *p_argv[]) :
   _daemon(false),
   _usage(false),
   _is_error(false),
+  _use_ssl(false),
   _arg_error(NULL),
   _priority(GEARMAN_JOB_PRIORITY_NORMAL),
   _timeout(-1),
@@ -91,7 +92,7 @@ void Args::init(int argc)
 
   opterr= 0;
 
-  while ((c = getopt(argc, argv, "bc:f:h:HILnNp:Pst:u:vwi:d")) != -1)
+  while ((c = getopt(argc, argv, "bc:f:h:HILnNp:Pst:u:vwi:dS")) != -1)
   {
     switch(c)
     {
@@ -168,6 +169,10 @@ void Args::init(int argc)
       _verbose= true;
       break;
 
+    case 'S':
+      _use_ssl= true;
+      break;
+
     default:
       _is_error= true;
 

+ 6 - 0
bin/arguments.h

@@ -161,6 +161,11 @@ public:
     return _suppress_input;
   }
 
+  bool use_ssl() const
+  {
+    return _use_ssl;
+  }
+
   const char *argument(size_t arg)
   {
     return argv[arg];
@@ -220,6 +225,7 @@ private:
   bool _daemon;
   bool _usage;
   bool _is_error;
+  bool _use_ssl;
   char *_arg_error;
   gearman_job_priority_t _priority;
   int _timeout;

+ 11 - 0
bin/gearman.cc

@@ -263,6 +263,11 @@ void _client(Args &args)
     return;
   }
 
+  if (args.use_ssl())
+  {
+    gearman_client_add_options(&client, GEARMAN_CLIENT_SSL);
+  }
+
   gearman_client_set_created_fn(&client, _client_created);
   gearman_client_set_data_fn(&client, _client_data);
   gearman_client_set_warning_fn(&client, _client_warning);
@@ -520,6 +525,11 @@ void _worker(Args &args)
     _exit(EXIT_FAILURE);
   }
 
+  if (args.use_ssl())
+  {
+    gearman_worker_add_options(&worker, GEARMAN_WORKER_SSL);
+  }
+
   gearman_worker_set_workload_free_fn(&worker, _worker_free, NULL);
 
   for (Function::vector::iterator iter= args.begin(); 
@@ -784,6 +794,7 @@ static void usage(Args& args, char *name)
   fprintf(stream, "\t-p <port>     - Job server port\n");
   fprintf(stream, "\t-t <timeout>  - Timeout in milliseconds\n");
   fprintf(stream, "\t-i <pidfile>  - Create a pidfile for the process\n");
+  fprintf(stream, "\t-S            - Enable SSL connections\n");
 
   fprintf(stream, "\nClient options:\n");
   fprintf(stream, "\t-b            - Run jobs in the background(%s)\n", args.background() ? "true" : "false");