Changeset 692

Show
Ignore:
Timestamp:
02/11/08 00:24:55 (10 months ago)
Author:
dormando
Message:

Binary protocol updates for binary incr/decr response. (Dustin Sallings)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/binary/server/doc/binary-protocol-plan-v2.xml

    r687 r692  
    435435      +---------------+---------------+---------------+---------------+ 
    436436    Total 20 bytes 
     437      </artwork></figure> 
     438        </t> 
     439 
     440        <t> 
     441      <figure> 
     442        <preamble>incr/decr response body:</preamble> 
     443          <artwork> 
     444    Byte/     0       |       1       |       2       |       3       | 
     445       /              |               |               |               | 
     446      |0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7| 
     447      +---------------+---------------+---------------+---------------+ 
     448     0| 64-bit unsigned response.                                     | 
     449      |                                                               | 
     450      +---------------+---------------+---------------+---------------+ 
     451    Total 8 bytes 
    437452      </artwork></figure> 
    438453        </t> 
  • branches/binary/server/memcached.c

    r686 r692  
    942942    char *key; 
    943943    size_t nkey; 
    944     int i,res
    945     char *responseBuf = c->wbuf + BIN_INCR_HDR_LEN; 
     944    int i
     945    uint64_t *responseBuf = (uint64_t*) c->wbuf + BIN_INCR_HDR_LEN; 
    946946 
    947947    assert(c != NULL); 
     
    981981    if (it) { 
    982982        /* Weird magic in add_delta forces me to pad here */ 
    983         memset(responseBuf, ' ', 32); 
    984         responseBuf[32]=0x00; 
    985         add_delta(it, c->cmd == CMD_INCR, delta, responseBuf); 
    986         res = strlen(responseBuf); 
    987          
    988         assert(res > 0); 
    989         write_bin_response(c, responseBuf, BIN_INCR_HDR_LEN, res); 
     983        char tmpbuf[INCR_MAX_STORAGE_LEN]; 
     984        uint64_t l=0; 
     985        memset(tmpbuf, ' ', INCR_MAX_STORAGE_LEN); 
     986        tmpbuf[INCR_MAX_STORAGE_LEN]=0x00; 
     987        add_delta(it, c->cmd == CMD_INCR, delta, tmpbuf); 
     988        *responseBuf=swap64(strtoull(tmpbuf, NULL, 10)); 
     989 
     990        write_bin_response(c, responseBuf, BIN_INCR_HDR_LEN, INCR_RES_LEN); 
    990991        item_remove(it);         /* release our reference */ 
    991992    } else { 
    992993        if(exptime >= 0) { 
    993994            /* Save some room for the response */ 
    994             assert(c->wsize > BIN_INCR_HDR_LEN + 32); 
    995             snprintf(responseBuf, BIN_INCR_HDR_LEN + 32, "%llu", initial); 
    996              
    997             res = strlen(responseBuf); 
    998             it = item_alloc(key, nkey, 0, realtime(exptime), res + 2); 
    999              
    1000             memcpy(ITEM_data(it), responseBuf, res); 
    1001              
     995            assert(c->wsize > BIN_INCR_HDR_LEN + BIN_DEL_HDR_LEN); 
     996            *responseBuf=swap64(initial); 
     997            it = item_alloc(key, nkey, 0, realtime(exptime), 
     998                INCR_MAX_STORAGE_LEN); 
     999            snprintf(ITEM_data(it), INCR_MAX_STORAGE_LEN, "%llu", initial); 
     1000 
    10021001            if(store_item(it, NREAD_SET)) { 
    1003                 write_bin_response(c, responseBuf, BIN_INCR_HDR_LEN, res); 
     1002                write_bin_response(c, responseBuf, BIN_INCR_HDR_LEN, 
     1003                    INCR_RES_LEN); 
    10041004            } else { 
    10051005                write_bin_error(c, ERR_NOT_STORED, 0); 
  • branches/binary/server/memcached.h

    r686 r692  
    5050#define BIN_DEL_HDR_LEN 4 
    5151#define BIN_PKT_HDR_WORDS (MIN_BIN_PKT_LENGTH/sizeof(uint32_t)) 
     52 
     53/* Body is a single 64-bit int */ 
     54#define INCR_RES_LEN 8 
     55/* len(18446744073709551616) + 2 (or so) */ 
     56#define INCR_MAX_STORAGE_LEN 24 
    5257 
    5358#define BIN_REQ_MAGIC 0x80