Add support for SASL
[m6w6/libmemcached] / libmemcached / protocol_handler.h
index ef816a0d71c33cf1639a4e80c4d28bedea1fceb2..78eda07745a4d86a55b214d8d49c905bfe1b3b56 100644 (file)
@@ -1,15 +1,23 @@
-/*
- * Summary: Definition of the callback interface to the protocol handler
+/* LibMemcached
+ * Copyright (C) 2006-2009 Brian Aker
+ * All rights reserved.
+ *
+ * Use and distribution licensed under the BSD license.  See
+ * the COPYING file in the parent directory for full text.
  *
- * Copy: See Copyright for the status of this software.
+ * Summary: Definition of the callback interface to the protocol handler
  *
  * Author: Trond Norbye
+ *
  */
-#ifndef MEMCACHED_PROTOCOL_H
-#define MEMCACHED_PROTOCOL_H
+
+#ifndef __LIBMEMCACHED_PROTOCOL_H__
+#define __LIBMEMCACHED_PROTOCOL_H__
 
 #include <sys/types.h>
-#include <stdbool.h>
+#if !defined(__cplusplus)
+# include <stdbool.h>
+#endif
 
 #include <libmemcached/memcached/protocol_binary.h>
 #include <libmemcached/visibility.h>
  * and never assume anything about the internal layout / sizes of the
  * structures.
  */
-struct memcached_protocol_st;
-struct memcached_protocol_client_st;
+typedef struct memcached_protocol_st memcached_protocol_st;
+typedef struct memcached_protocol_client_st memcached_protocol_client_st;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 /**
  * Function the protocol handler should call to receive data.
@@ -37,7 +49,7 @@ struct memcached_protocol_client_st;
  */
 typedef ssize_t (*memcached_protocol_recv_func)(const void *cookie,
                                                 int fd,
-                                                void *buf, 
+                                                void *buf,
                                                 size_t nbuf);
 
 /**
@@ -53,7 +65,7 @@ typedef ssize_t (*memcached_protocol_recv_func)(const void *cookie,
  */
 typedef ssize_t (*memcached_protocol_send_func)(const void *cookie,
                                                 int fd,
-                                                const void *buf, 
+                                                const void *buf,
                                                 size_t nbuf);
 
 /**
@@ -62,14 +74,14 @@ typedef ssize_t (*memcached_protocol_send_func)(const void *cookie,
  * @return NULL if allocation of an instance fails
  */
 LIBMEMCACHED_API
-struct memcached_protocol_st *memcached_protocol_create_instance(void);
+memcached_protocol_st *memcached_protocol_create_instance(void);
 
 /**
  * Get the callbacks associated with a protocol handler instance
  * @return the callbacks currently used
  */
 LIBMEMCACHED_API
-struct memcached_binary_protocol_callback_st *memcached_binary_protocol_get_callbacks(struct memcached_protocol_st *instance);
+memcached_binary_protocol_callback_st *memcached_binary_protocol_get_callbacks(memcached_protocol_st *instance);
 
 /**
  * Set the callbacks to be used by the given protocol handler instance
@@ -77,7 +89,7 @@ struct memcached_binary_protocol_callback_st *memcached_binary_protocol_get_call
  * @param callback the callbacks to use
  */
 LIBMEMCACHED_API
-void memcached_binary_protocol_set_callbacks(struct memcached_protocol_st *instance, struct memcached_binary_protocol_callback_st *callback);
+void memcached_binary_protocol_set_callbacks(memcached_protocol_st *instance, memcached_binary_protocol_callback_st *callback);
 
 /**
  * Should the library inspect the packages being sent and received and verify
@@ -88,7 +100,7 @@ void memcached_binary_protocol_set_callbacks(struct memcached_protocol_st *insta
  * @param enable true if you want the library to check packages, false otherwise
  */
 LIBMEMCACHED_API
-void memcached_binary_protocol_set_pedantic(struct memcached_protocol_st *instance, bool enable);
+void memcached_binary_protocol_set_pedantic(memcached_protocol_st *instance, bool enable);
 
 /**
  * Is the library inpecting each package?
@@ -96,7 +108,7 @@ void memcached_binary_protocol_set_pedantic(struct memcached_protocol_st *instan
  * @return true it the library is inspecting each package, false otherwise
  */
 LIBMEMCACHED_API
-bool memcached_binary_protocol_get_pedantic(struct memcached_protocol_st *instance);
+bool memcached_binary_protocol_get_pedantic(memcached_protocol_st *instance);
 
 /**
  * Destroy an instance of the protocol handler
@@ -104,19 +116,19 @@ bool memcached_binary_protocol_get_pedantic(struct memcached_protocol_st *instan
  * @param instance The instance to destroy
  */
 LIBMEMCACHED_API
