From: Brian Aker Date: Tue, 14 Jun 2011 23:14:33 +0000 (-0700) Subject: This creates memcached_htonll() to be used internally (we want to avoid conflicts... X-Git-Tag: 0.51~4^2~11 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=56baf2c0a1a9a6111637dffeea16f997307320ee;p=m6w6%2Flibmemcached This creates memcached_htonll() to be used internally (we want to avoid conflicts around htonll). Also, this version includes an update to the server startup so that we don't try to shutdown anything we didn't start. --- diff --git a/clients/memcapable.cc b/clients/memcapable.cc index baac28b2..9c9feb52 100644 --- a/clients/memcapable.cc +++ b/clients/memcapable.cc @@ -297,7 +297,7 @@ static enum test_return send_packet(command *cmd) cmd->plain.message.header.request.bodylen= ntohl(cmd->plain.message.header.request.bodylen); cmd->plain.message.header.request.cas= - ntohll(cmd->plain.message.header.request.cas); + memcached_ntohll(cmd->plain.message.header.request.cas); execute(resend_packet(cmd)); return TEST_PASS; @@ -343,7 +343,7 @@ static enum test_return recv_packet(response *rsp) rsp->plain.message.header.response.bodylen= ntohl(rsp->plain.message.header.response.bodylen); rsp->plain.message.header.response.cas= - ntohll(rsp->plain.message.header.response.cas); + memcached_ntohll(rsp->plain.message.header.response.cas); size_t bodysz= rsp->plain.message.header.response.bodylen; if (bodysz > 0) @@ -472,8 +472,8 @@ static void arithmetic_command(command *cmd, cmd->incr.message.header.request.extlen= 20; cmd->incr.message.header.request.bodylen= (uint32_t)(keylen + 20); cmd->incr.message.header.request.opaque= 0xdeadbeef; - cmd->incr.message.body.delta= htonll(delta); - cmd->incr.message.body.initial= htonll(initial); + cmd->incr.message.body.delta= memcached_htonll(delta); + cmd->incr.message.body.initial= memcached_htonll(initial); cmd->incr.message.body.expiration= htonl(exptime); off_t key_offset= sizeof (protocol_binary_request_no_extras) + 20; @@ -690,8 +690,7 @@ static enum test_return test_binary_set_impl(const char* key, uint8_t cc) } /* try to set with the correct CAS value */ - cmd.plain.message.header.request.cas= - htonll(rsp.plain.message.header.response.cas); + cmd.plain.message.header.request.cas= memcached_htonll(rsp.plain.message.header.response.cas); execute(resend_packet(&cmd)); if (cc == PROTOCOL_BINARY_CMD_SET) { @@ -702,8 +701,7 @@ static enum test_return test_binary_set_impl(const char* key, uint8_t cc) execute(test_binary_noop()); /* try to set with an incorrect CAS value */ - cmd.plain.message.header.request.cas= - htonll(rsp.plain.message.header.response.cas - 1); + cmd.plain.message.header.request.cas= memcached_htonll(rsp.plain.message.header.response.cas - 1); execute(resend_packet(&cmd)); execute(send_binary_noop()); execute(recv_packet(&rsp)); @@ -819,8 +817,7 @@ static enum test_return test_binary_replace_impl(const char* key, uint8_t cc) } /* verify that replace with CAS value works! */ - cmd.plain.message.header.request.cas= - htonll(rsp.plain.message.header.response.cas); + cmd.plain.message.header.request.cas= memcached_htonll(rsp.plain.message.header.response.cas); execute(resend_packet(&cmd)); if (cc == PROTOCOL_BINARY_CMD_REPLACE) @@ -832,8 +829,7 @@ static enum test_return test_binary_replace_impl(const char* key, uint8_t cc) execute(test_binary_noop()); /* try to set with an incorrect CAS value */ - cmd.plain.message.header.request.cas= - htonll(rsp.plain.message.header.response.cas - 1); + cmd.plain.message.header.request.cas= memcached_htonll(rsp.plain.message.header.response.cas - 1); execute(resend_packet(&cmd)); execute(send_binary_noop()); execute(recv_packet(&rsp)); @@ -956,7 +952,7 @@ static enum test_return test_binary_incr_impl(const char* key, uint8_t cc) { execute(recv_packet(&rsp)); verify(validate_response_header(&rsp, cc, PROTOCOL_BINARY_RESPONSE_SUCCESS)); - verify(ntohll(rsp.incr.message.body.value) == ii); + verify(memcached_ntohll(rsp.incr.message.body.value) == ii); } else execute(test_binary_noop()); @@ -994,7 +990,7 @@ static enum test_return test_binary_decr_impl(const char* key, uint8_t cc) { execute(recv_packet(&rsp)); verify(validate_response_header(&rsp, cc, PROTOCOL_BINARY_RESPONSE_SUCCESS)); - verify(ntohll(rsp.decr.message.body.value) == (uint64_t)ii); + verify(memcached_ntohll(rsp.decr.message.body.value) == (uint64_t)ii); } else execute(test_binary_noop()); @@ -1006,7 +1002,7 @@ static enum test_return test_binary_decr_impl(const char* key, uint8_t cc) { execute(recv_packet(&rsp)); verify(validate_response_header(&rsp, cc, PROTOCOL_BINARY_RESPONSE_SUCCESS)); - verify(ntohll(rsp.decr.message.body.value) == 0); + verify(memcached_ntohll(rsp.decr.message.body.value) == 0); } else { diff --git a/example/interface_v0.c b/example/interface_v0.c index 74a98eaf..a5462734 100644 --- a/example/interface_v0.c +++ b/example/interface_v0.c @@ -78,7 +78,7 @@ static protocol_binary_response_status get_command_handler(const void *cookie, msg.response.message.body.flags= htonl(item->flags); char *ptr= (char*)(msg.response.bytes + sizeof(*header) + 4); uint32_t bodysize= 4; - msg.response.message.header.response.cas= htonll(item->cas); + msg.response.message.header.response.cas= memcached_htonll(item->cas); if (opcode == PROTOCOL_BINARY_CMD_GETK || opcode == PROTOCOL_BINARY_CMD_GETKQ) { memcpy(ptr, item->key, item->nkey); @@ -172,8 +172,8 @@ static protocol_binary_response_status arithmetic_command_handler(const void *co }; uint16_t keylen= ntohs(header->request.keylen); - uint64_t initial= ntohll(req->message.body.initial); - uint64_t delta= ntohll(req->message.body.delta); + uint64_t initial= memcached_ntohll(req->message.body.initial); + uint64_t delta= memcached_ntohll(req->message.body.delta); uint32_t expiration= ntohl(req->message.body.expiration); uint32_t flags= 0; void *key= req->bytes + sizeof(req->bytes); @@ -222,8 +222,8 @@ static protocol_binary_response_status arithmetic_command_handler(const void *co if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS) { response.message.header.response.bodylen= ntohl(8); - response.message.body.value= ntohll((*(uint64_t*)item->data)); - response.message.header.response.cas= ntohll(item->cas); + response.message.body.value= memcached_ntohll((*(uint64_t*)item->data)); + response.message.header.response.cas= memcached_ntohll(item->cas); release_item(item); if (header->request.opcode == PROTOCOL_BINARY_CMD_INCREMENTQ || @@ -250,6 +250,7 @@ static protocol_binary_response_status version_command_handler(const void *cooki .opcode= PROTOCOL_BINARY_CMD_VERSION, .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), .opaque= header->request.opaque, + .cas= 0, .bodylen= htonl((uint32_t)strlen(versionstring)) } }; @@ -265,7 +266,7 @@ static protocol_binary_response_status concat_command_handler(const void *cookie { protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS; uint16_t keylen= ntohs(header->request.keylen); - uint64_t cas= ntohll(header->request.cas); + uint64_t cas= memcached_ntohll(header->request.cas); void *key= header + 1; uint32_t vallen= ntohl(header->request.bodylen) - keylen; void *val= (char*)key + keylen; @@ -316,7 +317,7 @@ static protocol_binary_response_status concat_command_handler(const void *cookie .opcode= header->request.opcode, .status= htons(rval), .opaque= header->request.opaque, - .cas= htonll(cas), + .cas= memcached_htonll(cas), } } }; @@ -356,7 +357,7 @@ static protocol_binary_response_status set_command_handler(const void *cookie, struct item* item= get_item(key, keylen); if (item != NULL) { - if (item->cas != ntohll(header->request.cas)) + if (item->cas != memcached_ntohll(header->request.cas)) { release_item(item); response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS); @@ -378,7 +379,7 @@ static protocol_binary_response_status set_command_handler(const void *cookie, /* SETQ shouldn't return a message */ if (header->request.opcode == PROTOCOL_BINARY_CMD_SET) { - response.message.header.response.cas= htonll(item->cas); + response.message.header.response.cas= memcached_htonll(item->cas); release_item(item); return response_handler(cookie, header, (void*)&response); } @@ -425,7 +426,7 @@ static protocol_binary_response_status add_command_handler(const void *cookie, /* ADDQ shouldn't return a message */ if (header->request.opcode == PROTOCOL_BINARY_CMD_ADD) { - response.message.header.response.cas= htonll(item->cas); + response.message.header.response.cas= memcached_htonll(item->cas); release_item(item); return response_handler(cookie, header, (void*)&response); } @@ -467,21 +468,26 @@ static protocol_binary_response_status replace_command_handler(const void *cooki struct item* item= get_item(key, keylen); if (item == NULL) + { response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_KEY_ENOENT); - else if (header->request.cas == 0 || ntohll(header->request.cas) == item->cas) + } + else if (header->request.cas == 0 || memcached_ntohll(header->request.cas) == item->cas) { release_item(item); delete_item(key, keylen); item= create_item(key, keylen, data, datalen, flags, timeout); + if (item == NULL) + { response.message.header.response.status= htons(PROTOCOL_BINARY_RESPONSE_ENOMEM); + } else { put_item(item); /* REPLACEQ shouldn't return a message */ if (header->request.opcode == PROTOCOL_BINARY_CMD_REPLACE) { - response.message.header.response.cas= htonll(item->cas); + response.message.header.response.cas= memcached_htonll(item->cas); release_item(item); return response_handler(cookie, header, (void*)&response); } diff --git a/libmemcached/auto.cc b/libmemcached/auto.cc index d7289f06..2bfc5bba 100644 --- a/libmemcached/auto.cc +++ b/libmemcached/auto.cc @@ -137,8 +137,8 @@ static memcached_return_t binary_incr_decr(memcached_st *ptr, uint8_t cmd, request.message.header.request.extlen= 20; request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES; request.message.header.request.bodylen= htonl((uint32_t)(key_length + memcached_array_size(ptr->prefix_key) +request.message.header.request.extlen)); - request.message.body.delta= htonll(offset); - request.message.body.initial= htonll(initial); + request.message.body.delta= memcached_htonll(offset); + request.message.body.initial= memcached_htonll(initial); request.message.body.expiration= htonl((uint32_t) expiration); struct libmemcached_io_vector_st vector[]= diff --git a/libmemcached/byteorder.cc b/libmemcached/byteorder.cc index ab35a9ef..80ea0210 100644 --- a/libmemcached/byteorder.cc +++ b/libmemcached/byteorder.cc @@ -35,7 +35,12 @@ * */ -#include +#include + +#include + +#include +#include /* Byte swap a 64-bit number. */ #ifndef swap64 @@ -58,6 +63,20 @@ static inline uint64_t swap64(uint64_t in) } #endif +#ifdef HAVE_HTONLL + +uint64_t memcached_ntohll(uint64_t value) +{ + return ntohll(value); +} + +uint64_t memcached_htonll(uint64_t value) +{ + return htonll(value); +} + +#else // HAVE_HTONLL + uint64_t memcached_ntohll(uint64_t value) { return swap64(value); @@ -67,3 +86,5 @@ uint64_t memcached_htonll(uint64_t value) { return swap64(value); } + +#endif // HAVE_HTONLL diff --git a/libmemcached/byteorder.h b/libmemcached/byteorder.h index f78790a8..92687c1d 100644 --- a/libmemcached/byteorder.h +++ b/libmemcached/byteorder.h @@ -37,36 +37,16 @@ #pragma once -#if HAVE_SYS_TYPES_H -#include -#endif - -#ifndef HAVE_HTONLL -#define ntohll(a) memcached_ntohll(a) -#define htonll(a) memcached_htonll(a) - #ifdef __cplusplus extern "C" { #endif LIBMEMCACHED_LOCAL uint64_t memcached_ntohll(uint64_t); + LIBMEMCACHED_LOCAL uint64_t memcached_htonll(uint64_t); + #ifdef __cplusplus } #endif - -#endif - -#ifdef linux -/* /usr/include/netinet/in.h defines macros from ntohs() to _bswap_nn to - * optimize the conversion functions, but the prototypes generate warnings - * from gcc. The conversion methods isn't the bottleneck for my app, so - * just remove the warnings by undef'ing the optimization .. - */ -#undef ntohs -#undef ntohl -#undef htons -#undef htonl -#endif diff --git a/libmemcached/protocol/binary_handler.c b/libmemcached/protocol/binary_handler.c index 93fb3162..0997ebb0 100644 --- a/libmemcached/protocol/binary_handler.c +++ b/libmemcached/protocol/binary_handler.c @@ -155,7 +155,7 @@ get_response_handler(const void *cookie, .opcode= opcode, .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), .opaque= client->current_command->request.opaque, - .cas= htonll(cas), + .cas= memcached_htonll(cas), .keylen= htons(keylen), .extlen= 4, .bodylen= htonl(bodylen + keylen + 4), @@ -184,12 +184,12 @@ get_response_handler(const void *cookie, * @param body the length of the body * @param bodylen the length of the body */ -static protocol_binary_response_status -stat_response_handler(const void *cookie, - const void *key, - uint16_t keylen, - const void *body, - uint32_t bodylen) { +static protocol_binary_response_status stat_response_handler(const void *cookie, + const void *key, + uint16_t keylen, + const void *body, + uint32_t bodylen) +{ memcached_protocol_client_st *client= (void*)cookie; @@ -201,6 +201,7 @@ stat_response_handler(const void *cookie, .opaque= client->current_command->request.opaque, .keylen= htons(keylen), .bodylen= htonl(bodylen + keylen), + .cas= 0 }, }; @@ -236,6 +237,7 @@ version_response_handler(const void *cookie, .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), .opaque= client->current_command->request.opaque, .bodylen= htonl(textlen), + .cas= 0 }, }; @@ -291,7 +293,7 @@ add_command_handler(const void *cookie, .opcode= PROTOCOL_BINARY_CMD_ADD, .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), .opaque= header->request.opaque, - .cas= ntohll(cas) + .cas= memcached_ntohll(cas) } } }; @@ -326,8 +328,8 @@ decrement_command_handler(const void *cookie, { uint16_t keylen= ntohs(header->request.keylen); protocol_binary_request_decr *request= (void*)header; - uint64_t init= ntohll(request->message.body.initial); - uint64_t delta= ntohll(request->message.body.delta); + uint64_t init= memcached_ntohll(request->message.body.initial); + uint64_t delta= memcached_ntohll(request->message.body.delta); uint32_t timeout= ntohl(request->message.body.expiration); void *key= request->bytes + sizeof(request->bytes); uint64_t result; @@ -347,10 +349,10 @@ decrement_command_handler(const void *cookie, .opcode= PROTOCOL_BINARY_CMD_DECREMENT, .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), .opaque= header->request.opaque, - .cas= ntohll(cas), + .cas= memcached_ntohll(cas), .bodylen= htonl(8) }, - .body.value= htonll(result) + .body.value= memcached_htonll(result) } }; rval= response_handler(cookie, header, (void*)&response); @@ -383,8 +385,8 @@ delete_command_handler(const void *cookie, if (client->root->callback->interface.v1.delete != NULL) { uint16_t keylen= ntohs(header->request.keylen); - void *key= (header + 1); - uint64_t cas= ntohll(header->request.cas); + void *key= (header +1); + uint64_t cas= memcached_ntohll(header->request.cas); rval= client->root->callback->interface.v1.delete(cookie, key, keylen, cas); if (rval == PROTOCOL_BINARY_RESPONSE_SUCCESS && header->request.opcode == PROTOCOL_BINARY_CMD_DELETE) @@ -521,8 +523,8 @@ increment_command_handler(const void *cookie, { uint16_t keylen= ntohs(header->request.keylen); protocol_binary_request_incr *request= (void*)header; - uint64_t init= ntohll(request->message.body.initial); - uint64_t delta= ntohll(request->message.body.delta); + uint64_t init= memcached_ntohll(request->message.body.initial); + uint64_t delta= memcached_ntohll(request->message.body.delta); uint32_t timeout= ntohl(request->message.body.expiration); void *key= request->bytes + sizeof(request->bytes); uint64_t cas; @@ -542,10 +544,10 @@ increment_command_handler(const void *cookie, .opcode= PROTOCOL_BINARY_CMD_INCREMENT, .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), .opaque= header->request.opaque, - .cas= ntohll(cas), + .cas= memcached_ntohll(cas), .bodylen= htonl(8) }, - .body.value= htonll(result) + .body.value= memcached_htonll(result) } }; @@ -614,9 +616,9 @@ append_command_handler(const void *cookie, { uint16_t keylen= ntohs(header->request.keylen); uint32_t datalen= ntohl(header->request.bodylen) - keylen; - char *key= (void*)(header + 1); - char *data= key + keylen; - uint64_t cas= ntohll(header->request.cas); + char *key= (void*)(header +1); + char *data= key +keylen; + uint64_t cas= memcached_ntohll(header->request.cas); uint64_t result_cas; rval= client->root->callback->interface.v1.append(cookie, key, keylen, @@ -633,7 +635,7 @@ append_command_handler(const void *cookie, .opcode= PROTOCOL_BINARY_CMD_APPEND, .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), .opaque= header->request.opaque, - .cas= ntohll(result_cas), + .cas= memcached_ntohll(result_cas), }, } }; @@ -670,7 +672,7 @@ prepend_command_handler(const void *cookie, uint32_t datalen= ntohl(header->request.bodylen) - keylen; char *key= (char*)(header + 1); char *data= key + keylen; - uint64_t cas= ntohll(header->request.cas); + uint64_t cas= memcached_ntohll(header->request.cas); uint64_t result_cas; rval= client->root->callback->interface.v1.prepend(cookie, key, keylen, data, datalen, cas, @@ -686,7 +688,7 @@ prepend_command_handler(const void *cookie, .opcode= PROTOCOL_BINARY_CMD_PREPEND, .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), .opaque= header->request.opaque, - .cas= ntohll(result_cas), + .cas= memcached_ntohll(result_cas), }, } }; @@ -764,7 +766,7 @@ replace_command_handler(const void *cookie, uint32_t timeout= ntohl(request->message.body.expiration); char *key= ((char*)header) + sizeof(*header) + 8; char *data= key + keylen; - uint64_t cas= ntohll(header->request.cas); + uint64_t cas= memcached_ntohll(header->request.cas); uint64_t result_cas; rval= client->root->callback->interface.v1.replace(cookie, key, keylen, @@ -782,7 +784,7 @@ replace_command_handler(const void *cookie, .opcode= PROTOCOL_BINARY_CMD_REPLACE, .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), .opaque= header->request.opaque, - .cas= ntohll(result_cas), + .cas= memcached_ntohll(result_cas), }, } }; @@ -822,7 +824,7 @@ set_command_handler(const void *cookie, uint32_t timeout= ntohl(request->message.body.expiration); char *key= ((char*)header) + sizeof(*header) + 8; char *data= key + keylen; - uint64_t cas= ntohll(header->request.cas); + uint64_t cas= memcached_ntohll(header->request.cas); uint64_t result_cas; @@ -840,7 +842,7 @@ set_command_handler(const void *cookie, .opcode= PROTOCOL_BINARY_CMD_SET, .status= htons(PROTOCOL_BINARY_RESPONSE_SUCCESS), .opaque= header->request.opaque, - .cas= ntohll(result_cas), + .cas= memcached_ntohll(result_cas), }, } }; diff --git a/libmemcached/response.cc b/libmemcached/response.cc index 6ee62af0..d3d2510e 100644 --- a/libmemcached/response.cc +++ b/libmemcached/response.cc @@ -384,7 +384,7 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan header.response.keylen= ntohs(header.response.keylen); header.response.status= ntohs(header.response.status); header.response.bodylen= ntohl(header.response.bodylen); - header.response.cas= ntohll(header.response.cas); + header.response.cas= memcached_ntohll(header.response.cas); uint32_t bodylen= header.response.bodylen; if (header.response.status == PROTOCOL_BINARY_RESPONSE_SUCCESS || @@ -450,7 +450,7 @@ static memcached_return_t binary_read_one_response(memcached_server_write_instan return MEMCACHED_UNKNOWN_READ_FAILURE; } - val= ntohll(val); + val= memcached_ntohll(val); memcpy(buffer, &val, sizeof(val)); } break; diff --git a/libmemcached/storage.cc b/libmemcached/storage.cc index c6d653c1..95d93c76 100644 --- a/libmemcached/storage.cc +++ b/libmemcached/storage.cc @@ -493,7 +493,7 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, request.message.header.request.extlen)); if (cas) - request.message.header.request.cas= htonll(cas); + request.message.header.request.cas= memcached_htonll(cas); flush= (bool) ((server->root->flags.buffer_requests && verb == SET_OP) ? 0 : 1); diff --git a/libtest/server.c b/libtest/server.c index 1c3ea100..dac57c77 100644 --- a/libtest/server.c +++ b/libtest/server.c @@ -178,6 +178,7 @@ void server_startup(server_startup_st *construct) if (libmemcached_util_flush("localhost", construct->port[x], NULL)) { fprintf(stderr, "Found server on port %d, flushed it!\n", (int)construct->port[x]); + construct->is_used[x]= true; } // If we can flush it, we will just use it else { @@ -202,15 +203,22 @@ void server_startup(server_startup_st *construct) MEMCACHED_BINARY, construct->pid_file[x], construct->port[x], construct->port[x]); } - if (libmemcached_util_ping("localhost", construct->port[x], NULL)) - { - fprintf(stderr, "Server on port %u already exists\n", construct->port[x]); - } - else - { - status= system(buffer); - fprintf(stderr, "STARTING SERVER: %s status:%d\n", buffer, status); - } + if (construct->is_used[x]) + { + fprintf(stderr, "USING SERVER: %s\n", buffer); + } + else + { + if (libmemcached_util_ping("localhost", construct->port[x], NULL)) + { + fprintf(stderr, "Server on port %u already exists\n", construct->port[x]); + } + else + { + status= system(buffer); + fprintf(stderr, "STARTING SERVER: %s status:%d\n", buffer, status); + } + } int count; size_t remaining_length= sizeof(server_string_buffer) - (size_t)(end_ptr -server_string_buffer); @@ -237,6 +245,10 @@ void server_startup(server_startup_st *construct) for (uint32_t x= 0; x < construct->count; x++) { uint32_t counter= 3000; // Absurd, just to catch run away process + + if (construct->is_used[x]) + continue; + while (construct->pids[x] <= 0 && --counter) { FILE *file= fopen(construct->pid_file[x], "r"); @@ -255,12 +267,13 @@ void server_startup(server_startup_st *construct) } fclose(file); } + switch (errno) { default: - fprintf(stderr, "Could not open pid file %s -> fopen(%s) -> %s:%d\n", construct->pid_file[x], strerror(errno), - __FILE__, __LINE__); + fprintf(stderr, "Could not open pid file %s -> fopen(%s) -> %s:%d\n", construct->pid_file[x], strerror(errno), __FILE__, __LINE__); abort(); + case ENOENT: case EINTR: case EACCES: @@ -331,6 +344,9 @@ void server_shutdown(server_startup_st *construct) { for (uint32_t x= 0; x < construct->count; x++) { + if (construct->is_used[x]) + continue; + kill_file(construct->pid_file[x]); } diff --git a/libtest/server.h b/libtest/server.h index 454f69ca..581cf859 100644 --- a/libtest/server.h +++ b/libtest/server.h @@ -32,6 +32,7 @@ struct server_startup_st char pid_file[SERVERS_TO_CREATE][FILENAME_MAX]; in_port_t port[SERVERS_TO_CREATE]; int pids[SERVERS_TO_CREATE]; + bool is_used[SERVERS_TO_CREATE]; // Did we start it, or was it just sitting there? }; void server_startup(server_startup_st *construct); diff --git a/tests/mem_functions.cc b/tests/mem_functions.cc index c74b6b1e..338e23c8 100644 --- a/tests/mem_functions.cc +++ b/tests/mem_functions.cc @@ -2581,34 +2581,34 @@ static test_return_t user_supplied_bug9(memcached_st *memc) static test_return_t user_supplied_bug10(memcached_st *memc) { const char *key= "foo"; - char *value; size_t value_length= 512; - unsigned int x; size_t key_len= 3; unsigned int set= 1; memcached_st *mclone= memcached_clone(NULL, memc); - int32_t timeout; memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_NO_BLOCK, set); memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, set); - timeout= 2; - memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, - (uint64_t)timeout); + int32_t timeout= 0; + memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, (uint64_t)timeout); - value = (char*)malloc(value_length * sizeof(char)); + char *value= (char*)malloc(value_length * sizeof(char)); - for (x= 0; x < value_length; x++) + for (unsigned int x= 0; x < value_length; x++) + { value[x]= (char) (x % 127); + } - for (x= 1; x <= 100000; ++x) + for (unsigned int x= 1; x <= 100000; ++x) { memcached_return_t rc= memcached_set(mclone, key, key_len,value, value_length, 0, 0); - test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_WRITE_FAILURE || - rc == MEMCACHED_BUFFERED || rc == MEMCACHED_TIMEOUT); + test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_WRITE_FAILURE or rc == MEMCACHED_BUFFERED or rc == MEMCACHED_TIMEOUT or rc == MEMCACHED_CONNECTION_FAILURE, + memcached_strerror(NULL, rc)); - if (rc == MEMCACHED_WRITE_FAILURE || rc == MEMCACHED_TIMEOUT) + if (rc == MEMCACHED_WRITE_FAILURE or rc == MEMCACHED_TIMEOUT) + { x--; + } } free(value); @@ -2623,33 +2623,31 @@ static test_return_t user_supplied_bug10(memcached_st *memc) static test_return_t user_supplied_bug11(memcached_st *memc) { const char *key= "foo"; - char *value; size_t value_length= 512; - unsigned int x; size_t key_len= 3; - memcached_return_t rc; unsigned int set= 1; - int32_t timeout; memcached_st *mclone= memcached_clone(NULL, memc); memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_NO_BLOCK, set); memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, set); - timeout= -1; - memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, - (size_t)timeout); + int32_t timeout= -1; + memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, (size_t)timeout); timeout= (int32_t)memcached_behavior_get(mclone, MEMCACHED_BEHAVIOR_POLL_TIMEOUT); test_true(timeout == -1); - value = (char*)malloc(value_length * sizeof(char)); + char *value= (char*)malloc(value_length * sizeof(char)); - for (x= 0; x < value_length; x++) + for (unsigned int x= 0; x < value_length; x++) + { value[x]= (char) (x % 127); + } - for (x= 1; x <= 100000; ++x) + for (unsigned int x= 1; x <= 100000; ++x) { - rc= memcached_set(mclone, key, key_len,value, value_length, 0, 0); + memcached_return_t rc= memcached_set(mclone, key, key_len,value, value_length, 0, 0); + (void)rc; } free(value); @@ -4065,15 +4063,13 @@ static test_return_t pre_settimer(memcached_st *memc) static test_return_t poll_timeout(memcached_st *memc) { - size_t timeout; - - timeout= 100; + size_t timeout= 100; // Not using, just checking that it sets memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, timeout); timeout= (size_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT); - test_true(timeout == 100); + test_compare(100, timeout); return TEST_SUCCESS; }