#include <libmemcached/error.hpp>
#include <libmemcached/memory.h>
#include <libmemcached/io.h>
+#ifdef __cplusplus
+#include <libmemcached/string.hpp>
+#include <libmemcached/io.hpp>
#include <libmemcached/do.hpp>
+#endif
#include <libmemcached/internal.h>
#include <libmemcached/array.h>
#include <libmemcached/libmemcached_probes.h>
return MEMCACHED_WRITE_FAILURE;
if (send_length + instance->write_buffer_offset > MAX_UDP_DATAGRAM_LENGTH)
+ {
memcached_io_write(instance, NULL, 0, true);
+ }
}
rc= memcached_do(instance, buffer, (size_t)send_length, to_write);
libmemcached/initialize_query.h \
libmemcached/internal.h \
libmemcached/io.h \
+ libmemcached/io.hpp \
libmemcached/is.h \
libmemcached/libmemcached_probes.h \
libmemcached/memory.h \
libmemcached/protocol/binary_handler.h \
libmemcached/protocol/common.h \
libmemcached/response.h \
+ libmemcached/string.hpp \
libmemcached/virtual_bucket.h
nobase_include_HEADERS+= \
memcached_return_t memcached_io_readline(memcached_server_write_instance_st ptr,
char *buffer_ptr,
- size_t size)
+ size_t size,
+ size_t& total_nr)
{
+ total_nr= 0;
bool line_complete= false;
- size_t total_nr= 0;
while (not line_complete)
{
#pragma once
-#include <libmemcached/memcached.h>
-
#define MAX_UDP_DATAGRAM_LENGTH 1400
#define UDP_DATAGRAM_HEADER_LENGTH 8
#define UDP_REQUEST_ID_MSG_SIG_DIGITS 10
const void *buffer;
};
-#ifdef __cplusplus
-extern "C" {
-#endif
-
LIBMEMCACHED_LOCAL
-memcached_return_t memcached_io_wait_for_write(memcached_server_write_instance_st ptr);
+ssize_t memcached_io_write(memcached_server_write_instance_st ptr,
+ const void *buffer, size_t length, bool with_flush);
LIBMEMCACHED_LOCAL
ssize_t memcached_io_writev(memcached_server_write_instance_st ptr,
const struct libmemcached_io_vector_st *vector,
size_t number_of, bool with_flush);
-LIBMEMCACHED_LOCAL
-ssize_t memcached_io_write(memcached_server_write_instance_st ptr,
- const void *buffer, size_t length, bool with_flush);
-
-LIBMEMCACHED_LOCAL
-void memcached_io_reset(memcached_server_write_instance_st ptr);
-
-LIBMEMCACHED_LOCAL
-memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr,
- void *buffer, size_t length, ssize_t *nread);
-
-/* Read a line (terminated by '\n') into the buffer */
-LIBMEMCACHED_LOCAL
-memcached_return_t memcached_io_readline(memcached_server_write_instance_st ptr,
- char *buffer_ptr,
- size_t size);
-
-LIBMEMCACHED_LOCAL
-void memcached_io_close(memcached_server_write_instance_st ptr);
-
-/* Read n bytes of data from the server and store them in dta */
-LIBMEMCACHED_LOCAL
-memcached_return_t memcached_safe_read(memcached_server_write_instance_st ptr,
- void *dta,
- size_t size);
-
-LIBMEMCACHED_LOCAL
-memcached_return_t memcached_io_init_udp_header(memcached_server_write_instance_st ptr,
- uint16_t thread_id);
-
-LIBMEMCACHED_LOCAL
-memcached_server_write_instance_st memcached_io_get_readable_server(memcached_st *memc);
-
-LIBMEMCACHED_LOCAL
-memcached_return_t memcached_io_slurp(memcached_server_write_instance_st ptr);
-
-#ifdef __cplusplus
-}
-#endif
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * LibMemcached
+ *
+ * Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ * Copyright (C) 2006-2009 Brian Aker
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * The names of its contributors may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+LIBMEMCACHED_LOCAL
+memcached_return_t memcached_io_wait_for_write(memcached_server_write_instance_st ptr);
+
+LIBMEMCACHED_LOCAL
+void memcached_io_reset(memcached_server_write_instance_st ptr);
+
+LIBMEMCACHED_LOCAL
+memcached_return_t memcached_io_read(memcached_server_write_instance_st ptr,
+ void *buffer, size_t length, ssize_t *nread);
+
+/* Read a line (terminated by '\n') into the buffer */
+LIBMEMCACHED_LOCAL
+memcached_return_t memcached_io_readline(memcached_server_write_instance_st ptr,
+ char *buffer_ptr,
+ size_t size,
+ size_t& total);
+
+LIBMEMCACHED_LOCAL
+void memcached_io_close(memcached_server_write_instance_st ptr);
+
+/* Read n bytes of data from the server and store them in dta */
+LIBMEMCACHED_LOCAL
+memcached_return_t memcached_safe_read(memcached_server_write_instance_st ptr,
+ void *dta,
+ size_t size);
+
+LIBMEMCACHED_LOCAL
+memcached_return_t memcached_io_init_udp_header(memcached_server_write_instance_st ptr,
+ uint16_t thread_id);
+
+LIBMEMCACHED_LOCAL
+memcached_server_write_instance_st memcached_io_get_readable_server(memcached_st *memc);
+
+LIBMEMCACHED_LOCAL
+memcached_return_t memcached_io_slurp(memcached_server_write_instance_st ptr);
+
+#ifdef __cplusplus
+}
+#endif
*/
#include <libmemcached/common.h>
+#include <libmemcached/string.hpp>
static memcached_return_t textual_read_one_response(memcached_server_write_instance_st ptr,
char *buffer, size_t buffer_length,
char *buffer, size_t buffer_length,
memcached_result_st *result)
{
- memcached_return_t rc= memcached_io_readline(ptr, buffer, buffer_length);
+ size_t total_read;
+ memcached_return_t rc= memcached_io_readline(ptr, buffer, buffer_length, total_read);
+
if (memcached_failed(rc))
{
return rc;
}
else if (buffer[1] == 'E') /* SERVER_ERROR */
{
- char *startptr= buffer + 13, *endptr= startptr;
+ if (total_read == memcached_literal_param_size("SERVER_ERROR"))
+ {
+ return MEMCACHED_SERVER_ERROR;
+ }
+
+ if (total_read > memcached_literal_param_size("SERVER_ERROR object too large for cache") and
+ (memcmp(buffer, memcached_literal_param("SERVER_ERROR object too large for cache")) == 0))
+ {
+ return MEMCACHED_E2BIG;
+ }
+
+ // Move past the basic error message and whitespace
+ char *startptr= buffer + memcached_literal_param_size("SERVER_ERROR");
+ if (startptr[0] == ' ')
+ {
+ startptr++;
+ }
+ char *endptr= startptr;
while (*endptr != '\r' && *endptr != '\n') endptr++;
return memcached_set_error(*ptr, MEMCACHED_SERVER_ERROR, MEMCACHED_AT, startptr, size_t(endptr - startptr));
}
#endif
-#ifdef __cplusplus
-#define memcached_literal_param(X) (X), (static_cast<size_t>((sizeof(X) - 1)))
-#else
-#define memcached_literal_param(X) (X), ((size_t)((sizeof(X) - 1)))
-#endif
-
-#define memcached_string_make_from_cstr(X) (X), ((X) ? strlen(X) : 0)
-
#endif
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * libmcachedd client library.
+ *
+ * Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * * The names of its contributors may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#pragma once
+
+#include "util/string.hpp"
+
+#define memcached_literal_param util_literal_param
+#define memcached_literal_param_size util_literal_param_size
+#define memcached_string_make_from_cstr util_string_make_from_cstr
+#define memcached_array_length util_array_length
+
+