-void memcached_protocol_destroy_instance(struct memcached_protocol_st *instance);
+void memcached_protocol_destroy_instance(memcached_protocol_st *instance);
 
 /**
  * Set the IO functions used by the instance to send and receive data. The
- * functions should behave like recv(3socket) and send(3socket). 
- * 
+ * functions should behave like recv(3socket) and send(3socket).
+ *
  * @param instance the instance to specify the IO functions for
  * @param recv the function to call for reciving data
  * @param send the function to call for sending data
  */
 LIBMEMCACHED_API
-void memached_protocol_set_io_functions(struct memcached_protocol_st *instance, 
-                                        memcached_protocol_recv_func recv, 
+void memached_protocol_set_io_functions(memcached_protocol_st *instance,
+                                        memcached_protocol_recv_func recv,
                                         memcached_protocol_send_func send);
 
 
@@ -124,45 +136,54 @@ void memached_protocol_set_io_functions(struct memcached_protocol_st *instance,
  * Create a new client instance and associate it with a socket
  * @param instance the protocol instance to bind the client to
  * @param sock the client socket
- * @return NULL if allocation fails, otherwise an instance 
+ * @return NULL if allocation fails, otherwise an instance
  */
 LIBMEMCACHED_API
-struct memcached_protocol_client_st *memcached_protocol_create_client(struct memcached_protocol_st *instance, int sock);
+memcached_protocol_client_st *memcached_protocol_create_client(memcached_protocol_st *instance, int sock);
 
 /**
  * Destroy a client handle.
- * The caller needs to close the socket accociated with the client 
+ * The caller needs to close the socket accociated with the client
  * <b>before</b> calling this function. This function invalidates the
  * client memory area.
  *
  * @param client the client to destroy
  */
 LIBMEMCACHED_API
-void memcached_protocol_client_destroy(struct memcached_protocol_client_st *client);
+void memcached_protocol_client_destroy(memcached_protocol_client_st *client);
+
+/**
+ * Error event means that the client encountered an error with the
+ * connection so you should shut it down
+ */
+#define MEMCACHED_PROTOCOL_ERROR_EVENT 1
+/**
+ * Please notify when there is more data available to read
+ */
+#define MEMCACHED_PROTOCOL_READ_EVENT 2
+/**
+ * Please notify when it is possible to send more data
+ */
+#define MEMCACHED_PROTOCOL_WRITE_EVENT 4
+/**
+ * Backed paused the execution for this client
+ */
+#define MEMCACHED_PROTOCOL_PAUSE_EVENT 8
 
 /**
- * The different events the client is interested in
+ * The different events the client is interested in. This is a bitmask of
+ * the constants defined above.
  */
-enum MEMCACHED_PROTOCOL_EVENT { 
-   /* Error event means that the client encountered an error with the
-    * connection so you should shut it down */
-   ERROR_EVENT, 
-   /* Please notify when there is more data available to read */
-   READ_EVENT, 
-   /* Please notify when it is possible to send more data */ 
-   WRITE_EVENT, 
-   /* Please notify when it is possible to send or receive data */
-   READ_WRITE_EVENT 
-};
+typedef uint32_t memcached_protocol_event_t;
 
 /**
- * Let the client do some work. This might involve reading / sending data 
+ * Let the client do some work. This might involve reading / sending data
  * to/from the client, or perform callbacks to execute a command.
  * @param client the client structure to work on
  * @return The next event the protocol handler will be notified for
  */
 LIBMEMCACHED_API
-enum MEMCACHED_PROTOCOL_EVENT memcached_protocol_client_work(struct memcached_protocol_client_st *client);
+memcached_protocol_event_t memcached_protocol_client_work(memcached_protocol_client_st *client);
 
 /**
  * Get the socket attached to a client handle
@@ -170,7 +191,7 @@ enum MEMCACHED_PROTOCOL_EVENT memcached_protocol_client_work(struct memcached_pr
  * @return the socket handle
  */
 LIBMEMCACHED_API
-int memcached_protocol_client_get_socket(struct memcached_protocol_client_st *client);
+int memcached_protocol_client_get_socket(memcached_protocol_client_st *client);
 
 /**
  * Get the error id socket attached to a client handle
@@ -178,7 +199,7 @@ int memcached_protocol_client_get_socket(struct memcached_protocol_client_st *cl
  * @return the OS error code from the client
  */
 LIBMEMCACHED_API
-int memcached_protocol_client_get_errno(struct memcached_protocol_client_st *client);
+int memcached_protocol_client_get_errno(memcached_protocol_client_st *client);
 
 /**
  * Get a raw response handler for the given cookie
@@ -188,4 +209,9 @@ int memcached_protocol_client_get_errno(struct memcached_protocol_client_st *cli
  */
 LIBMEMCACHED_API
 memcached_binary_protocol_raw_response_handler memcached_binary_protocol_get_raw_response_handler(const void *cookie);
+
+#ifdef __cplusplus
+}
+#endif
+
 #endif