Refactor: rename __write_vector_st
[m6w6/libmemcached] / tests / server.c
index 543d5bacebd21ffc838e00e0921209e1c3858f1e..f2717795af0af04c2d5f46960a8f0f6a861e0278 100644 (file)
 #include <libmemcached/memcached.h>
 #include <libmemcached/util.h>
 #include <unistd.h>
+#include <sys/time.h>
+
 #include "server.h"
 
 void server_startup(server_startup_st *construct)
 {
-  unsigned int x;
-
   if ((construct->server_list= getenv("MEMCACHED_SERVERS")))
   {
     printf("servers %s\n", construct->server_list);
@@ -46,7 +46,7 @@ void server_startup(server_startup_st *construct)
       char *end_ptr;
       end_ptr= server_string_buffer;
 
-      for (x= 0; x < construct->count; x++)
+      for (uint32_t x= 0; x < construct->count; x++)
       {
         char buffer[1024]; /* Nothing special for number */
         int count;
@@ -95,6 +95,40 @@ void server_startup(server_startup_st *construct)
       }
       *end_ptr= 0;
 
+      for (uint32_t x= 0; x < construct->count; x++)
+      {
+        uint32_t counter= 3;
+        char buffer[1024]; /* Nothing special for number */
+
+        snprintf(buffer, sizeof(buffer), "/tmp/%umemc.pid", x);
+
+        while (--counter)
+        {
+          int memcached_pid;
+
+          FILE *file;
+          file= fopen(buffer, "r");
+          if (file == NULL)
+          {
+#ifndef WIN32
+            struct timespec req= { .tv_sec= 0, .tv_nsec= 5000 };
+            nanosleep(&req, NULL);
+#endif
+            continue;
+          }
+          char *found= fgets(buffer, sizeof(buffer), file);
+          if (!found)
+          {
+            abort();
+          }
+          // Yes, we currently pitch this and don't make use of it.
+          memcached_pid= atoi(buffer);
+          fclose(file);
+        }
+
+
+      }
+
       construct->server_list= strdup(server_string_buffer);
     }
     printf("servers %s\n", construct->server_list);
@@ -105,7 +139,7 @@ void server_startup(server_startup_st *construct)
 
   srandom((unsigned int)time(NULL));
 
-  for (x= 0; x < memcached_server_list_count(construct->servers); x++)
+  for (uint32_t x= 0; x < memcached_server_list_count(construct->servers); x++)
   {
     printf("\t%s : %d\n", memcached_server_name(&construct->servers[x]), memcached_server_port(&construct->servers[x]));
     assert(construct->servers[x].fd == -1);
@@ -117,11 +151,9 @@ void server_startup(server_startup_st *construct)
 
 void server_shutdown(server_startup_st *construct)
 {
-  unsigned int x;
-
   if (construct->server_list)
   {
-    for (x= 0; x < construct->count; x++)
+    for (uint32_t x= 0; x < construct->count; x++)
     {
       char buffer[1024]; /* Nothing special for number */
       sprintf(buffer, "cat /tmp/%umemc.pid | xargs kill", x);