Changeset 35027 for platform/mysql

Show
Ignore:
Timestamp:
08/24/09 19:15:04 (4 years ago)
Author:
kazuho
Message:

add host option

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • platform/mysql/mycached/trunk/testclient.cc

    r35025 r35027  
    11extern "C" { 
     2#include <arpa/inet.h> 
    23#include <assert.h> 
    34#include <fcntl.h> 
     5#include <netdb.h> 
    46#include <netinet/in.h> 
    57#include <netinet/tcp.h> 
     
    2224static int connections_per_thread = 1; 
    2325static int runs_per_thread = 100000 / num_threads; 
     26static struct in_addr host; 
    2427static unsigned short port = 11211; 
    2528 
     
    7174    addr.sin_family = AF_INET; 
    7275    addr.sin_port = htons(port); 
    73     addr.sin_addr.s_addr = htonl(0x7f000001); 
     76    memcpy(&addr.sin_addr, &host, sizeof(host)); 
    7477    assert(connect(sock, (sockaddr*)&addr, sizeof(addr)) == 0); 
    7578    setup_sock(sock); 
     
    9093  int ch; 
    9194   
    92   while ((ch = getopt(argc, argv, "t:c:n:p:")) != -1) { 
     95  host.s_addr = htonl(0x7f000001); 
     96   
     97  while ((ch = getopt(argc, argv, "t:c:n:h:p:")) != -1) { 
    9398    switch (ch) { 
    9499    case 't': 
     
    100105    case 'n': 
    101106      assert(sscanf(optarg, "%d", &runs_per_thread) == 1); 
     107      break; 
     108    case 'h': 
     109      if (inet_aton(optarg, &host) == 0) { 
     110        struct hostent* h = gethostbyname(optarg); 
     111        assert(h != NULL && "host not found"); 
     112        assert(h->h_addrtype = AF_INET); 
     113        assert(h->h_length == sizeof(host)); 
     114        memcpy(&host, h->h_addr_list[0], sizeof(host)); 
     115      } 
    102116      break; 
    103117    case 'p':