87
90
memcached_error_free(memc);
90
// For memory allocation we use our error since it is a bit more specific
91
if (local_errno == ENOMEM and rc == MEMCACHED_ERRNO)
93
rc= MEMCACHED_MEMORY_ALLOCATION_FAILURE;
96
if (rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE)
101
if (rc == MEMCACHED_ERRNO and not local_errno)
107
if (rc == MEMCACHED_ERRNO and local_errno == ENOTCONN)
109
rc= MEMCACHED_CONNECTION_FAILURE;
112
if (rc == MEMCACHED_ERRNO and local_errno == ECONNRESET)
114
rc= MEMCACHED_CONNECTION_FAILURE;
117
if (local_errno == EINVAL)
119
rc= MEMCACHED_INVALID_ARGUMENTS;
122
if (local_errno == ECONNREFUSED)
124
rc= MEMCACHED_CONNECTION_FAILURE;
127
memcached_error_t *error= libmemcached_xmalloc(&memc, memcached_error_t);
128
if (error == NULL) // Bad business if this happens
134
error->query_id= memc.query_id;
136
error->local_errno= local_errno;
138
const char *errmsg_ptr;
139
char errmsg[MAX_ERROR_LENGTH];
93
if (memcached_fatal(rc) or rc == MEMCACHED_CLIENT_ERROR)
95
// For memory allocation we use our error since it is a bit more specific
96
if (local_errno == ENOMEM and rc == MEMCACHED_ERRNO)
98
rc= MEMCACHED_MEMORY_ALLOCATION_FAILURE;
101
if (rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE)
106
if (rc == MEMCACHED_ERRNO and not local_errno)
112
if (rc == MEMCACHED_ERRNO and local_errno == ENOTCONN)
114
rc= MEMCACHED_CONNECTION_FAILURE;
117
if (rc == MEMCACHED_ERRNO and local_errno == ECONNRESET)
119
rc= MEMCACHED_CONNECTION_FAILURE;
122
if (local_errno == EINVAL)
124
rc= MEMCACHED_INVALID_ARGUMENTS;
127
if (local_errno == ECONNREFUSED)
129
rc= MEMCACHED_CONNECTION_FAILURE;
132
if (rc == MEMCACHED_TIMEOUT)
136
memcached_error_t *error= libmemcached_xmalloc(&memc, memcached_error_t);
137
if (error == NULL) // Bad business if this happens
139
assert_msg(error, "libmemcached_xmalloc() failed to allocate a memcached_error_t");
144
error->query_id= memc.query_id;
146
error->local_errno= local_errno;
148
// MEMCACHED_CLIENT_ERROR is a special case because it is an error coming from the server
149
if (rc == MEMCACHED_CLIENT_ERROR)
153
if (str and str->size)
155
assert(error->local_errno == 0);
156
error->local_errno= 0;
158
error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %.*s",
160
int(str->size), str->c_str);
163
else if (local_errno)
165
const char *errmsg_ptr;
166
char errmsg[MAX_ERROR_LENGTH];
145
170
#if defined(STRERROR_R_CHAR_P) && STRERROR_R_CHAR_P
146
errmsg_ptr= strerror_r(local_errno, errmsg, sizeof(errmsg));
171
errmsg_ptr= strerror_r(local_errno, errmsg, sizeof(errmsg));
147
172
#elif defined(HAVE_STRERROR_R) && HAVE_STRERROR_R
148
strerror_r(local_errno, errmsg, sizeof(errmsg));
173
strerror_r(local_errno, errmsg, sizeof(errmsg));
150
175
#elif defined(HAVE_STRERROR) && HAVE_STRERROR
151
snprintf(errmsg, sizeof(errmsg), "%s", strerror(local_errno));
176
snprintf(errmsg, sizeof(errmsg), "%s", strerror(local_errno));
157
if (str and str->size and local_errno)
159
error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s(%s), %.*s -> %s",
161
memcached_strerror(&memc, rc),
163
memcached_string_printf(*str), at);
165
else if (local_errno)
167
error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s(%s) -> %s",
169
memcached_strerror(&memc, rc),
173
else if (rc == MEMCACHED_PARSE_ERROR and str and str->size)
175
error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %.*s -> %s",
177
int(str->size), str->c_str, at);
179
else if (str and str->size)
181
error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s, %.*s -> %s",
183
memcached_strerror(&memc, rc),
184
int(str->size), str->c_str, at);
188
error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s -> %s",
190
memcached_strerror(&memc, rc), at);
193
error->next= memc.error_messages;
194
memc.error_messages= error;
180
if (str and str->size and local_errno)
182
error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s(%s), %.*s -> %s",
184
memcached_strerror(&memc, rc),
186
memcached_string_printf(*str), at);
190
error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s(%s) -> %s",
192
memcached_strerror(&memc, rc),
197
else if (rc == MEMCACHED_PARSE_ERROR and str and str->size)
199
error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %.*s -> %s",
201
int(str->size), str->c_str, at);
203
else if (str and str->size)
205
error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s, %.*s -> %s",
207
memcached_strerror(&memc, rc),
208
int(str->size), str->c_str, at);
212
error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s -> %s",
214
memcached_strerror(&memc, rc), at);
217
error->next= memc.error_messages;
218
memc.error_messages= error;
197
222
if (error_log_fd == -1)