Changeset 760

Show
Ignore:
Timestamp:
03/19/08 05:18:15 (6 months ago)
Author:
dsallings
Message:

Alignment fixes for 64-bit processors.

Files:

Legend:

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

    r705 r760  
    310310       |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| 
    311311       +---------------+---------------+---------------+---------------+ 
    312       0| Flags                                                         | 
    313        +---------------+---------------+---------------+---------------+ 
    314       4| Data version check                                            | 
    315       |                                                               | 
     312      0| Data version check                                            | 
     313       |                                                               | 
     314      +---------------+---------------+---------------+---------------+ 
     315      8| Flags                                                         | 
    316316       +---------------+---------------+---------------+---------------+ 
    317317     Total 12 bytes 
     
    400400       |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| 
    401401       +---------------+---------------+---------------+---------------+ 
    402       0| Flags                                                         | 
    403        +---------------+---------------+---------------+---------------+ 
    404       4| Expiration                                                    | 
    405       +---------------+---------------+---------------+---------------+ 
    406       8| Data version check                                            | 
    407        |                                                               | 
     402      0| Data version check                                            | 
     403       |                                                               | 
     404      +---------------+---------------+---------------+---------------+ 
     405      8| Flags                                                         | 
     406      +---------------+---------------+---------------+---------------+ 
     407     12| Expiration                                                    | 
    408408       +---------------+---------------+---------------+---------------+ 
    409409     Total 16 bytes 
  • branches/binary/server/memcached.c

    r759 r760  
    10851085        assert(c->rsize >= MIN_BIN_PKT_LENGTH + 4); 
    10861086 
    1087         /* This is a bit of magic.  I'm using wbuf as the header, so I'll place 
    1088         this is int in far enough to cover the header */ 
    1089         flags = (int*)(c->wbuf + MIN_BIN_PKT_LENGTH); 
    1090         *flags = htonl(strtoul(ITEM_suffix(it), NULL, 10)); 
    1091  
    10921087        /* the length has two unnecessary bytes, and then we write four more */ 
    10931088        add_bin_header(c, 0, GET_RES_HDR_LEN, it->nbytes - 2 + GET_RES_HDR_LEN); 
    1094         /* Flags */ 
     1089 
     1090        /* Add the "extras" field: CAS-id followed by flags. The cas is a 64- 
     1091           bit datatype and require alignment to 8-byte boundaries on some 
     1092           architechtures. Verify that the size of the packet header is of 
     1093           the correct size (if not the following code generates SIGBUS on 
     1094           sparc hardware). 
     1095        */ 
     1096        assert(MIN_BIN_PKT_LENGTH % 8 == 0); 
     1097        identifier = (uint64_t*)(c->wbuf + MIN_BIN_PKT_LENGTH); 
     1098        *identifier = swap64(it->cas_id); 
     1099        add_iov(c, identifier, 8); 
     1100 
     1101        /* Add the flags */ 
     1102        flags = (int*)(c->wbuf + MIN_BIN_PKT_LENGTH + 8); 
     1103        *flags = htonl(strtoul(ITEM_suffix(it), NULL, 10)); 
    10951104        add_iov(c, flags, 4); 
    1096         identifier = (uint64_t*)(c->wbuf + MIN_BIN_PKT_LENGTH + 4); 
    1097         *identifier = swap64((uint32_t)it->cas_id); 
    1098         add_iov(c, identifier, 8); 
    1099         /* bytes minus the CRLF */ 
     1105 
     1106        /* Add the data minus the CRLF */ 
    11001107        add_iov(c, ITEM_data(it), it->nbytes - 2); 
    11011108        conn_set_state(c, conn_mwrite); 
     
    11731180    key[nkey] = 0x00; 
    11741181 
    1175     flags = ntohl(*((int*)(c->rbuf))); 
    1176     exptime = ntohl(*((int*)(c->rbuf + 4))); 
     1182    flags = ntohl(*((int*)(c->rbuf + 8))); 
     1183    exptime = ntohl(*((int*)(c->rbuf + 12))); 
    11771184    vlen = c->bin_header[2] - (nkey + hdrlen); 
    11781185 
     
    11981205    } 
    11991206 
    1200     it->cas_id = (uint64_t)swap64(*((int64_t*)(c->rbuf + 8))); 
     1207    it->cas_id = (uint64_t)swap64(*((int64_t*)(c->rbuf))); 
    12011208 
    12021209    switch(c->cmd) { 
     
    12891296            return; 
    12901297        } 
    1291      
     1298 
    12921299        c->msgcurr = 0; 
    12931300        c->msgused = 0; 
     
    12971304            return; 
    12981305        } 
    1299      
     1306 
    13001307        c->cmd = (c->bin_header[0] >> 16) & 0xff; 
    13011308        c->keylen = c->bin_header[0] & 0xffff;