X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fprotocol%2Fprotocol_handler.c;h=fb90001db940548c385c635c71c671050d4b8c1c;hb=8fd8f655540e3d6aa0b0a3eb0f4f7df1be2e6542;hp=12cf248c18566db06e83250efd964d06425e2165;hpb=a148d541d261c9c867c412e773920f5a1973bbae;p=m6w6%2Flibmemcached diff --git a/libmemcached/protocol/protocol_handler.c b/libmemcached/protocol/protocol_handler.c index 12cf248c..fb90001d 100644 --- a/libmemcached/protocol/protocol_handler.c +++ b/libmemcached/protocol/protocol_handler.c @@ -118,18 +118,19 @@ static bool drain_output(struct memcached_protocol_client_st *client) static struct chunk_st *allocate_output_chunk(struct memcached_protocol_client_st *client) { struct chunk_st *ret= cache_alloc(client->root->buffer_cache); + if (ret == NULL) { return NULL; } - ret->offset = ret->nbytes = 0; - ret->next = NULL; - ret->size = CHUNK_BUFFERSIZE; + ret->offset= ret->nbytes= 0; + ret->next= NULL; + ret->size= CHUNK_BUFFERSIZE; ret->data= (void*)(ret + 1); if (client->output == NULL) { - client->output = client->output_tail = ret; + client->output= client->output_tail= ret; } else { @@ -158,7 +159,7 @@ static protocol_binary_response_status spool_output(struct memcached_protocol_cl return PROTOCOL_BINARY_RESPONSE_SUCCESS; } - size_t offset = 0; + size_t offset= 0; struct chunk_st *chunk= client->output; while (offset < length) @@ -171,10 +172,10 @@ static protocol_binary_response_status spool_output(struct memcached_protocol_cl } } - size_t bulk = length - offset; + size_t bulk= length - offset; if (bulk > chunk->size - chunk->nbytes) { - bulk = chunk->size - chunk->nbytes; + bulk= chunk->size - chunk->nbytes; } memcpy(chunk->data + chunk->nbytes, data, bulk); @@ -193,7 +194,7 @@ static protocol_binary_response_status spool_output(struct memcached_protocol_cl * so the implementors needs to provide an implementation of that interface * */ -static enum MEMCACHED_PROTOCOL_EVENT determine_protocol(struct memcached_protocol_client_st *client, ssize_t *length, void **endptr) +static memcached_protocol_event_t determine_protocol(struct memcached_protocol_client_st *client, ssize_t *length, void **endptr) { if (*client->root->input_buffer == (uint8_t)PROTOCOL_BINARY_REQ) { @@ -219,7 +220,7 @@ static enum MEMCACHED_PROTOCOL_EVENT determine_protocol(struct memcached_protoco const char *err= "CLIENT_ERROR: Unsupported protocol\r\n"; client->root->spool(client, err, strlen(err)); client->root->drain(client); - return ERROR_EVENT; /* Unsupported protocol */ + return MEMCACHED_PROTOCOL_ERROR_EVENT; /* Unsupported protocol */ } return client->work(client, length, endptr); @@ -249,10 +250,11 @@ struct memcached_protocol_st *memcached_protocol_create_instance(void) return NULL; } - ret->buffer_cache = cache_create("protocol_handler", + ret->buffer_cache= cache_create("protocol_handler", CHUNK_BUFFERSIZE + sizeof(struct chunk_st), 0, NULL, NULL); - if (ret->buffer_cache == NULL) { + if (ret->buffer_cache == NULL) + { free(ret->input_buffer); free(ret); } @@ -286,7 +288,7 @@ void memcached_protocol_client_destroy(struct memcached_protocol_client_st *clie free(client); } -enum MEMCACHED_PROTOCOL_EVENT memcached_protocol_client_work(struct memcached_protocol_client_st *client) +memcached_protocol_event_t memcached_protocol_client_work(struct memcached_protocol_client_st *client) { /* Try to send data and read from the socket */ bool more_data= true; @@ -312,9 +314,10 @@ enum MEMCACHED_PROTOCOL_EVENT memcached_protocol_client_work(struct memcached_pr } void *endptr; - if (client->work(client, &len, &endptr) == ERROR_EVENT) + memcached_protocol_event_t events= client->work(client, &len, &endptr); + if (events == MEMCACHED_PROTOCOL_ERROR_EVENT) { - return ERROR_EVENT; + return MEMCACHED_PROTOCOL_ERROR_EVENT; } if (len > 0) @@ -325,7 +328,7 @@ enum MEMCACHED_PROTOCOL_EVENT memcached_protocol_client_work(struct memcached_pr if (client->input_buffer == NULL) { client->error= ENOMEM; - return ERROR_EVENT; + return MEMCACHED_PROTOCOL_ERROR_EVENT; } memcpy(client->input_buffer, endptr, (size_t)len); client->input_buffer_offset= (size_t)len; @@ -336,7 +339,7 @@ enum MEMCACHED_PROTOCOL_EVENT memcached_protocol_client_work(struct memcached_pr { /* Connection closed */ drain_output(client); - return ERROR_EVENT; + return MEMCACHED_PROTOCOL_ERROR_EVENT; } else { @@ -344,16 +347,20 @@ enum MEMCACHED_PROTOCOL_EVENT memcached_protocol_client_work(struct memcached_pr { client->error= errno; /* mark this client as terminated! */ - return ERROR_EVENT; + return MEMCACHED_PROTOCOL_ERROR_EVENT; } - more_data = false; + more_data= false; } } while (more_data); if (!drain_output(client)) { - return ERROR_EVENT; + return MEMCACHED_PROTOCOL_ERROR_EVENT; } - return (client->output) ? READ_WRITE_EVENT : READ_EVENT; + memcached_protocol_event_t ret= MEMCACHED_PROTOCOL_READ_EVENT; + if (client->output) + ret|= MEMCACHED_PROTOCOL_READ_EVENT; + + return ret; }