~brianaker/libmemcached/embedded

« back to all changes in this revision

Viewing changes to clients/utilities.c

  • Committer: brian@gir-2.local
  • Date: 2008-03-10 15:04:41 UTC
  • mto: (317.6.1)
  • mto: This revision was merged to the branch mainline in revision 321.
  • Revision ID: brian@gir-2.local-20080310150441-jyhbjx6bwo46f6tg
Huge refactoring of directory structure.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <ctype.h>
 
3
#include <string.h>
 
4
#include "utilities.h"
 
5
 
 
6
 
 
7
long int timedif(struct timeval a, struct timeval b)
 
8
{
 
9
  register int us, s;
 
10
 
 
11
  us = a.tv_usec - b.tv_usec;
 
12
  us /= 1000;
 
13
  s = a.tv_sec - b.tv_sec;
 
14
  s *= 1000;
 
15
  return s + us;
 
16
}
 
17
 
 
18
void version_command(char *command_name)
 
19
{
 
20
  printf("%s v%u.%u\n", command_name, 1, 0);
 
21
  exit(0);
 
22
}
 
23
 
 
24
char *lookup_help(memcached_options option)
 
25
{
 
26
  switch (option)
 
27
  {
 
28
  case OPT_SERVERS: return("List which servers you wish to connect to.");
 
29
  case OPT_VERSION: return("Display the version of the application and then exit.");
 
30
  case OPT_HELP: return("Diplay this message and then exit.");
 
31
  case OPT_VERBOSE: return("Give more details on the progression of the application.");
 
32
  case OPT_DEBUG: return("Provide output only useful for debugging.");
 
33
  case OPT_FLAG: return("Provide flag information for storage operation.");
 
34
  case OPT_EXPIRE: return("Set the expire option for the object.");
 
35
  case OPT_SET: return("Use set command with memcached when storing.");
 
36
  case OPT_REPLACE: return("Use replace command with memcached when storing.");
 
37
  case OPT_ADD: return("Use add command with memcached when storing.");
 
38
  case OPT_SLAP_EXECUTE_NUMBER: return("Number of times to execute the given test.");
 
39
  case OPT_SLAP_INITIAL_LOAD: return("Number of key pairs to load before executing tests.");
 
40
  case OPT_SLAP_TEST: return("Test to run.");
 
41
  case OPT_SLAP_CONCURRENCY: return("Number of users to simulate with load.");
 
42
  case OPT_SLAP_NON_BLOCK: return("Set TCP up to use non-blocking IO.");
 
43
  case OPT_SLAP_TCP_NODELAY: return("Set TCP socket up to use nodelay.");
 
44
  case OPT_FLUSH: return("Flush servers before running tests.");
 
45
  case OPT_HASH: return("Select hash type.");
 
46
  };
 
47
 
 
48
  WATCHPOINT_ASSERT(0);
 
49
  return "forgot to document this function :)";
 
50
}
 
51
 
 
52
void help_command(char *command_name, char *description,
 
53
                  const struct option *long_options,
 
54
                  memcached_programs_help_st *options)
 
55
{
 
56
  unsigned int x;
 
57
 
 
58
  printf("%s v%u.%u\n\n", command_name, 1, 0);
 
59
  printf("\t%s\n\n", description);
 
60
  printf("Current options. A '=' means the option takes a value.\n\n");
 
61
 
 
62
  for (x= 0; long_options[x].name; x++) 
 
63
  {
 
64
    char *help_message;
 
65
 
 
66
    printf("\t --%s%c\n", long_options[x].name, 
 
67
           long_options[x].has_arg ? '=' : ' ');  
 
68
    if ((help_message= lookup_help(long_options[x].val)))
 
69
      printf("\t\t%s\n", help_message);
 
70
  }
 
71
 
 
72
  printf("\n");
 
73
  exit(0);
 
74
}
 
75
 
 
76
void process_hash_option(memcached_st *memc, char *opt_hash)
 
77
{
 
78
  uint64_t set;
 
79
  memcached_return rc;
 
80
 
 
81
  if (opt_hash == NULL)
 
82
    return;
 
83
 
 
84
  set= MEMCACHED_HASH_DEFAULT; /* Just here to solve warning */
 
85
  if (!strcasecmp(opt_hash, "CRC"))
 
86
    set= MEMCACHED_HASH_CRC;
 
87
  else if (!strcasecmp(opt_hash, "FNV1_64"))
 
88
    set= MEMCACHED_HASH_FNV1_64;
 
89
  else if (!strcasecmp(opt_hash, "FNV1A_64"))
 
90
    set= MEMCACHED_HASH_FNV1A_64;
 
91
  else if (!strcasecmp(opt_hash, "FNV1_32"))
 
92
    set= MEMCACHED_HASH_FNV1_32;
 
93
  else if (!strcasecmp(opt_hash, "FNV1A_32"))
 
94
    set= MEMCACHED_HASH_FNV1A_32;
 
95
  else if (!strcasecmp(opt_hash, "KETAMA"))
 
96
    set= MEMCACHED_HASH_KETAMA;
 
97
  else
 
98
  {
 
99
    fprintf(stderr, "hash: type not recognized %s\n", opt_hash);
 
100
    exit(1);
 
101
  }
 
102
 
 
103
  rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, set);
 
104
  if (rc != MEMCACHED_SUCCESS)
 
105
  {
 
106
    fprintf(stderr, "hash: memcache error %s\n", memcached_strerror(memc, rc));
 
107
    exit(1);
 
108
  }
 
109
}
 
110