Remove memcached_do()
[awesomized/libmemcached] / example / memcached_light.c
index 96c74d7e6f6904cae5802b61ff74a87141a9f07f..1827437857bdfd144705223bb5581f3a5e0d22bc 100644 (file)
 #include <string.h>
 #include <event.h>
 
-#include <libmemcached/protocol_handler.h>
-#include <libmemcached/byteorder.h>
-#include "storage.h"
-#include "memcached_light.h"
+#include <libmemcachedprotocol-0.0/handler.h>
+#include <libmemcached/close_socket.hpp>
+#include <example/byteorder.h>
+#include "example/storage.h"
+#include "example/memcached_light.h"
 
 extern memcached_binary_protocol_callback_st interface_v0_impl;
 extern memcached_binary_protocol_callback_st interface_v1_impl;
 
-static SOCKET server_sockets[1024];
+static memcached_socket_t server_sockets[1024];
 static int num_server_sockets= 0;
 
 struct connection
@@ -72,7 +73,7 @@ typedef struct options_st options_st;
  * @param which identifying the event that occurred (not used)
  * @param arg the connection structure for the client
  */
-static void drive_client(SOCKET fd, short which, void *arg)
+static void drive_client(memcached_socket_t fd, short which, void *arg)
 {
   (void)which;
   struct connection *client= arg;
@@ -114,14 +115,14 @@ static void drive_client(SOCKET fd, short which, void *arg)
  * @param which identifying the event that occurred (not used)
  * @param arg the connection structure for the server
  */
-static void accept_handler(SOCKET fd, short which, void *arg)
+static void accept_handler(memcached_socket_t fd, short which, void *arg)
 {
   (void)which;
   struct connection *server= arg;
   /* accept new client */
   struct sockaddr_storage addr;
   socklen_t addrlen= sizeof(addr);
-  SOCKET sock= accept(fd, (struct sockaddr *)&addr, &addrlen);
+  memcached_socket_t sock= accept(fd, (struct sockaddr *)&addr, &addrlen);
 
   if (sock == INVALID_SOCKET)
   {
@@ -180,14 +181,14 @@ static int server_socket(const char *port)
     else
       perror("getaddrinfo()");
 
-    return 1;
+    return 0;
   }
 
   struct linger ling= {0, 0};
 
   for (struct addrinfo *next= ai; next; next= next->ai_next)
   {
-    SOCKET sock= socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
+    memcached_socket_t sock= socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
     if (sock == INVALID_SOCKET)
     {
       perror("Failed to create socket");
@@ -287,8 +288,8 @@ static const char* comcode2str(uint8_t cmd)
 /**
  * Print out the command we are about to execute
  */
-static void pre_execute(const void *cookie __attribute__((unused)),
-                        protocol_binary_request_header *header __attribute__((unused)))
+static void pre_execute(const void *cookie,
+                        protocol_binary_request_header *header)
 {
   if (verbose)
   {
@@ -303,8 +304,8 @@ static void pre_execute(const void *cookie __attribute__((unused)),
 /**
  * Print out the command we just executed
  */
-static void post_execute(const void *cookie __attribute__((unused)),
-                         protocol_binary_request_header *header __attribute__((unused)))
+static void post_execute(const void *cookie,
+                         protocol_binary_request_header *header)
 {
   if (verbose)
   {
@@ -343,7 +344,7 @@ static protocol_binary_response_status unknown(const void *cookie,
  *
  * @param argc number of items in the argument vector
  * @param argv argument vector
- * @return 0 on success, 1 otherwise
+ * @return EXIT_SUCCESS on success, 1 otherwise
  */
 int main(int argc, char **argv)
 {
@@ -356,7 +357,7 @@ int main(int argc, char **argv)
   if (event_base == NULL)
   {
     fprintf(stderr, "Failed to create an instance of libevent\n");
-    return 1;
+    return EXIT_FAILURE;
   }
 
   /*
@@ -389,14 +390,14 @@ int main(int argc, char **argv)
     default:
       (void)fprintf(stderr, "Usage: %s [-p port] [-v] [-1] [-c #clients] [-P pidfile]\n",
                     argv[0]);
-      return 1;
+      return EXIT_FAILURE;
     }
   }
 
   if (! initialize_storage())
   {
     /* Error message already printed */
-    return 1;
+    return EXIT_FAILURE;
   }
 
   if (! global_options.has_port)
@@ -423,7 +424,7 @@ int main(int argc, char **argv)
   if (num_server_sockets == 0)
   {
     fprintf(stderr, "I don't have any server sockets\n");
-    return 1;
+    return EXIT_FAILURE;
   }
 
   /*
@@ -439,14 +440,14 @@ int main(int argc, char **argv)
   if ((protocol_handle= memcached_protocol_create_instance()) == NULL)
   {
     fprintf(stderr, "Failed to allocate protocol handle\n");
-    return 1;
+    return EXIT_FAILURE;
   }
 
   socket_userdata_map= calloc((size_t)(maxconns), sizeof(struct connection));
   if (socket_userdata_map == NULL)
   {
     fprintf(stderr, "Failed to allocate room for connections\n");
-    return 1;
+    return EXIT_FAILURE;
   }
 
   memcached_binary_protocol_set_callbacks(protocol_handle, interface);
@@ -470,5 +471,5 @@ int main(int argc, char **argv)
   event_base_loop(event_base, 0);
 
   /* NOTREACHED */
-  return 0;
+  return EXIT_SUCCESS;
 }