Changeset 759
- Timestamp:
- 03/18/08 17:21:31 (5 months ago)
- Files:
-
- branches/binary/server/memcached.c (modified) (26 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/binary/server/memcached.c
r758 r759 166 166 167 167 static void settings_init(void) { 168 settings.access =0700;168 settings.access = 0700; 169 169 settings.port = 11211; 170 170 settings.udpport = 0; … … 296 296 297 297 static char *prot_text(enum protocol prot) { 298 char *rv ="unknown";298 char *rv = "unknown"; 299 299 switch(prot) { 300 300 case ascii_prot: 301 rv ="ascii";301 rv = "ascii"; 302 302 break; 303 303 case binary_prot: 304 rv ="binary";304 rv = "binary"; 305 305 break; 306 306 case ascii_udp_prot: 307 rv ="ascii-udp";307 rv = "ascii-udp"; 308 308 break; 309 309 case negotiating_prot: 310 rv ="auto-negotiate";310 rv = "auto-negotiate"; 311 311 break; 312 312 } … … 351 351 if (c->rbuf != 0) free(c->rbuf); 352 352 if (c->wbuf != 0) free(c->wbuf); 353 if (c->ilist != 0) free(c->ilist);353 if (c->ilist != 0) free(c->ilist); 354 354 if (c->suffixlist != 0) free(c->suffixlist); 355 355 if (c->iov != 0) free(c->iov); … … 515 515 516 516 static enum conn_states get_init_state(conn *c) { 517 int rv =0;517 int rv = 0; 518 518 assert(c != NULL); 519 519 520 520 switch(c->protocol) { 521 521 case binary_prot: 522 rv =conn_bin_init;522 rv = conn_bin_init; 523 523 break; 524 524 case negotiating_prot: 525 rv =conn_negotiate;525 rv = conn_negotiate; 526 526 break; 527 527 default: 528 rv =conn_read;528 rv = conn_read; 529 529 } 530 530 return rv; … … 865 865 866 866 static void add_bin_header(conn *c, int err, int hdr_len, int body_len) { 867 int i =0;867 int i = 0; 868 868 uint32_t *res_header; 869 869 … … 896 896 } 897 897 898 for(i =0; i<BIN_PKT_HDR_WORDS; i++) {898 for(i = 0; i<BIN_PKT_HDR_WORDS; i++) { 899 899 res_header[i] = htonl(res_header[i]); 900 900 } … … 905 905 906 906 static void write_bin_error(conn *c, int err, int swallow) { 907 char *errstr ="Unknown error";907 char *errstr = "Unknown error"; 908 908 switch(err) { 909 909 case ERR_UNKNOWN_CMD: 910 errstr ="Unknown command";910 errstr = "Unknown command"; 911 911 break; 912 912 case ERR_NOT_FOUND: 913 errstr ="Not found";913 errstr = "Not found"; 914 914 break; 915 915 case ERR_INVALID_ARGUMENTS: 916 errstr ="Invalid arguments";916 errstr = "Invalid arguments"; 917 917 break; 918 918 case ERR_EXISTS: 919 errstr ="Data exists for key.";919 errstr = "Data exists for key."; 920 920 break; 921 921 case ERR_TOO_LARGE: 922 errstr ="Too large.";922 errstr = "Too large."; 923 923 break; 924 924 case ERR_NOT_STORED: 925 errstr ="Not stored.";925 errstr = "Not stored."; 926 926 break; 927 927 default: 928 errstr ="UNHANDLED ERROR";928 errstr = "UNHANDLED ERROR"; 929 929 fprintf(stderr, "UNHANDLED ERROR: %d\n", err); 930 930 } … … 937 937 conn_set_state(c, conn_mwrite); 938 938 if(swallow > 0) { 939 c->sbytes =swallow;939 c->sbytes = swallow; 940 940 c->write_and_go = conn_swallow; 941 941 } else { … … 959 959 /* Little endian, flip the bytes around until someone makes a faster/better 960 960 * way to do this. */ 961 int64_t rv =0;962 int i =0;963 for(i =0; i<8; i++) {961 int64_t rv = 0; 962 int i = 0; 963 for(i = 0; i<8; i++) { 964 964 rv = (rv << 8) | (in & 0xff); 965 965 in >>= 8; … … 984 984 assert(c != NULL); 985 985 986 key =c->rbuf + BIN_INCR_HDR_LEN;987 nkey =c->keylen;988 key[nkey] =0x00;986 key = c->rbuf + BIN_INCR_HDR_LEN; 987 nkey = c->keylen; 988 key[nkey] = 0x00; 989 989 990 990 delta = swap64(*((int64_t*)(c->rbuf))); … … 994 994 if(settings.verbose) { 995 995 fprintf(stderr, "incr "); 996 for(i =0; i<nkey; i++) {996 for(i = 0; i<nkey; i++) { 997 997 fprintf(stderr, "%c", key[i]); 998 998 } … … 1004 1004 /* Weird magic in add_delta forces me to pad here */ 1005 1005 char tmpbuf[INCR_MAX_STORAGE_LEN]; 1006 uint64_t l =0;1006 uint64_t l = 0; 1007 1007 memset(tmpbuf, ' ', INCR_MAX_STORAGE_LEN); 1008 tmpbuf[INCR_MAX_STORAGE_LEN] =0x00;1008 tmpbuf[INCR_MAX_STORAGE_LEN] = 0x00; 1009 1009 add_delta(it, c->cmd == CMD_INCR, delta, tmpbuf); 1010 *response_buf =swap64(strtoull(tmpbuf, NULL, 10));1010 *response_buf = swap64(strtoull(tmpbuf, NULL, 10)); 1011 1011 1012 1012 write_bin_response(c, response_buf, BIN_INCR_HDR_LEN, INCR_RES_LEN); … … 1016 1016 /* Save some room for the response */ 1017 1017 assert(c->wsize > BIN_INCR_HDR_LEN + BIN_DEL_HDR_LEN); 1018 *response_buf =swap64(initial);1018 *response_buf = swap64(initial); 1019 1019 it = item_alloc(key, nkey, 0, realtime(exptime), 1020 1020 INCR_MAX_STORAGE_LEN); … … 1035 1035 1036 1036 static void complete_update_bin(conn *c) { 1037 int eno =-1, ret=0;1037 int eno = -1, ret = 0; 1038 1038 assert(c != NULL); 1039 1039 … … 1062 1062 default: 1063 1063 if(c->item_comm == NREAD_ADD) { 1064 eno =ERR_EXISTS;1064 eno = ERR_EXISTS; 1065 1065 } else if(c->item_comm == NREAD_REPLACE) { 1066 eno =ERR_NOT_FOUND;1066 eno = ERR_NOT_FOUND; 1067 1067 } else { 1068 eno =ERR_NOT_STORED;1068 eno = ERR_NOT_STORED; 1069 1069 } 1070 1070 write_bin_error(c, eno, 0); … … 1087 1087 /* This is a bit of magic. I'm using wbuf as the header, so I'll place 1088 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));1089 flags = (int*)(c->wbuf + MIN_BIN_PKT_LENGTH); 1090 *flags = htonl(strtoul(ITEM_suffix(it), NULL, 10)); 1091 1091 1092 1092 /* the length has two unnecessary bytes, and then we write four more */ … … 1094 1094 /* Flags */ 1095 1095 add_iov(c, flags, 4); 1096 identifier =(uint64_t*)(c->wbuf + MIN_BIN_PKT_LENGTH + 4);1097 *identifier =swap64((uint32_t)it->cas_id);1096 identifier = (uint64_t*)(c->wbuf + MIN_BIN_PKT_LENGTH + 4); 1097 *identifier = swap64((uint32_t)it->cas_id); 1098 1098 add_iov(c, identifier, 8); 1099 1099 /* bytes minus the CRLF */ … … 1165 1165 item *it; 1166 1166 int comm; 1167 int hdrlen =BIN_SET_HDR_LEN;1167 int hdrlen = BIN_SET_HDR_LEN; 1168 1168 1169 1169 assert(c != NULL); 1170 1170 1171 key =c->rbuf + hdrlen;1172 nkey =c->keylen;1173 key[nkey] =0x00;1171 key = c->rbuf + hdrlen; 1172 nkey = c->keylen; 1173 key[nkey] = 0x00; 1174 1174 1175 1175 flags = ntohl(*((int*)(c->rbuf))); … … 1236 1236 key = c->rbuf + 4; 1237 1237 nkey = c->keylen; 1238 key[nkey] =0x00;1238 key[nkey] = 0x00; 1239 1239 1240 1240 if(settings.verbose) { … … 1254 1254 } else { 1255 1255 /* XXX: This is really lame, but defer_delete returns a string */ 1256 char *res =defer_delete(it, exptime);1256 char *res = defer_delete(it, exptime); 1257 1257 if(res[0] == 'D') { 1258 1258 write_bin_response(c, NULL, 0, 0); … … 1271 1271 if(c->cmd < 0) { 1272 1272 /* No command defined. Figure out what they're trying to say. */ 1273 int i =0;1273 int i = 0; 1274 1274 /* I did a bit of hard-coding around the packet sizes */ 1275 1275 assert(BIN_PKT_HDR_WORDS == 3); 1276 for(i =0; i<BIN_PKT_HDR_WORDS; i++) {1276 for(i = 0; i<BIN_PKT_HDR_WORDS; i++) { 1277 1277 c->bin_header[i] = ntohl(c->bin_header[i]); 1278 1278 } … … 1368 1368 /* We've already got the first letter of the command, so pretend like we 1369 1369 * Did a single byte read from try_read_command */ 1370 c->rcurr =c->rbuf;1371 c->rbytes =1;1370 c->rcurr = c->rbuf; 1371 c->rbytes = 1; 1372 1372 conn_set_state(c, conn_read); 1373 1373 } … … 2113 2113 } 2114 2114 if(value < 0) { 2115 value =0;2115 value = 0; 2116 2116 } 2117 2117 sprintf(buf, "%llu", value); … … 2665 2665 return TRANSMIT_SOFT_ERROR; 2666 2666 } 2667 /* if res ==0 or res==-1 and error is not EAGAIN or EWOULDBLOCK,2667 /* if res == 0 or res == -1 and error is not EAGAIN or EWOULDBLOCK, 2668 2668 we have a real error, on which we close the connection */ 2669 2669 if (settings.verbose > 0) … … 3155 3155 addr.sun_family = AF_UNIX; 3156 3156 strcpy(addr.sun_path, path); 3157 old_umask =umask( ~(access_mask&0777));3157 old_umask = umask( ~(access_mask&0777)); 3158 3158 if (bind(sfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) { 3159 3159 perror("bind()"); … … 3675 3675 3676 3676 /* 3677 * ignore SIGPIPE signals; we can use errno ==EPIPE if we3677 * ignore SIGPIPE signals; we can use errno == EPIPE if we 3678 3678 * need that information 3679 3679 */
