]> git.ipfire.org Git - thirdparty/squid.git/blob - src/store_client.cc
SourceFormat: enforcement
[thirdparty/squid.git] / src / store_client.cc
1
2 /*
3 * $Id$
4 *
5 * DEBUG: section 90 Storage Manager Client-Side Interface
6 * AUTHOR: Duane Wessels
7 *
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 *
34 * Portions copyright (c) 2003 Robert Collins <robertc@squid-cache.org>
35 */
36
37 #include "squid.h"
38 #include "event.h"
39 #include "StoreClient.h"
40 #include "Store.h"
41 #include "HttpReply.h"
42 #include "MemObject.h"
43 #include "StoreMeta.h"
44 #include "StoreMetaUnpacker.h"
45 #if DELAY_POOLS
46 #include "DelayPools.h"
47 #endif
48 #include "HttpRequest.h"
49 #include "MemBuf.h"
50
51 /*
52 * NOTE: 'Header' refers to the swapfile metadata header.
53 * 'OBJHeader' refers to the object header, with cannonical
54 * processed object headers (which may derive from FTP/HTTP etc
55 * upstream protocols
56 * 'Body' refers to the swapfile body, which is the full
57 * HTTP reply (including HTTP headers and body).
58 */
59 static StoreIOState::STRCB storeClientReadBody;
60 static StoreIOState::STRCB storeClientReadHeader;
61 static void storeClientCopy2(StoreEntry * e, store_client * sc);
62 static EVH storeClientCopyEvent;
63 static int CheckQuickAbort2(StoreEntry * entry);
64 static void CheckQuickAbort(StoreEntry * entry);
65
66 CBDATA_CLASS_INIT(store_client);
67
68 void *
69 store_client::operator new (size_t)
70 {
71 CBDATA_INIT_TYPE(store_client);
72 store_client *result = cbdataAlloc(store_client);
73 return result;
74 }
75
76 void
77 store_client::operator delete (void *address)
78 {
79 store_client *t = static_cast<store_client *>(address);
80 cbdataFree(t);
81 }
82
83 bool
84 store_client::memReaderHasLowerOffset(int64_t anOffset) const
85 {
86 return getType() == STORE_MEM_CLIENT && copyInto.offset < anOffset;
87 }
88
89 int
90 store_client::getType() const
91 {
92 return type;
93 }
94
95 #if STORE_CLIENT_LIST_DEBUG
96 static store_client *
97 storeClientListSearch(const MemObject * mem, void *data)
98 {
99 dlink_node *node;
100 store_client *sc = NULL;
101
102 for (node = mem->clients.head; node; node = node->next) {
103 sc = node->data;
104
105 if (sc->owner == data)
106 return sc;
107 }
108
109 return NULL;
110 }
111
112 int
113 storeClientIsThisAClient(store_client * sc, void *someClient)
114 {
115 return sc->owner == someClient;
116 }
117
118 #endif
119 #include "HttpRequest.h"
120
121 /* add client with fd to client list */
122 store_client *
123 storeClientListAdd(StoreEntry * e, void *data)
124 {
125 MemObject *mem = e->mem_obj;
126 store_client *sc;
127 assert(mem);
128 #if STORE_CLIENT_LIST_DEBUG
129
130 if (storeClientListSearch(mem, data) != NULL)
131 /* XXX die! */
132 assert(1 == 0);
133
134 #endif
135
136 sc = new store_client (e);
137
138 mem->addClient(sc);
139
140 return sc;
141 }
142
143 void
144 store_client::callback(ssize_t sz, bool error)
145 {
146 StoreIOBuffer result(sz, 0 ,copyInto.data);
147
148 if (sz < 0) {
149 result.flags.error = 1;
150 result.length = 0;
151 } else {
152 result.flags.error = error ? 1 : 0;
153 }
154
155 result.offset = cmp_offset;
156 assert(_callback.pending());
157 cmp_offset = copyInto.offset + sz;
158 STCB *temphandler = _callback.callback_handler;
159 void *cbdata = _callback.callback_data;
160 _callback = Callback(NULL, NULL);
161 copyInto.data = NULL;
162
163 if (cbdataReferenceValid(cbdata))
164 temphandler(cbdata, result);
165
166 cbdataReferenceDone(cbdata);
167 }
168
169 static void
170 storeClientCopyEvent(void *data)
171 {
172 store_client *sc = (store_client *)data;
173 debugs(90, 3, "storeClientCopyEvent: Running");
174 assert (sc->flags.copy_event_pending);
175 sc->flags.copy_event_pending = 0;
176
177 if (!sc->_callback.pending())
178 return;
179
180 storeClientCopy2(sc->entry, sc);
181 }
182
183 store_client::store_client(StoreEntry *e) : entry (e)
184 #if DELAY_POOLS
185 , delayId()
186 #endif
187 , type (e->storeClientType())
188 , object_ok(true)
189 {
190 cmp_offset = 0;
191 flags.disk_io_pending = 0;
192 entry->refcount++;
193
194 if (getType() == STORE_DISK_CLIENT)
195 /* assert we'll be able to get the data we want */
196 /* maybe we should open swapin_sio here */
197 assert(entry->swap_filen > -1 || entry->swapOutAble());
198
199 #if STORE_CLIENT_LIST_DEBUG
200
201 owner = cbdataReference(data);
202
203 #endif
204 }
205
206 store_client::~store_client()
207 {}
208
209 /* copy bytes requested by the client */
210 void
211 storeClientCopy(store_client * sc,
212 StoreEntry * e,
213 StoreIOBuffer copyInto,
214 STCB * callback,
215 void *data)
216 {
217 assert (sc != NULL);
218 sc->copy(e, copyInto,callback,data);
219 }
220
221 void
222 store_client::copy(StoreEntry * anEntry,
223 StoreIOBuffer copyRequest,
224 STCB * callback_fn,
225 void *data)
226 {
227 assert (anEntry == entry);
228 assert (callback_fn);
229 assert (data);
230 assert(!EBIT_TEST(entry->flags, ENTRY_ABORTED));
231 debugs(90, 3, "store_client::copy: " << entry->getMD5Text() << ", from " <<
232 copyRequest.offset << ", for length " <<
233 (int) copyRequest.length << ", cb " << callback_fn << ", cbdata " <<
234 data);
235
236 #if STORE_CLIENT_LIST_DEBUG
237
238 assert(this == storeClientListSearch(entry->mem_obj, data));
239 #endif
240
241 assert(!_callback.pending());
242 #if ONLYCONTIGUOUSREQUESTS
243
244 assert(cmp_offset == copyRequest.offset);
245 #endif
246 /* range requests will skip into the body */
247 cmp_offset = copyRequest.offset;
248 _callback = Callback (callback_fn, cbdataReference(data));
249 copyInto.data = copyRequest.data;
250 copyInto.length = copyRequest.length;
251 copyInto.offset = copyRequest.offset;
252
253 static bool copying (false);
254 assert (!copying);
255 copying = true;
256 PROF_start(storeClient_kickReads);
257 /* we might be blocking comm reads due to readahead limits
258 * now we have a new offset, trigger those reads...
259 */
260 entry->mem_obj->kickReads();
261 PROF_stop(storeClient_kickReads);
262 copying = false;
263
264 storeClientCopy2(entry, this);
265 }
266
267 /*
268 * This function is used below to decide if we have any more data to
269 * send to the client. If the store_status is STORE_PENDING, then we
270 * do have more data to send. If its STORE_OK, then
271 * we continue checking. If the object length is negative, then we
272 * don't know the real length and must open the swap file to find out.
273 * If the length is >= 0, then we compare it to the requested copy
274 * offset.
275 */
276 static int
277 storeClientNoMoreToSend(StoreEntry * e, store_client * sc)
278 {
279 int64_t len;
280
281 if (e->store_status == STORE_PENDING)
282 return 0;
283
284 if ((len = e->objectLen()) < 0)
285 return 0;
286
287 if (sc->copyInto.offset < len)
288 return 0;
289
290 return 1;
291 }
292
293 static void
294 storeClientCopy2(StoreEntry * e, store_client * sc)
295 {
296 /* reentrancy not allowed - note this could lead to
297 * dropped events
298 */
299
300 if (sc->flags.copy_event_pending) {
301 return;
302 }
303
304 if (EBIT_TEST(e->flags, ENTRY_FWD_HDR_WAIT)) {
305 debugs(90, 5, "storeClientCopy2: returning because ENTRY_FWD_HDR_WAIT set");
306 return;
307 }
308
309 if (sc->flags.store_copying) {
310 sc->flags.copy_event_pending = 1;
311 debugs(90, 3, "storeClientCopy2: Queueing storeClientCopyEvent()");
312 eventAdd("storeClientCopyEvent", storeClientCopyEvent, sc, 0.0, 0);
313 return;
314 }
315
316 debugs(90, 3, "storeClientCopy2: " << e->getMD5Text());
317 assert(sc->_callback.pending());
318 /*
319 * We used to check for ENTRY_ABORTED here. But there were some
320 * problems. For example, we might have a slow client (or two) and
321 * the server-side is reading far ahead and swapping to disk. Even
322 * if the server-side aborts, we want to give the client(s)
323 * everything we got before the abort condition occurred.
324 */
325 /* Warning: doCopy may indirectly free itself in callbacks,
326 * hence the lock to keep it active for the duration of
327 * this function
328 */
329 cbdataInternalLock(sc);
330 assert (sc->flags.store_copying == 0);
331 sc->doCopy(e);
332 assert (sc->flags.store_copying == 0);
333 cbdataInternalUnlock(sc);
334 }
335
336 void
337 store_client::doCopy(StoreEntry *anEntry)
338 {
339 assert (anEntry == entry);
340 flags.store_copying = 1;
341 MemObject *mem = entry->mem_obj;
342
343 debugs(33, 5, "store_client::doCopy: co: " <<
344 copyInto.offset << ", hi: " <<
345 mem->endOffset());
346
347 if (storeClientNoMoreToSend(entry, this)) {
348 /* There is no more to send! */
349 debugs(33, 3, HERE << "There is no more to send!");
350 callback(0);
351 flags.store_copying = 0;
352 return;
353 }
354
355 /* Check that we actually have data */
356 if (anEntry->store_status == STORE_PENDING && copyInto.offset >= mem->endOffset()) {
357 debugs(90, 3, "store_client::doCopy: Waiting for more");
358 flags.store_copying = 0;
359 return;
360 }
361
362 /*
363 * Slight weirdness here. We open a swapin file for any
364 * STORE_DISK_CLIENT, even if we can copy the requested chunk
365 * from memory in the next block. We must try to open the
366 * swapin file before sending any data to the client side. If
367 * we postpone the open, and then can not open the file later
368 * on, the client loses big time. Its transfer just gets cut
369 * off. Better to open it early (while the client side handler
370 * is clientCacheHit) so that we can fall back to a cache miss
371 * if needed.
372 */
373
374 if (STORE_DISK_CLIENT == getType() && swapin_sio == NULL)
375 startSwapin();
376 else
377 scheduleRead();
378 }
379
380 void
381 store_client::startSwapin()
382 {
383 debugs(90, 3, "store_client::doCopy: Need to open swap in file");
384 /* gotta open the swapin file */
385
386 if (storeTooManyDiskFilesOpen()) {
387 /* yuck -- this causes a TCP_SWAPFAIL_MISS on the client side */
388 fail();
389 flags.store_copying = 0;
390 return;
391 } else if (!flags.disk_io_pending) {
392 /* Don't set store_io_pending here */
393 storeSwapInStart(this);
394
395 if (swapin_sio == NULL) {
396 fail();
397 flags.store_copying = 0;
398 return;
399 }
400
401 /*
402 * If the open succeeds we either copy from memory, or
403 * schedule a disk read in the next block.
404 */
405 scheduleRead();
406
407 return;
408 } else {
409 debugs(90, 1, "WARNING: Averted multiple fd operation (1)");
410 flags.store_copying = 0;
411 return;
412 }
413 }
414
415 void
416 store_client::scheduleRead()
417 {
418 MemObject *mem = entry->mem_obj;
419
420 if (copyInto.offset >= mem->inmem_lo && copyInto.offset < mem->endOffset())
421 scheduleMemRead();
422 else
423 scheduleDiskRead();
424 }
425
426 void
427 store_client::scheduleDiskRead()
428 {
429 /* What the client wants is not in memory. Schedule a disk read */
430 assert(STORE_DISK_CLIENT == getType());
431
432 assert(!flags.disk_io_pending);
433
434 debugs(90, 3, "store_client::doCopy: reading from STORE");
435
436 fileRead();
437
438 flags.store_copying = 0;
439 }
440
441 void
442 store_client::scheduleMemRead()
443 {
444 /* What the client wants is in memory */
445 /* Old style */
446 debugs(90, 3, "store_client::doCopy: Copying normal from memory");
447 size_t sz = entry->mem_obj->data_hdr.copy(copyInto);
448 callback(sz);
449 flags.store_copying = 0;
450 }
451
452 void
453 store_client::fileRead()
454 {
455 MemObject *mem = entry->mem_obj;
456
457 assert(_callback.pending());
458 assert(!flags.disk_io_pending);
459 flags.disk_io_pending = 1;
460
461 if (mem->swap_hdr_sz != 0)
462 if (entry->swap_status == SWAPOUT_WRITING)
463 assert(mem->swapout.sio->offset() > copyInto.offset + (int64_t)mem->swap_hdr_sz);
464
465 storeRead(swapin_sio,
466 copyInto.data,
467 copyInto.length,
468 copyInto.offset + mem->swap_hdr_sz,
469 mem->swap_hdr_sz == 0 ? storeClientReadHeader
470 : storeClientReadBody,
471 this);
472 }
473
474 static void
475 storeClientMemWriteComplete(void *data, StoreIOBuffer wroteBuffer)
476 {
477 // Nothin to do here but callback is needed
478 }
479
480 void
481 store_client::readBody(const char *buf, ssize_t len)
482 {
483 int parsed_header = 0;
484
485 // Don't assert disk_io_pending here.. may be called by read_header
486 flags.disk_io_pending = 0;
487 assert(_callback.pending());
488 debugs(90, 3, "storeClientReadBody: len " << len << "");
489
490 if (copyInto.offset == 0 && len > 0 && entry->getReply()->sline.status == 0) {
491 /* Our structure ! */
492 HttpReply *rep = (HttpReply *) entry->getReply(); // bypass const
493
494 if (!rep->parseCharBuf(copyInto.data, headersEnd(copyInto.data, len))) {
495 debugs(90, 0, "Could not parse headers from on disk object");
496 } else {
497 parsed_header = 1;
498 }
499 }
500
501 const HttpReply *rep = entry->getReply();
502 if (len > 0 && rep && entry->mem_obj->inmem_lo == 0 && entry->objectLen() <= (int64_t)Config.Store.maxInMemObjSize && Config.onoff.memory_cache_disk) {
503 storeGetMemSpace(len);
504 // The above may start to free our object so we need to check again
505 if (entry->mem_obj->inmem_lo == 0) {
506 /* Copy read data back into memory.
507 * but first we need to adjust offset.. some parts of the code
508 * counts offset including headers, some parts count offset as
509 * withing the body.. copyInto is including headers, but the mem
510 * cache expects offset without headers (using negative for headers)
511 * eventually not storing packed headers in memory at all.
512 */
513 int64_t mem_offset = entry->mem_obj->endOffset();
514 if ((copyInto.offset == mem_offset) || (parsed_header && mem_offset == rep->hdr_sz)) {
515 entry->mem_obj->write(StoreIOBuffer(len, copyInto.offset - rep->hdr_sz, copyInto.data), storeClientMemWriteComplete, this);
516 }
517 }
518 }
519
520 callback(len);
521 }
522
523 void
524 store_client::fail()
525 {
526 object_ok = false;
527 /* synchronous open failures callback from the store,
528 * before startSwapin detects the failure.
529 * TODO: fix this inconsistent behaviour - probably by
530 * having storeSwapInStart become a callback functions,
531 * not synchronous
532 */
533
534 if (_callback.pending())
535 callback(0, true);
536 }
537
538 static void
539 storeClientReadHeader(void *data, const char *buf, ssize_t len, StoreIOState::Pointer self)
540 {
541 store_client *sc = (store_client *)data;
542 sc->readHeader(buf, len);
543 }
544
545 static void
546 storeClientReadBody(void *data, const char *buf, ssize_t len, StoreIOState::Pointer self)
547 {
548 store_client *sc = (store_client *)data;
549 sc->readBody(buf, len);
550 }
551
552 void
553 store_client::unpackHeader(char const *buf, ssize_t len)
554 {
555 debugs(90, 3, "store_client::unpackHeader: len " << len << "");
556
557 if (len < 0) {
558 debugs(90, 3, "store_client::unpackHeader: " << xstrerror() << "");
559 fail();
560 return;
561 }
562
563 int swap_hdr_sz = 0;
564 StoreMetaUnpacker aBuilder(buf, len, &swap_hdr_sz);
565
566 if (!aBuilder.isBufferSane()) {
567 /* oops, bad disk file? */
568 debugs(90, 1, "WARNING: swapfile header inconsistent with available data");
569 fail();
570 return;
571 }
572
573 tlv *tlv_list = aBuilder.createStoreMeta ();
574
575 if (tlv_list == NULL) {
576 debugs(90, 1, "WARNING: failed to unpack meta data");
577 fail();
578 return;
579 }
580
581 /*
582 * Check the meta data and make sure we got the right object.
583 */
584 for (tlv *t = tlv_list; t; t = t->next) {
585 if (!t->checkConsistency(entry)) {
586 storeSwapTLVFree(tlv_list);
587 fail();
588 return;
589 }
590 }
591
592 storeSwapTLVFree(tlv_list);
593
594 entry->mem_obj->swap_hdr_sz = swap_hdr_sz;
595 entry->mem_obj->object_sz = entry->swap_file_sz - swap_hdr_sz;
596
597 }
598
599 void
600 store_client::readHeader(char const *buf, ssize_t len)
601 {
602 MemObject *const mem = entry->mem_obj;
603
604 assert(flags.disk_io_pending);
605 flags.disk_io_pending = 0;
606 assert(_callback.pending());
607
608 unpackHeader (buf, len);
609
610 if (!object_ok)
611 return;
612
613 /*
614 * If our last read got some data the client wants, then give
615 * it to them, otherwise schedule another read.
616 */
617 size_t body_sz = len - mem->swap_hdr_sz;
618
619 if (copyInto.offset < static_cast<int64_t>(body_sz)) {
620 /*
621 * we have (part of) what they want
622 */
623 size_t copy_sz = min(copyInto.length, body_sz);
624 debugs(90, 3, "storeClientReadHeader: copying " << copy_sz << " bytes of body");
625 xmemmove(copyInto.data, copyInto.data + mem->swap_hdr_sz, copy_sz);
626
627 readBody(copyInto.data, copy_sz);
628
629 return;
630 }
631
632 /*
633 * we don't have what the client wants, but at least we now
634 * know the swap header size.
635 */
636 fileRead();
637 }
638
639 int
640 storeClientCopyPending(store_client * sc, StoreEntry * e, void *data)
641 {
642 #if STORE_CLIENT_LIST_DEBUG
643 assert(sc == storeClientListSearch(e->mem_obj, data));
644 #endif
645 #ifndef SILLY_CODE
646
647 assert(sc);
648 #endif
649
650 assert(sc->entry == e);
651 #if SILLY_CODE
652
653 if (sc == NULL)
654 return 0;
655
656 #endif
657
658 if (!sc->_callback.pending())
659 return 0;
660
661 return 1;
662 }
663
664 /*
665 * This routine hasn't been optimised to take advantage of the
666 * passed sc. Yet.
667 */
668 int
669 storeUnregister(store_client * sc, StoreEntry * e, void *data)
670 {
671 MemObject *mem = e->mem_obj;
672 #if STORE_CLIENT_LIST_DEBUG
673
674 assert(sc == storeClientListSearch(e->mem_obj, data));
675 #endif
676
677 if (mem == NULL)
678 return 0;
679
680 debugs(90, 3, "storeUnregister: called for '" << e->getMD5Text() << "'");
681
682 if (sc == NULL) {
683 debugs(90, 3, "storeUnregister: No matching client for '" << e->getMD5Text() << "'");
684 return 0;
685 }
686
687 if (mem->clientCount() == 0) {
688 debugs(90, 3, "storeUnregister: Consistency failure - store client being unregistered is not in the mem object's list for '" << e->getMD5Text() << "'");
689 return 0;
690 }
691
692 dlinkDelete(&sc->node, &mem->clients);
693 mem->nclients--;
694
695 if (e->store_status == STORE_OK && e->swap_status != SWAPOUT_DONE)
696 e->swapOut();
697
698 if (sc->swapin_sio != NULL) {
699 storeClose(sc->swapin_sio);
700 sc->swapin_sio = NULL;
701 statCounter.swap.ins++;
702 }
703
704 if (sc->_callback.pending()) {
705 /* callback with ssize = -1 to indicate unexpected termination */
706 debugs(90, 3, "storeUnregister: store_client for " << mem->url << " has a callback");
707 sc->fail();
708 }
709
710 #if STORE_CLIENT_LIST_DEBUG
711 cbdataReferenceDone(sc->owner);
712
713 #endif
714
715 delete sc;
716
717 assert(e->lock_count > 0);
718
719 if (mem->nclients == 0)
720 CheckQuickAbort(e);
721 else
722 mem->kickReads();
723
724 return 1;
725 }
726
727 /* Call handlers waiting for data to be appended to E. */
728 void
729 StoreEntry::invokeHandlers()
730 {
731 /* Commit what we can to disk, if appropriate */
732 swapOut();
733 int i = 0;
734 store_client *sc;
735 dlink_node *nx = NULL;
736 dlink_node *node;
737
738 PROF_start(InvokeHandlers);
739
740 debugs(90, 3, "InvokeHandlers: " << getMD5Text() );
741 /* walk the entire list looking for valid callbacks */
742
743 for (node = mem_obj->clients.head; node; node = nx) {
744 sc = (store_client *)node->data;
745 nx = node->next;
746 debugs(90, 3, "StoreEntry::InvokeHandlers: checking client #" << i++ );
747
748 if (!sc->_callback.pending())
749 continue;
750
751 if (sc->flags.disk_io_pending)
752 continue;
753
754 storeClientCopy2(this, sc);
755 }
756 PROF_stop(InvokeHandlers);
757 }
758
759 int
760 storePendingNClients(const StoreEntry * e)
761 {
762 MemObject *mem = e->mem_obj;
763 int npend = NULL == mem ? 0 : mem->nclients;
764 debugs(90, 3, "storePendingNClients: returning " << npend);
765 return npend;
766 }
767
768 /* return 1 if the request should be aborted */
769 static int
770 CheckQuickAbort2(StoreEntry * entry)
771 {
772 MemObject * const mem = entry->mem_obj;
773 assert(mem);
774 debugs(90, 3, "CheckQuickAbort2: entry=" << entry << ", mem=" << mem);
775
776 if (mem->request && !mem->request->flags.cachable) {
777 debugs(90, 3, "CheckQuickAbort2: YES !mem->request->flags.cachable");
778 return 1;
779 }
780
781 if (EBIT_TEST(entry->flags, KEY_PRIVATE)) {
782 debugs(90, 3, "CheckQuickAbort2: YES KEY_PRIVATE");
783 return 1;
784 }
785
786 int64_t expectlen = entry->getReply()->content_length + entry->getReply()->hdr_sz;
787
788 if (expectlen < 0)
789 /* expectlen is < 0 if *no* information about the object has been received */
790 return 1;
791
792 int64_t curlen = mem->endOffset ();
793
794 if (Config.quickAbort.min < 0) {
795 debugs(90, 3, "CheckQuickAbort2: NO disabled");
796 return 0;
797 }
798
799 if ( Config.rangeOffsetLimit < 0 && mem->request && mem->request->range ) {
800 /* Don't abort if the admin has configured range_ofset -1 to download fully for caching. */
801 debugs(90, 3, "CheckQuickAbort2: NO admin configured range replies to full-download");
802 return 0;
803 }
804
805 if (curlen > expectlen) {
806 debugs(90, 3, "CheckQuickAbort2: YES bad content length");
807 return 1;
808 }
809
810 if ((expectlen - curlen) < (Config.quickAbort.min << 10)) {
811 debugs(90, 3, "CheckQuickAbort2: NO only little more left");
812 return 0;
813 }
814
815 if ((expectlen - curlen) > (Config.quickAbort.max << 10)) {
816 debugs(90, 3, "CheckQuickAbort2: YES too much left to go");
817 return 1;
818 }
819
820 if (expectlen < 100) {
821 debugs(90, 3, "CheckQuickAbort2: NO avoid FPE");
822 return 0;
823 }
824
825 if ((curlen / (expectlen / 100)) > (Config.quickAbort.pct)) {
826 debugs(90, 3, "CheckQuickAbort2: NO past point of no return");
827 return 0;
828 }
829
830 debugs(90, 3, "CheckQuickAbort2: YES default, returning 1");
831 return 1;
832 }
833
834 static void
835 CheckQuickAbort(StoreEntry * entry)
836 {
837 assert (entry);
838
839 if (storePendingNClients(entry) > 0)
840 return;
841
842 if (entry->store_status != STORE_PENDING)
843 return;
844
845 if (EBIT_TEST(entry->flags, ENTRY_SPECIAL))
846 return;
847
848 if (CheckQuickAbort2(entry) == 0)
849 return;
850
851 entry->abort();
852 }
853
854 void
855 store_client::dumpStats(MemBuf * output, int clientNumber) const
856 {
857 if (_callback.pending())
858 return;
859
860 output->Printf("\tClient #%d, %p\n", clientNumber, _callback.callback_data);
861
862 output->Printf("\t\tcopy_offset: %"PRId64"\n",
863 copyInto.offset);
864
865 output->Printf("\t\tcopy_size: %d\n",
866 (int) copyInto.length);
867
868 output->Printf("\t\tflags:");
869
870 if (flags.disk_io_pending)
871 output->Printf(" disk_io_pending");
872
873 if (flags.store_copying)
874 output->Printf(" store_copying");
875
876 if (flags.copy_event_pending)
877 output->Printf(" copy_event_pending");
878
879 output->Printf("\n");
880 }
881
882 bool
883 store_client::Callback::pending() const
884 {
885 return callback_handler && callback_data;
886 }
887
888 store_client::Callback::Callback(STCB *function, void *data) : callback_handler(function), callback_data (data) {}
889
890 #if DELAY_POOLS
891 void
892 store_client::setDelayId(DelayId delay_id)
893 {
894 delayId = delay_id;
895 }
896
897 #endif