comparison src/c/urweb.c @ 2262:34ad83d9b729

Fix recording bugs to do with nesting and buffer reallocation. Stop MonoFooify printing spurious errors.
author Ziv Scully <ziv@mit.edu>
date Wed, 07 Oct 2015 08:58:08 -0400
parents c275bbc41194
children 1e3ba868f8bf
comparison
equal deleted inserted replaced
2261:f81f1930c5d6 2262:34ad83d9b729
70 free(b->start); 70 free(b->start);
71 } 71 }
72 72
73 void uw_buffer_reset(uw_buffer *b) { 73 void uw_buffer_reset(uw_buffer *b) {
74 b->front = b->start; 74 b->front = b->start;
75 if (b->front != b->back) {
76 *b->front = 0;
77 }
75 } 78 }
76 79
77 int uw_buffer_check(uw_buffer *b, size_t extra) { 80 int uw_buffer_check(uw_buffer *b, size_t extra) {
78 if (b->back - b->front < extra) { 81 if (b->back - b->front < extra) {
79 size_t desired = b->front - b->start + extra, next; 82 size_t desired = b->front - b->start + extra, next;
484 487
485 char *output_buffer; 488 char *output_buffer;
486 size_t output_buffer_size; 489 size_t output_buffer_size;
487 490
488 // For caching. 491 // For caching.
489 char *recording; 492 int numRecording;
493 int recordingOffset;
490 494
491 int remoteSock; 495 int remoteSock;
492 }; 496 };
493 497
494 size_t uw_headers_max = SIZE_MAX; 498 size_t uw_headers_max = SIZE_MAX;
570 ctx->needsResig = 0; 574 ctx->needsResig = 0;
571 575
572 ctx->output_buffer = malloc(1); 576 ctx->output_buffer = malloc(1);
573 ctx->output_buffer_size = 1; 577 ctx->output_buffer_size = 1;
574 578
575 ctx->recording = 0; 579 ctx->numRecording = 0;
580 ctx->recordingOffset = 0;
576 581
577 ctx->remoteSock = -1; 582 ctx->remoteSock = -1;
578 583
579 return ctx; 584 return ctx;
580 } 585 }
1687 uw_write_unsafe(ctx, s); 1692 uw_write_unsafe(ctx, s);
1688 *ctx->page.front = 0; 1693 *ctx->page.front = 0;
1689 } 1694 }
1690 1695
1691 void uw_recordingStart(uw_context ctx) { 1696 void uw_recordingStart(uw_context ctx) {
1692 ctx->recording = ctx->page.front; 1697 if (ctx->numRecording++ == 0) {
1698 ctx->recordingOffset = ctx->page.front - ctx->page.start;
1699 }
1693 } 1700 }
1694 1701
1695 char *uw_recordingRead(uw_context ctx) { 1702 char *uw_recordingRead(uw_context ctx) {
1696 return strdup(ctx->recording); 1703 // Only the outermost recorder can read unless the recording is empty.
1704 char *recording = ctx->page.start + ctx->recordingOffset;
1705 if (--ctx->numRecording > 0 && recording != ctx->page.front) {
1706 return NULL;
1707 }
1708 return strdup(recording);
1697 } 1709 }
1698 1710
1699 char *uw_Basis_attrifyInt(uw_context ctx, uw_Basis_int n) { 1711 char *uw_Basis_attrifyInt(uw_context ctx, uw_Basis_int n) {
1700 char *result; 1712 char *result;
1701 int len; 1713 int len;
4541 4553
4542 time_t uw_Sqlcache_timeMax(time_t x, time_t y) { 4554 time_t uw_Sqlcache_timeMax(time_t x, time_t y) {
4543 return difftime(x, y) > 0 ? x : y; 4555 return difftime(x, y) > 0 ? x : y;
4544 } 4556 }
4545 4557
4546 void uw_Sqlcache_freeuw_Sqlcache_CacheValue(uw_Sqlcache_CacheValue *value) { 4558 void uw_Sqlcache_free(uw_Sqlcache_CacheValue *value) {
4547 if (value) { 4559 if (value) {
4548 free(value->result); 4560 free(value->result);
4549 free(value->output); 4561 free(value->output);
4550 free(value); 4562 free(value);
4551 } 4563 }
4552 } 4564 }
4553 4565
4554 void uw_Sqlcache_delete(uw_Sqlcache_Cache *cache, uw_Sqlcache_CacheEntry* entry) { 4566 void uw_Sqlcache_delete(uw_Sqlcache_Cache *cache, uw_Sqlcache_CacheEntry* entry) {
4555 //uw_Sqlcache_listUw_Sqlcache_Delete(cache->lru, entry); 4567 //uw_Sqlcache_listUw_Sqlcache_Delete(cache->lru, entry);
4556 HASH_DELETE(hh, cache->table, entry); 4568 HASH_DELETE(hh, cache->table, entry);
4557 uw_Sqlcache_freeuw_Sqlcache_CacheValue(entry->value); 4569 uw_Sqlcache_free(entry->value);
4558 free(entry->key); 4570 free(entry->key);
4559 free(entry); 4571 free(entry);
4560 } 4572 }
4561 4573
4562 uw_Sqlcache_CacheValue *uw_Sqlcache_checkHelper(uw_Sqlcache_Cache *cache, char **keys, int timeInvalid) { 4574 uw_Sqlcache_CacheValue *uw_Sqlcache_checkHelper(uw_Sqlcache_Cache *cache, char **keys, int timeInvalid) {
4593 HASH_ADD_KEYPTR(hh, cache->table, entry->key, strlen(entry->key), entry); 4605 HASH_ADD_KEYPTR(hh, cache->table, entry->key, strlen(entry->key), entry);
4594 } 4606 }
4595 entry->timeValid = timeNow; 4607 entry->timeValid = timeNow;
4596 if (cache->height == 0) { 4608 if (cache->height == 0) {
4597 //uw_Sqlcache_listAdd(cache->lru, entry); 4609 //uw_Sqlcache_listAdd(cache->lru, entry);
4598 uw_Sqlcache_freeuw_Sqlcache_CacheValue(entry->value); 4610 uw_Sqlcache_free(entry->value);
4599 entry->value = value; 4611 entry->value = value;
4600 //if (cache->lru->size > MAX_SIZE) { 4612 //if (cache->lru->size > MAX_SIZE) {
4601 //uw_Sqlcache_delete(cache, cache->lru->first); 4613 //uw_Sqlcache_delete(cache, cache->lru->first);
4602 // TODO: return flushed value. 4614 // TODO: return flushed value.
4603 //} 4615 //}