- server_st &server= construct->server[x];
-
- {
- char *var;
- char variable_buffer[1024];
-
- snprintf(variable_buffer, sizeof(variable_buffer), "LIBMEMCACHED_PORT_%u", x);
-
- if ((var= getenv(variable_buffer)))
- {
- server.set_port((in_port_t)atoi(var));
- }
- else
- {
- server.set_port(in_port_t(x + TEST_PORT_BASE + port_base));
-
- while (not cycle_server(server))
- {
- std::cerr << CERR_PREFIX << "Found server " << server << ", could not flush it, so trying next port." << std::endl;
- port_base++;
- server.set_port(in_port_t(x + TEST_PORT_BASE + port_base));
- }
- }
- }
-
- if (server.is_used())
- {
- std::cerr << std::endl << "Using server at : " << server << std::endl;
- }
- else
- {
- char buffer[FILENAME_MAX];
- if (x == 0)
- {
- snprintf(buffer, sizeof(buffer), "%s -d -t 1 -p %u -U %u -m 128",
- MEMCACHED_BINARY, server.port(), server.port());
- }
- else
- {
- snprintf(buffer, sizeof(buffer), "%s -d -t 1 -p %u -U %u",
- MEMCACHED_BINARY, server.port(), server.port());
- }
-
- int status= system(buffer);
- if (status == -1)
- {
- std::cerr << CERR_PREFIX << "Failed system(" << buffer << ")" << std::endl;
- return false;
- }
- fprintf(stderr, "STARTING SERVER: %s\n", buffer);
-
- int count= 30;
- memcached_return_t rc;
- while (not libmemcached_util_ping(server.hostname, server.port(), &rc) and --count)
- {
- global_sleep();
- }
-
- if (memcached_failed(rc))
- {
- std::cerr << CERR_PREFIX << "libmemcached_util_ping() failed:" << memcached_strerror(NULL, rc) << " Connection:" << server << std::endl;
- return false;
- }
-
- server.set_pid(libmemcached_util_getpid(server.hostname, server.port(), &rc));
- if (not server.has_pid())
- {
- std::cerr << CERR_PREFIX << "libmemcached_util_getpid() failed" << memcached_strerror(NULL, rc) << " Connection: " << server << std::endl;
- return false;
- }
- }
-
- server_config_string+= "--server=";
- server_config_string+= server.hostname;
- server_config_string+= ":";
- server_config_string+= boost::lexical_cast<std::string>(server.port());
- server_config_string+= " ";
- fprintf(stderr, " Port %d\n", server.port());