Mercurial > urweb
comparison src/c/urweb.c @ 2281:75cb60a7f6f1
Simplify C interface.
author | Ziv Scully <ziv@mit.edu> |
---|---|
date | Thu, 12 Nov 2015 09:15:50 -0500 |
parents | 985c8016b592 |
children | 19b233bb3176 |
comparison
equal
deleted
inserted
replaced
2280:985c8016b592 | 2281:75cb60a7f6f1 |
---|---|
486 int usedSig, needsResig; | 486 int usedSig, needsResig; |
487 | 487 |
488 char *output_buffer; | 488 char *output_buffer; |
489 size_t output_buffer_size; | 489 size_t output_buffer_size; |
490 | 490 |
491 // For caching. | 491 // Sqlcache. |
492 int numRecording; | 492 int numRecording; |
493 int recordingOffset; | 493 int recordingOffset; |
494 | 494 |
495 int remoteSock; | 495 int remoteSock; |
496 }; | 496 }; |
4614 } | 4614 } |
4615 | 4615 |
4616 // The NUL-terminated prefix of [key] below always looks something like "_k1_k2_k3..._kn". | 4616 // The NUL-terminated prefix of [key] below always looks something like "_k1_k2_k3..._kn". |
4617 // TODO: strlen(key) = buf - key? | 4617 // TODO: strlen(key) = buf - key? |
4618 | 4618 |
4619 uw_Sqlcache_Value *uw_Sqlcache_check(uw_Sqlcache_Cache *cache, char **keys, int numKeys) { | 4619 uw_Sqlcache_Value *uw_Sqlcache_check(uw_Sqlcache_Cache *cache, char **keys) { |
4620 size_t numKeys = cache->numKeys; | |
4620 char *key = uw_Sqlcache_allocKeyBuffer(keys, numKeys); | 4621 char *key = uw_Sqlcache_allocKeyBuffer(keys, numKeys); |
4621 char *buf = key; | 4622 char *buf = key; |
4622 time_t timeInvalid = cache->timeInvalid; | 4623 time_t timeInvalid = cache->timeInvalid; |
4623 uw_Sqlcache_Entry *entry; | 4624 uw_Sqlcache_Entry *entry; |
4624 while (numKeys-- > 0) { | 4625 while (numKeys-- > 0) { |
4634 free(key); | 4635 free(key); |
4635 uw_Sqlcache_Value *value = entry->value; | 4636 uw_Sqlcache_Value *value = entry->value; |
4636 return value && value->timeValid > timeInvalid ? value : NULL; | 4637 return value && value->timeValid > timeInvalid ? value : NULL; |
4637 } | 4638 } |
4638 | 4639 |
4639 void uw_Sqlcache_store(uw_Sqlcache_Cache *cache, char **keys, int numKeys, uw_Sqlcache_Value *value) { | 4640 void uw_Sqlcache_store(uw_Sqlcache_Cache *cache, char **keys, uw_Sqlcache_Value *value) { |
4641 size_t numKeys = cache->numKeys; | |
4640 char *key = uw_Sqlcache_allocKeyBuffer(keys, numKeys); | 4642 char *key = uw_Sqlcache_allocKeyBuffer(keys, numKeys); |
4641 char *buf = key; | 4643 char *buf = key; |
4642 time_t timeNow = uw_Sqlcache_getTimeNow(cache); | 4644 time_t timeNow = uw_Sqlcache_getTimeNow(cache); |
4643 uw_Sqlcache_Entry *entry; | 4645 uw_Sqlcache_Entry *entry; |
4644 while (numKeys-- > 0) { | 4646 while (numKeys-- > 0) { |
4657 uw_Sqlcache_freeValue(entry->value); | 4659 uw_Sqlcache_freeValue(entry->value); |
4658 entry->value = value; | 4660 entry->value = value; |
4659 entry->value->timeValid = timeNow; | 4661 entry->value->timeValid = timeNow; |
4660 } | 4662 } |
4661 | 4663 |
4662 void uw_Sqlcache_flush(uw_Sqlcache_Cache *cache, char **keys, int numKeys) { | 4664 void uw_Sqlcache_flush(uw_Sqlcache_Cache *cache, char **keys) { |
4665 size_t numKeys = cache->numKeys; | |
4663 char *key = uw_Sqlcache_allocKeyBuffer(keys, numKeys); | 4666 char *key = uw_Sqlcache_allocKeyBuffer(keys, numKeys); |
4664 char *buf = key; | 4667 char *buf = key; |
4665 time_t timeNow = uw_Sqlcache_getTimeNow(cache); | 4668 time_t timeNow = uw_Sqlcache_getTimeNow(cache); |
4666 uw_Sqlcache_Entry *entry; | 4669 uw_Sqlcache_Entry *entry; |
4667 while (numKeys-- > 0) { | 4670 while (numKeys-- > 0) { |