Changeset 615 for trunk/server/memcached.c
- Timestamp:
- 10/03/07 19:59:11 (2 years ago)
- Files:
-
- 1 modified
-
trunk/server/memcached.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/memcached.c
r608 r615 1026 1026 1027 1027 /* ntokens is overwritten here... shrug.. */ 1028 static inline void process_get_command(conn *c, token_t *tokens, size_t ntokens ) {1028 static inline void process_get_command(conn *c, token_t *tokens, size_t ntokens, bool return_key_ptr) { 1029 1029 char *key; 1030 1030 size_t nkey; … … 1032 1032 item *it; 1033 1033 token_t *key_token = &tokens[KEY_TOKEN]; 1034 1034 char suffix[255]; 1035 uint32_t in_memory_ptr; 1035 1036 assert(c != NULL); 1036 1037 … … 1082 1083 * " " + flags + " " + data length + "\r\n" + data (with \r\n) 1083 1084 */ 1084 if (add_iov(c, "VALUE ", 6) != 0 || 1085 add_iov(c, ITEM_key(it), it->nkey) != 0 || 1086 add_iov(c, ITEM_suffix(it), it->nsuffix + it->nbytes) != 0) 1087 { 1088 break; 1089 } 1085 1086 if(return_key_ptr == true) 1087 { 1088 in_memory_ptr = (uint32_t)item_get(key, nkey); 1089 sprintf(suffix," %d %d %lu\r\n", atoi(ITEM_suffix(it) + 1), it->nbytes - 2, in_memory_ptr); 1090 if (add_iov(c, "VALUE ", 6) != 0 || 1091 add_iov(c, ITEM_key(it), it->nkey) != 0 || 1092 add_iov(c, suffix, strlen(suffix)) != 0 || 1093 add_iov(c, ITEM_data(it), it->nbytes) != 0) 1094 { 1095 break; 1096 } 1097 } 1098 else 1099 { 1100 if (add_iov(c, "VALUE ", 6) != 0 || 1101 add_iov(c, ITEM_key(it), it->nkey) != 0 || 1102 add_iov(c, ITEM_suffix(it), it->nsuffix + it->nbytes) != 0) 1103 { 1104 break; 1105 } 1106 } 1107 1108 1090 1109 if (settings.verbose > 1) 1091 1110 fprintf(stderr, ">%d sending key %s\n", c->sfd, ITEM_key(it)); … … 1136 1155 } 1137 1156 1138 static void process_update_command(conn *c, token_t *tokens, const size_t ntokens, int comm ) {1157 static void process_update_command(conn *c, token_t *tokens, const size_t ntokens, int comm, bool handle_cas) { 1139 1158 char *key; 1140 1159 size_t nkey; … … 1142 1161 time_t exptime; 1143 1162 int vlen; 1163 uint32_t req_memory_ptr, in_memory_ptr; 1164 1144 1165 item *it; 1145 1166 … … 1157 1178 exptime = strtol(tokens[3].value, NULL, 10); 1158 1179 vlen = strtol(tokens[4].value, NULL, 10); 1180 1181 // does cas value exist? 1182 if(tokens[5].value) 1183 { 1184 req_memory_ptr = strtoull(tokens[5].value, NULL, 10); 1185 } 1159 1186 1160 1187 if(errno == ERANGE || ((flags == 0 || exptime == 0) && errno == EINVAL)) { … … 1181 1208 1182 1209 it = item_alloc(key, nkey, flags, realtime(exptime), vlen+2); 1210 1211 /* HANDLE_CAS VALIDATION */ 1212 if(handle_cas == true) 1213 { 1214 item *itmp=item_get(key, it->nkey); 1215 /* Release the reference */ 1216 if(itmp) { 1217 item_remove(itmp); 1218 } 1219 in_memory_ptr = (uint32_t)itmp; 1220 if(in_memory_ptr == req_memory_ptr) 1221 { 1222 // validates allow the set 1223 } 1224 else if(in_memory_ptr) 1225 { 1226 out_string(c, "EXISTS"); 1227 1228 /* swallow the data line */ 1229 c->write_and_go = conn_swallow; 1230 c->sbytes = vlen + 2; 1231 return; 1232 } 1233 else 1234 { 1235 out_string(c, "NOT FOUND"); 1236 /* swallow the data line */ 1237 c->write_and_go = conn_swallow; 1238 c->sbytes = vlen + 2; 1239 return; 1240 } 1241 } 1183 1242 1184 1243 if (it == 0) { … … 1420 1479 1421 1480 ntokens = tokenize_command(command, tokens, MAX_TOKENS); 1422 1423 1481 if (ntokens >= 3 && 1424 1482 ((strcmp(tokens[COMMAND_TOKEN].value, "get") == 0) || 1425 1483 (strcmp(tokens[COMMAND_TOKEN].value, "bget") == 0))) { 1426 1484 1427 process_get_command(c, tokens, ntokens );1485 process_get_command(c, tokens, ntokens, false); 1428 1486 1429 1487 } else if (ntokens == 6 && … … 1432 1490 (strcmp(tokens[COMMAND_TOKEN].value, "replace") == 0 && (comm = NREAD_REPLACE)))) { 1433 1491 1434 process_update_command(c, tokens, ntokens, comm); 1492 process_update_command(c, tokens, ntokens, comm, false); 1493 1494 } else if (ntokens == 6 && (strcmp(tokens[COMMAND_TOKEN].value, "cas") == 0)) { 1495 1496 process_update_command(c, tokens, ntokens, comm, true); 1435 1497 1436 1498 } else if (ntokens == 4 && (strcmp(tokens[COMMAND_TOKEN].value, "incr") == 0)) { 1437 1499 1438 1500 process_arithmetic_command(c, tokens, ntokens, 1); 1501 1502 } else if (ntokens >= 3 && (strcmp(tokens[COMMAND_TOKEN].value, "gets") == 0)) { 1503 1504 process_get_command(c, tokens, ntokens, true); 1439 1505 1440 1506 } else if (ntokens == 4 && (strcmp(tokens[COMMAND_TOKEN].value, "decr") == 0)) {
