~clint-fewbar/ubuntu/precise/gearmand/drop-unneeded-patches

« back to all changes in this revision

Viewing changes to libgearman/gearman.c

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2009-08-11 10:06:22 UTC
  • mto: (1.2.3 upstream) (6.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20090811100622-6ig4iknanc73olum
ImportĀ upstreamĀ versionĀ 0.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
#include "common.h"
15
15
 
16
16
/*
 
17
 * Private declarations
 
18
 */
 
19
 
 
20
/**
 
21
 * @addtogroup gearman_private Private Functions
 
22
 * @ingroup gearman
 
23
 * @{
 
24
 */
 
25
 
 
26
/**
 
27
 * Names of the verbose levels provided.
 
28
 */
 
29
static const char *_verbose_name[GEARMAN_VERBOSE_MAX]=
 
30
{
 
31
  "FATAL",
 
32
  "ERROR",
 
33
  "INFO",
 
34
  "DEBUG",
 
35
  "CRAZY"
 
36
};
 
37
 
 
38
/** @} */
 
39
 
 
40
/*
17
41
 * Public definitions
18
42
 */
19
43
 
27
51
    return PACKAGE_BUGREPORT;
28
52
}
29
53
 
 
54
const char *gearman_verbose_name(gearman_verbose_t verbose)
 
55
{
 
56
  if (verbose >= GEARMAN_VERBOSE_MAX)
 
57
    return "UNKNOWN";
 
58
 
 
59
  return _verbose_name[verbose];
 
60
}
 
61
 
30
62
gearman_st *gearman_create(gearman_st *gearman)
31
63
{
32
64
  if (gearman == NULL)
35
67
    if (gearman == NULL)
36
68
      return NULL;
37
69
 
38
 
    memset(gearman, 0, sizeof(gearman_st));
39
 
    gearman->options|= GEARMAN_ALLOCATED;
 
70
    gearman->options= GEARMAN_ALLOCATED;
40
71
  }
41
72
  else
42
 
    memset(gearman, 0, sizeof(gearman_st));
 
73
    gearman->options= 0;
 
74
 
 
75
  gearman->verbose= 0;
 
76
  gearman->con_count= 0;
 
77
  gearman->job_count= 0;
 
78
  gearman->task_count= 0;
 
79
  gearman->packet_count= 0;
 
80
  gearman->pfds_size= 0;
 
81
  gearman->sending= 0;
 
82
  gearman->last_errno= 0;
 
83
  gearman->con_list= NULL;
 
84
  gearman->job_list= NULL;
 
85
  gearman->task_list= NULL;
 
86
  gearman->packet_list= NULL;
 
87
  gearman->pfds= NULL;
 
88
  gearman->log_fn= NULL;
 
89
  gearman->log_fn_arg= NULL;
 
90
  gearman->event_watch= NULL;
 
91
  gearman->event_watch_arg= NULL;
 
92
  gearman->workload_malloc= NULL;
 
93
  gearman->workload_malloc_arg= NULL;
 
94
  gearman->workload_free= NULL;
 
95
  gearman->workload_free_arg= NULL;
 
96
  gearman->task_fn_arg_free_fn= NULL;
 
97
  gearman->queue_fn_arg= NULL;
 
98
  gearman->queue_add_fn= NULL;
 
99
  gearman->queue_flush_fn= NULL;
 
100
  gearman->queue_done_fn= NULL;
 
101
  gearman->queue_replay_fn= NULL;
 
102
  gearman->last_error[0]= 0;
43
103
 
44
104
  return gearman;
45
105
}
52
112
  if (gearman == NULL)
53
113
    return NULL;
54
114
 
55
 
  gearman->options|= (from->options & ~GEARMAN_ALLOCATED);
 
115
  gearman->options|= (from->options & (gearman_options_t)~GEARMAN_ALLOCATED);
56
116
 
57
117
  for (con= from->con_list; con != NULL; con= con->next)
58
118
  {
187
247
{
188
248
  gearman->queue_replay_fn= replay_fn;
189
249
}
 
250
 
 
251
gearman_return_t gearman_parse_servers(const char *servers, void *data,
 
252
                                       gearman_parse_server_fn *server_fn)
 
253
 
254
  const char *ptr= servers;
 
255
  size_t x;
 
256
  char host[NI_MAXHOST];
 
257
  char port[NI_MAXSERV];
 
258
  gearman_return_t ret;
 
259
 
 
260
  if (ptr == NULL)
 
261
    return (*server_fn)(NULL, 0, data);
 
262
 
 
263
  while (1)
 
264
  { 
 
265
    x= 0;
 
266
 
 
267
    while (*ptr != 0 && *ptr != ',' && *ptr != ':')
 
268
    { 
 
269
      if (x < (NI_MAXHOST - 1))
 
270
        host[x++]= *ptr;
 
271
 
 
272
      ptr++;
 
273
    }
 
274
 
 
275
    host[x]= 0;
 
276
 
 
277
    if (*ptr == ':')
 
278
    { 
 
279
      ptr++;
 
280
      x= 0;
 
281
 
 
282
      while (*ptr != 0 && *ptr != ',')
 
283
      { 
 
284
        if (x < (NI_MAXSERV - 1))
 
285
          port[x++]= *ptr;
 
286
 
 
287
        ptr++;
 
288
      }
 
289
 
 
290
      port[x]= 0;
 
291
    }
 
292
    else
 
293
      port[0]= 0;
 
294
 
 
295
    ret= (*server_fn)(host, (in_port_t)atoi(port), data);
 
296
    if (ret != GEARMAN_SUCCESS)
 
297
      return ret;
 
298
 
 
299
    if (*ptr == 0)
 
300
      break;
 
301
 
 
302
    ptr++;
 
303
  }
 
304
 
 
305
  return GEARMAN_SUCCESS;
 
306
}