~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/gearman_udf/function_map.cc

pandora-build v0.42 - Started splitting out plugin system into pandora-build

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
16
#include "function_map.h"
17
 
#include <libgearman/client.h>
18
17
#include <string.h>
19
18
#include <stdlib.h>
20
19
 
46
45
bool GearmanFunctionMap::add(string function, string servers)
47
46
{
48
47
  map<string, gearman_client_st>::iterator x;
49
 
  gearman_return_t ret;
 
48
  string host;
 
49
  string port;
 
50
  size_t begin_pos= 0;
 
51
  size_t end_pos;
 
52
  size_t port_pos;
50
53
 
51
54
  pthread_mutex_lock(&lock);
52
55
 
60
63
    }
61
64
  }
62
65
 
63
 
  gearman_client_remove_servers(&(functionMap[function]));
64
 
  ret= gearman_client_add_servers(&(functionMap[function]), servers.c_str());
 
66
  /* Parse server strings in the format "host[:port][,host[:port]]..." */
 
67
  while (1)
 
68
  {
 
69
    end_pos= servers.find(',', begin_pos);
 
70
    if (end_pos == string::npos)
 
71
      host= servers.substr(begin_pos);
 
72
    else
 
73
      host= servers.substr(begin_pos, end_pos - begin_pos);
 
74
 
 
75
    port_pos= host.find(':');
 
76
    if (port_pos == string::npos)
 
77
      port.clear();
 
78
    else
 
79
    {
 
80
      port= host.substr(port_pos + 1);
 
81
      host[port_pos]= 0;
 
82
    }
 
83
 
 
84
    /* For each host:port pair, add a server to the cloning object. */
 
85
    if (gearman_client_add_server(&(functionMap[function]), host.c_str(),
 
86
                                  port.size() == 0 ?
 
87
                                  0 : atoi(port.c_str())) != GEARMAN_SUCCESS)
 
88
    {
 
89
      pthread_mutex_unlock(&lock);
 
90
      return false;
 
91
    }
 
92
 
 
93
    if (end_pos == string::npos)
 
94
      break;
 
95
 
 
96
    begin_pos= end_pos + 1;
 
97
  }
 
98
 
65
99
  pthread_mutex_unlock(&lock);
66
 
  if (ret != GEARMAN_SUCCESS)
67
 
    return false;
68
 
 
69
100
  return true;
70
101
}
71
102