X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Foptions%2Fcontext.h;h=7660d2d2a1813b45b1a8e2a6c683d2e71dda9d8c;hb=b16fffff43d822239ce79a366ec36873b0803df9;hp=d65f8ede53ce8659367a37c06cbbf1a078a9b6ab;hpb=de161b27e5e394ea0ae4a88e58fc9ebb21e821d0;p=awesomized%2Flibmemcached diff --git a/libmemcached/options/context.h b/libmemcached/options/context.h index d65f8ede..7660d2d2 100644 --- a/libmemcached/options/context.h +++ b/libmemcached/options/context.h @@ -37,7 +37,7 @@ #pragma once -#include +#include class Context { @@ -90,7 +90,7 @@ public: const char *set_hostname(const char *str, size_t size) { - size_t copy_length= std::min((size_t)NI_MAXHOST, size); + size_t copy_length= (size_t)NI_MAXHOST > size ? size : (size_t)NI_MAXHOST; memcpy(_hostname, str, copy_length); _hostname[copy_length]= 0; @@ -102,6 +102,31 @@ public: return _hostname; } + void abort(const char *error) + { + if (rc == MEMCACHED_SUCCESS) + rc= MEMCACHED_PARSE_ERROR; + + memcached_string_st *error_string= memcached_string_create(memc, NULL, 1024); + memcached_string_append(error_string, memcached_literal_param("Error occured while parsing: ")); + memcached_string_append(error_string, memcached_string_make_from_cstr(begin)); + memcached_string_append(error_string, memcached_literal_param(" (")); + + if (rc == MEMCACHED_PARSE_ERROR and error) + { + memcached_string_append(error_string, memcached_string_make_from_cstr(error)); + } + else + { + memcached_string_append(error_string, memcached_string_make_from_cstr(memcached_strerror(NULL, rc))); + } + memcached_string_append(error_string, memcached_literal_param(")")); + + memcached_set_error_string(memc, rc, memcached_string_value(error_string), memcached_string_length(error_string)); + + memcached_string_free(error_string); + } + ~Context() { destroy_scanner();