@@ -93,7 +93,6 @@ static void write_and_free(conn *c, char *buf, int bytes);
93
93
static int ensure_iov_space (conn * c );
94
94
static int add_iov (conn * c , const void * buf , int len );
95
95
static int add_msghdr (conn * c );
96
- static uint64_t mc_swap64 (uint64_t in );
97
96
98
97
/* time handling */
99
98
static void set_current_time (void ); /* update the global variable holding
@@ -891,7 +890,7 @@ static void add_bin_header(conn *c, uint16_t err, uint8_t hdr_len, uint16_t key_
891
890
892
891
header -> response .bodylen = htonl (body_len );
893
892
header -> response .opaque = c -> opaque ;
894
- header -> response .cas = mc_swap64 (c -> cas );
893
+ header -> response .cas = htonll (c -> cas );
895
894
896
895
if (settings .verbose > 1 ) {
897
896
int ii ;
@@ -976,24 +975,6 @@ static void write_bin_response(conn *c, void *d, int hlen, int keylen, int dlen)
976
975
}
977
976
}
978
977
979
- /* Byte swap a 64-bit number */
980
- static uint64_t mc_swap64 (uint64_t in ) {
981
- #ifdef ENDIAN_LITTLE
982
- /* Little endian, flip the bytes around until someone makes a faster/better
983
- * way to do this. */
984
- int64_t rv = 0 ;
985
- int i = 0 ;
986
- for (i = 0 ; i < 8 ; i ++ ) {
987
- rv = (rv << 8 ) | (in & 0xff );
988
- in >>= 8 ;
989
- }
990
- return rv ;
991
- #else
992
- /* big-endian machines don't need byte swapping */
993
- return in ;
994
- #endif
995
- }
996
-
997
978
static void complete_incr_bin (conn * c ) {
998
979
item * it ;
999
980
char * key ;
@@ -1006,8 +987,8 @@ static void complete_incr_bin(conn *c) {
1006
987
assert (c -> wsize >= sizeof (* rsp ));
1007
988
1008
989
/* fix byteorder in the request */
1009
- req -> message .body .delta = mc_swap64 (req -> message .body .delta );
1010
- req -> message .body .initial = mc_swap64 (req -> message .body .initial );
990
+ req -> message .body .delta = ntohll (req -> message .body .delta );
991
+ req -> message .body .initial = ntohll (req -> message .body .initial );
1011
992
req -> message .body .expiration = ntohl (req -> message .body .expiration );
1012
993
key = binary_get_key (c );
1013
994
nkey = c -> binary_header .request .keylen ;
@@ -1047,7 +1028,7 @@ static void complete_incr_bin(conn *c) {
1047
1028
if (st != PROTOCOL_BINARY_RESPONSE_SUCCESS ) {
1048
1029
write_bin_error (c , st , 0 );
1049
1030
} else {
1050
- rsp -> message .body .value = mc_swap64 (strtoull (tmpbuf , NULL , 10 ));
1031
+ rsp -> message .body .value = htonll (strtoull (tmpbuf , NULL , 10 ));
1051
1032
c -> cas = ITEM_get_cas (it );
1052
1033
write_bin_response (c , & rsp -> message .body , 0 , 0 ,
1053
1034
sizeof (rsp -> message .body .value ));
@@ -1056,7 +1037,7 @@ static void complete_incr_bin(conn *c) {
1056
1037
item_remove (it ); /* release our reference */
1057
1038
} else if (!it && req -> message .body .expiration != 0xffffffff ) {
1058
1039
/* Save some room for the response */
1059
- rsp -> message .body .value = mc_swap64 (req -> message .body .initial );
1040
+ rsp -> message .body .value = htonll (req -> message .body .initial );
1060
1041
it = item_alloc (key , nkey , 0 , realtime (req -> message .body .expiration ),
1061
1042
INCR_MAX_STORAGE_LEN );
1062
1043
@@ -1197,7 +1178,7 @@ static void process_bin_get(conn *c) {
1197
1178
keylen = nkey ;
1198
1179
}
1199
1180
add_bin_header (c , 0 , sizeof (rsp -> message .body ), keylen , bodylen );
1200
- rsp -> message .header .response .cas = mc_swap64 (ITEM_get_cas (it ));
1181
+ rsp -> message .header .response .cas = htonll (ITEM_get_cas (it ));
1201
1182
1202
1183
// add the flags
1203
1184
rsp -> message .body .flags = htonl (strtoul (ITEM_suffix (it ), NULL , 10 ));
@@ -1795,7 +1776,7 @@ static void process_bin_delete(conn *c) {
1795
1776
1796
1777
it = item_get (key , nkey );
1797
1778
if (it ) {
1798
- uint64_t cas = mc_swap64 (req -> message .header .request .cas );
1779
+ uint64_t cas = ntohll (req -> message .header .request .cas );
1799
1780
if (cas == 0 || cas == ITEM_get_cas (it )) {
1800
1781
MEMCACHED_COMMAND_DELETE (c -> sfd , ITEM_key (it ), it -> nkey );
1801
1782
item_unlink (it );
@@ -2922,7 +2903,7 @@ static int try_read_command(conn *c) {
2922
2903
c -> binary_header = * req ;
2923
2904
c -> binary_header .request .keylen = ntohs (req -> request .keylen );
2924
2905
c -> binary_header .request .bodylen = ntohl (req -> request .bodylen );
2925
- c -> binary_header .request .cas = mc_swap64 (req -> request .cas );
2906
+ c -> binary_header .request .cas = ntohll (req -> request .cas );
2926
2907
2927
2908
if (c -> binary_header .request .magic != PROTOCOL_BINARY_REQ ) {
2928
2909
if (settings .verbose ) {
0 commit comments