本文整理汇总了C++中CHECK_OBJ_NOTNULL函数的典型用法代码示例。如果您正苦于以下问题:C++ CHECK_OBJ_NOTNULL函数的具体用法?C++ CHECK_OBJ_NOTNULL怎么用?C++ CHECK_OBJ_NOTNULL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CHECK_OBJ_NOTNULL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: vmod_filtersep
const char *
vmod_filtersep(struct sess *sp)
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
return NULL;
}
示例2: VRY_Create
int
VRY_Create(struct busyobj *bo, struct vsb **psb)
{
const char *v, *p, *q, *h, *e;
struct vsb *sb, *sbh;
unsigned l;
int error = 0;
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
CHECK_OBJ_NOTNULL(bo->bereq, HTTP_MAGIC);
CHECK_OBJ_NOTNULL(bo->beresp, HTTP_MAGIC);
AN(psb);
AZ(*psb);
/* No Vary: header, no worries */
if (!http_GetHdr(bo->beresp, H_Vary, &v))
return (0);
/* For vary matching string */
sb = VSB_new_auto();
AN(sb);
/* For header matching strings */
sbh = VSB_new_auto();
AN(sbh);
for (p = v; *p; p++) {
/* Find next header-name */
if (vct_issp(*p))
continue;
for (q = p; *q && !vct_issp(*q) && *q != ','; q++)
continue;
if (q - p > INT8_MAX) {
VSLb(bo->vsl, SLT_Error,
"Vary header name length exceeded");
error = 1;
break;
}
/* Build a header-matching string out of it */
VSB_clear(sbh);
VSB_printf(sbh, "%c%.*s:%c",
(char)(1 + (q - p)), (int)(q - p), p, 0);
AZ(VSB_finish(sbh));
if (http_GetHdr(bo->bereq, VSB_data(sbh), &h)) {
AZ(vct_issp(*h));
/* Trim trailing space */
e = strchr(h, '\0');
while (e > h && vct_issp(e[-1]))
e--;
/* Encode two byte length and contents */
l = e - h;
if (l > 0xffff - 1) {
VSLb(bo->vsl, SLT_Error,
"Vary header maximum length exceeded");
error = 1;
break;
}
} else {
e = h;
l = 0xffff;
}
VSB_printf(sb, "%c%c", (int)(l >> 8), (int)(l & 0xff));
/* Append to vary matching string */
VSB_bcat(sb, VSB_data(sbh), VSB_len(sbh));
if (e != h)
VSB_bcat(sb, h, e - h);
while (vct_issp(*q))
q++;
if (*q == '\0')
break;
if (*q != ',') {
VSLb(bo->vsl, SLT_Error, "Malformed Vary header");
error = 1;
break;
}
p = q;
}
if (error) {
VSB_delete(sbh);
VSB_delete(sb);
return (-1);
}
/* Terminate vary matching string */
VSB_printf(sb, "%c%c%c", 0xff, 0xff, 0);
VSB_delete(sbh);
AZ(VSB_finish(sb));
*psb = sb;
return (VSB_len(sb));
}
示例3: cnt_lookup
static int
cnt_lookup(struct sess *sp)
{
struct objcore *oc;
struct object *o;
struct objhead *oh;
struct worker *wrk;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
wrk = sp->wrk;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC);
AZ(wrk->busyobj);
if (sp->hash_objhead == NULL) {
/* Not a waiting list return */
AZ(sp->vary_b);
AZ(sp->vary_l);
AZ(sp->vary_e);
(void)WS_Reserve(sp->ws, 0);
} else {
AN(sp->ws->r);
}
sp->vary_b = (void*)sp->ws->f;
sp->vary_e = (void*)sp->ws->r;
sp->vary_b[2] = '\0';
oc = HSH_Lookup(sp, &oh);
if (oc == NULL) {
/*
* We lost the session to a busy object, disembark the
* worker thread. The hash code to restart the session,
* still in STP_LOOKUP, later when the busy object isn't.
* NB: Do not access sp any more !
*/
return (1);
}
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
/* If we inserted a new object it's a miss */
if (oc->flags & OC_F_BUSY) {
wrk->stats.cache_miss++;
if (sp->vary_l != NULL) {
assert(oc->busyobj->vary == sp->vary_b);
VRY_Validate(oc->busyobj->vary);
WS_ReleaseP(sp->ws, (void*)sp->vary_l);
} else {
AZ(oc->busyobj->vary);
WS_Release(sp->ws, 0);
}
sp->vary_b = NULL;
sp->vary_l = NULL;
sp->vary_e = NULL;
wrk->objcore = oc;
CHECK_OBJ_NOTNULL(wrk->busyobj, BUSYOBJ_MAGIC);
sp->step = STP_MISS;
return (0);
}
o = oc_getobj(wrk, oc);
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
wrk->obj = o;
WS_Release(sp->ws, 0);
sp->vary_b = NULL;
sp->vary_l = NULL;
sp->vary_e = NULL;
if (oc->flags & OC_F_PASS) {
wrk->stats.cache_hitpass++;
WSP(sp, SLT_HitPass, "%u", wrk->obj->xid);
(void)HSH_Deref(wrk, NULL, &wrk->obj);
wrk->objcore = NULL;
sp->step = STP_PASS;
return (0);
}
wrk->stats.cache_hit++;
WSP(sp, SLT_Hit, "%u", wrk->obj->xid);
sp->step = STP_HIT;
return (0);
}
示例4: vbe_dir_gethdrs
vbe_dir_gethdrs(const struct director *d, struct worker *wrk,
struct busyobj *bo)
{
int i, extrachance = 1;
struct backend *bp;
struct vbc *vbc;
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
CAST_OBJ_NOTNULL(bp, d->priv, BACKEND_MAGIC);
/*
* Now that we know our backend, we can set a default Host:
* header if one is necessary. This cannot be done in the VCL
* because the backend may be chosen by a director.
*/
if (!http_GetHdr(bo->bereq, H_Host, NULL) && bp->hosthdr != NULL)
http_PrintfHeader(bo->bereq, "Host: %s", bp->hosthdr);
do {
vbc = vbe_dir_getfd(wrk, bp, bo);
if (vbc == NULL) {
VSLb(bo->vsl, SLT_FetchError, "no backend connection");
return (-1);
}
AN(bo->htc);
if (vbc->state != VBC_STATE_STOLEN)
extrachance = 0;
i = V1F_SendReq(wrk, bo, &bo->acct.bereq_hdrbytes, 0);
if (vbc->state != VBC_STATE_USED)
VBT_Wait(wrk, vbc);
assert(vbc->state == VBC_STATE_USED);
if (i == 0)
i = V1F_FetchRespHdr(bo);
if (i == 0) {
AN(bo->htc->priv);
return (0);
}
/*
* If we recycled a backend connection, there is a finite chance
* that the backend closed it before we got the bereq to it.
* In that case do a single automatic retry if req.body allows.
*/
vbe_dir_finish(d, wrk, bo);
AZ(bo->htc);
if (i < 0)
break;
if (bo->req != NULL &&
bo->req->req_body_status != REQ_BODY_NONE &&
bo->req->req_body_status != REQ_BODY_CACHED)
break;
VSC_C_main->backend_retry++;
} while (extrachance);
return (-1);
}
示例5: http1_dissect
static int
http1_dissect(struct worker *wrk, struct req *req)
{
const char *r_100 = "HTTP/1.1 100 Continue\r\n\r\n";
const char *r_400 = "HTTP/1.1 400 Bad Request\r\n\r\n";
const char *r_417 = "HTTP/1.1 417 Expectation Failed\r\n\r\n";
const char *p;
ssize_t r;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
/* Allocate a new vxid now that we know we'll need it. */
AZ(req->vsl->wid);
req->vsl->wid = VXID_Get(wrk, VSL_CLIENTMARKER);
VSLb(req->vsl, SLT_Begin, "req %u rxreq", VXID(req->sp->vxid));
VSL(SLT_Link, req->sp->vxid, "req %u rxreq", VXID(req->vsl->wid));
AZ(isnan(req->t_first)); /* First byte timestamp set by http1_wait */
AZ(isnan(req->t_req)); /* Complete req rcvd set by http1_wait */
req->t_prev = req->t_first;
VSLb_ts_req(req, "Start", req->t_first);
VSLb_ts_req(req, "Req", req->t_req);
/* Borrow VCL reference from worker thread */
VCL_Refresh(&wrk->vcl);
req->vcl = wrk->vcl;
wrk->vcl = NULL;
HTTP_Setup(req->http, req->ws, req->vsl, SLT_ReqMethod);
req->err_code = HTTP1_DissectRequest(req->htc, req->http);
/* If we could not even parse the request, just close */
if (req->err_code != 0) {
VSLb(req->vsl, SLT_HttpGarbage, "%.*s",
(int)(req->htc->rxbuf_e - req->htc->rxbuf_b),
req->htc->rxbuf_b);
wrk->stats->client_req_400++;
r = write(req->sp->fd, r_400, strlen(r_400));
if (r > 0)
req->acct.resp_hdrbytes += r;
req->doclose = SC_RX_JUNK;
return (-1);
}
assert (req->req_body_status == REQ_BODY_INIT);
if (req->htc->body_status == BS_CHUNKED) {
req->req_body_status = REQ_BODY_WITHOUT_LEN;
} else if (req->htc->body_status == BS_LENGTH) {
req->req_body_status = REQ_BODY_WITH_LEN;
} else if (req->htc->body_status == BS_NONE) {
req->req_body_status = REQ_BODY_NONE;
} else if (req->htc->body_status == BS_EOF) {
req->req_body_status = REQ_BODY_WITHOUT_LEN;
} else {
WRONG("Unknown req.body_length situation");
}
if (http_GetHdr(req->http, H_Expect, &p)) {
if (strcasecmp(p, "100-continue")) {
wrk->stats->client_req_417++;
req->err_code = 417;
r = write(req->sp->fd, r_417, strlen(r_417));
if (r > 0)
req->acct.resp_hdrbytes += r;
req->doclose = SC_RX_JUNK;
return (-1);
}
r = write(req->sp->fd, r_100, strlen(r_100));
if (r > 0)
req->acct.resp_hdrbytes += r;
if (r != strlen(r_100)) {
req->doclose = SC_REM_CLOSE;
return (-1);
}
http_Unset(req->http, H_Expect);
}
wrk->stats->client_req++;
wrk->stats->s_req++;
AZ(req->err_code);
req->ws_req = WS_Snapshot(req->ws);
req->doclose = http_DoConnection(req->http);
if (req->doclose == SC_RX_BAD) {
r = write(req->sp->fd, r_400, strlen(r_400));
if (r > 0)
req->acct.resp_hdrbytes += r;
return (-1);
}
assert(req->req_body_status != REQ_BODY_INIT);
HTTP_Copy(req->http0, req->http); // For ESI & restart
return (0);
}
示例6: vdir_rdlock
void
vdir_rdlock(struct vdir *vd)
{
CHECK_OBJ_NOTNULL(vd, VDIR_MAGIC);
AZ(pthread_rwlock_rdlock(&vd->mtx));
}
示例7: VJ_master
void
VJ_master(enum jail_master_e jme)
{
CHECK_OBJ_NOTNULL(vjt, JAIL_TECH_MAGIC);
vjt->master(jme);
}
示例8: vbf_stp_error
static enum fetch_step
vbf_stp_error(struct worker *wrk, struct busyobj *bo)
{
ssize_t l, ll, o;
double now;
uint8_t *ptr;
char time_str[VTIM_FORMAT_SIZE];
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
assert(bo->director_state == DIR_S_NULL);
now = W_TIM_real(wrk);
VSLb_ts_busyobj(bo, "Error", now);
AN(bo->fetch_objcore->flags & OC_F_BUSY);
AZ(bo->synth_body);
bo->synth_body = VSB_new_auto();
AN(bo->synth_body);
// XXX: reset all beresp flags ?
HTTP_Setup(bo->beresp, bo->ws, bo->vsl, SLT_BerespMethod);
http_PutResponse(bo->beresp, "HTTP/1.1", 503, "Backend fetch failed");
VTIM_format(now, time_str);
http_PrintfHeader(bo->beresp, "Date: %s", time_str);
http_SetHeader(bo->beresp, "Server: Varnish");
bo->fetch_objcore->exp.t_origin = bo->t_prev;
bo->fetch_objcore->exp.ttl = 0;
bo->fetch_objcore->exp.grace = 0;
bo->fetch_objcore->exp.keep = 0;
VCL_backend_error_method(bo->vcl, wrk, NULL, bo, bo->bereq->ws);
AZ(VSB_finish(bo->synth_body));
if (wrk->handling == VCL_RET_RETRY) {
VSB_delete(bo->synth_body);
bo->synth_body = NULL;
if (bo->retries++ < cache_param->max_retries)
return (F_STP_RETRY);
return (F_STP_FAIL);
}
assert(wrk->handling == VCL_RET_DELIVER);
VFP_Setup(bo->vfc);
bo->vfc->bo = bo;
bo->vfc->wrk = bo->wrk;
bo->vfc->oc = bo->fetch_objcore;
bo->vfc->http = bo->beresp;
bo->vfc->esi_req = bo->bereq;
if (vbf_beresp2obj(bo))
return (F_STP_FAIL);
ll = VSB_len(bo->synth_body);
o = 0;
while (ll > 0) {
l = ll;
if (VFP_GetStorage(bo->vfc, &l, &ptr) != VFP_OK)
break;
memcpy(ptr, VSB_data(bo->synth_body) + o, l);
VBO_extend(bo, l);
ll -= l;
o += l;
}
VSB_delete(bo->synth_body);
bo->synth_body = NULL;
HSH_Unbusy(wrk, bo->fetch_objcore);
VBO_setstate(bo, BOS_FINISHED);
return (F_STP_DONE);
}
示例9: VBF_Fetch
void
VBF_Fetch(struct worker *wrk, struct req *req, struct objcore *oc,
struct objcore *oldoc, enum vbf_fetch_mode_e mode)
{
struct busyobj *bo;
const char *how;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
CHECK_OBJ_ORNULL(oldoc, OBJCORE_MAGIC);
switch(mode) {
case VBF_PASS: how = "pass"; break;
case VBF_NORMAL: how = "fetch"; break;
case VBF_BACKGROUND: how = "bgfetch"; break;
default: WRONG("Wrong fetch mode");
}
bo = VBO_GetBusyObj(wrk, req);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
VSLb(bo->vsl, SLT_Begin, "bereq %u %s", VXID(req->vsl->wid), how);
VSLb(req->vsl, SLT_Link, "bereq %u %s", VXID(bo->vsl->wid), how);
THR_SetBusyobj(bo);
bo->refcount = 2;
oc->busyobj = bo;
CHECK_OBJ_NOTNULL(bo->vcl, VCL_CONF_MAGIC);
if (mode == VBF_PASS)
bo->do_pass = 1;
bo->vary = req->vary_b;
req->vary_b = NULL;
if (mode != VBF_BACKGROUND)
HSH_Ref(oc);
bo->fetch_objcore = oc;
AZ(bo->ims_oc);
if (oldoc != NULL && ObjCheckFlag(req->wrk, oldoc, OF_IMSCAND)) {
assert(oldoc->refcnt > 0);
HSH_Ref(oldoc);
bo->ims_oc = oldoc;
}
AZ(bo->req);
bo->req = req;
bo->fetch_task.priv = bo;
bo->fetch_task.func = vbf_fetch_thread;
if (Pool_Task(wrk->pool, &bo->fetch_task, POOL_QUEUE_FRONT))
vbf_fetch_thread(wrk, bo);
if (mode == VBF_BACKGROUND) {
VBO_waitstate(bo, BOS_REQ_DONE);
} else {
VBO_waitstate(bo, BOS_STREAM);
if (bo->state == BOS_FAILED) {
AN((oc->flags & OC_F_FAILED));
} else {
AZ(bo->fetch_objcore->flags & OC_F_BUSY);
}
}
VSLb_ts_req(req, "Fetch", W_TIM_real(wrk));
THR_SetBusyobj(NULL);
VBO_DerefBusyObj(wrk, &bo);
}
示例10: vbf_stp_fetch
static enum fetch_step
vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
{
char *p;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
CHECK_OBJ_NOTNULL(bo->fetch_objcore, OBJCORE_MAGIC);
assert(wrk->handling == VCL_RET_DELIVER);
/*
* The VCL variables beresp.do_g[un]zip tells us how we want the
* object processed before it is stored.
*
* The backend Content-Encoding header tells us what we are going
* to receive, which we classify in the following three classes:
*
* "Content-Encoding: gzip" --> object is gzip'ed.
* no Content-Encoding --> object is not gzip'ed.
* anything else --> do nothing wrt gzip
*
*/
/* We do nothing unless the param is set */
if (!cache_param->http_gzip_support)
bo->do_gzip = bo->do_gunzip = 0;
bo->is_gzip = http_HdrIs(bo->beresp, H_Content_Encoding, "gzip");
bo->is_gunzip = !http_GetHdr(bo->beresp, H_Content_Encoding, NULL);
/* It can't be both */
assert(bo->is_gzip == 0 || bo->is_gunzip == 0);
/* We won't gunzip unless it is gzip'ed */
if (bo->do_gunzip && !bo->is_gzip)
bo->do_gunzip = 0;
/* We wont gzip unless it is ungziped */
if (bo->do_gzip && !bo->is_gunzip)
bo->do_gzip = 0;
/* But we can't do both at the same time */
assert(bo->do_gzip == 0 || bo->do_gunzip == 0);
if (bo->do_gunzip || (bo->is_gzip && bo->do_esi))
(void)VFP_Push(bo->vfc, &vfp_gunzip, 1);
if (bo->do_esi && bo->do_gzip) {
(void)VFP_Push(bo->vfc, &vfp_esi_gzip, 1);
} else if (bo->do_esi && bo->is_gzip && !bo->do_gunzip) {
(void)VFP_Push(bo->vfc, &vfp_esi_gzip, 1);
} else if (bo->do_esi) {
(void)VFP_Push(bo->vfc, &vfp_esi, 1);
} else if (bo->do_gzip) {
(void)VFP_Push(bo->vfc, &vfp_gzip, 1);
} else if (bo->is_gzip && !bo->do_gunzip) {
(void)VFP_Push(bo->vfc, &vfp_testgunzip, 1);
}
if (bo->fetch_objcore->flags & OC_F_PRIVATE)
AN(bo->uncacheable);
/* No reason to try streaming a non-existing body */
if (bo->htc->body_status == BS_NONE)
bo->do_stream = 0;
if (VFP_Open(bo->vfc)) {
(void)VFP_Error(bo->vfc, "Fetch Pipeline failed to open");
bo->doclose = SC_RX_BODY;
VDI_Finish(bo->director_resp, bo->wrk, bo);
return (F_STP_ERROR);
}
if (vbf_beresp2obj(bo)) {
(void)VFP_Error(bo->vfc, "Could not get storage");
bo->doclose = SC_RX_BODY;
VDI_Finish(bo->director_resp, bo->wrk, bo);
return (F_STP_ERROR);
}
assert(WRW_IsReleased(wrk));
if (bo->do_gzip || (bo->is_gzip && !bo->do_gunzip))
ObjSetFlag(bo->wrk, bo->fetch_objcore, OF_GZIPED, 1);
if (bo->do_gzip || bo->do_gunzip)
ObjSetFlag(bo->wrk, bo->fetch_objcore, OF_CHGGZIP, 1);
if (http_IsStatus(bo->beresp, 200) && (
http_GetHdr(bo->beresp, H_Last_Modified, &p) ||
http_GetHdr(bo->beresp, H_ETag, &p)))
ObjSetFlag(bo->wrk, bo->fetch_objcore, OF_IMSCAND, 1);
if (bo->htc->body_status != BS_NONE)
AZ(VDI_GetBody(bo->director_resp, bo->wrk, bo));
/*
//.........这里部分代码省略.........
示例11: vbf_stp_condfetch
static enum fetch_step
vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
{
void *oi;
void *sp;
ssize_t sl, al, l;
uint8_t *ptr;
uint64_t ol;
enum objiter_status ois;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
AZ(vbf_beresp2obj(bo));
if (ObjGetattr(bo->wrk, bo->ims_oc, OA_ESIDATA, NULL) != NULL)
AZ(ObjCopyAttr(bo->wrk, bo->fetch_objcore, bo->ims_oc,
OA_ESIDATA));
AZ(ObjCopyAttr(bo->wrk, bo->fetch_objcore, bo->ims_oc, OA_FLAGS));
AZ(ObjCopyAttr(bo->wrk, bo->fetch_objcore, bo->ims_oc, OA_GZIPBITS));
if (bo->do_stream) {
HSH_Unbusy(wrk, bo->fetch_objcore);
VBO_setstate(bo, BOS_STREAM);
}
al = 0;
ol = ObjGetLen(bo->wrk, bo->ims_oc);
oi = ObjIterBegin(wrk, bo->ims_oc);
do {
ois = ObjIter(bo->ims_oc, oi, &sp, &sl);
while (sl > 0) {
l = ol - al;
if (VFP_GetStorage(bo->vfc, &l, &ptr) != VFP_OK)
break;
if (sl < l)
l = sl;
memcpy(ptr, sp, l);
VBO_extend(bo, l);
al += l;
sp = (char *)sp + l;
sl -= l;
}
} while (!bo->vfc->failed && (ois == OIS_DATA || ois == OIS_STREAM));
ObjIterEnd(bo->ims_oc, &oi);
if (bo->vfc->failed)
return (F_STP_FAIL);
if (!bo->do_stream)
HSH_Unbusy(wrk, bo->fetch_objcore);
assert(al == ol);
assert(ObjGetLen(bo->wrk, bo->fetch_objcore) == al);
EXP_Rearm(bo->ims_oc, bo->ims_oc->exp.t_origin, 0, 0, 0);
/* Recycle the backend connection before setting BOS_FINISHED to
give predictable backend reuse behavior for varnishtest */
VDI_Finish(bo->director_resp, bo->wrk, bo);
VBO_setstate(bo, BOS_FINISHED);
VSLb_ts_busyobj(bo, "BerespBody", W_TIM_real(wrk));
return (F_STP_DONE);
}
示例12: vbf_fetch_body_helper
static void
vbf_fetch_body_helper(struct busyobj *bo)
{
ssize_t l;
uint8_t *ptr;
enum vfp_status vfps = VFP_ERROR;
ssize_t est;
struct vfp_ctx *vfc;
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
vfc = bo->vfc;
CHECK_OBJ_NOTNULL(vfc, VFP_CTX_MAGIC);
AN(vfc->vfp_nxt);
est = bo->htc->content_length;
if (est < 0)
est = 0;
do {
if (bo->abandon) {
/*
* A pass object and delivery was terminted
* We don't fail the fetch, in order for hit-for-pass
* objects to be created.
*/
AN(vfc->oc->flags & OC_F_PASS);
VSLb(vfc->wrk->vsl, SLT_FetchError,
"Pass delivery abandoned");
vfps = VFP_END;
bo->doclose = SC_RX_BODY;
break;
}
AZ(vfc->failed);
l = est;
assert(l >= 0);
if (VFP_GetStorage(vfc, &l, &ptr) != VFP_OK) {
bo->doclose = SC_RX_BODY;
break;
}
AZ(vfc->failed);
vfps = VFP_Suck(vfc, ptr, &l);
if (l > 0 && vfps != VFP_ERROR) {
bo->acct.beresp_bodybytes += l;
VBO_extend(bo, l);
if (est >= l)
est -= l;
else
est = 0;
}
} while (vfps == VFP_OK);
VFP_Close(vfc);
if (vfps == VFP_ERROR) {
AN(vfc->failed);
(void)VFP_Error(vfc, "Fetch Pipeline failed to process");
bo->doclose = SC_RX_BODY;
}
if (!bo->do_stream)
ObjTrimStore(bo->wrk, vfc->oc);
}
示例13: vbf_stp_startfetch
static enum fetch_step
vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
{
int i, do_ims;
double now;
char time_str[VTIM_FORMAT_SIZE];
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
assert(bo->doclose == SC_NULL);
AZ(bo->storage_hint);
if (bo->do_pass)
AN(bo->req);
else
AZ(bo->req);
http_PrintfHeader(bo->bereq, "X-Varnish: %u", VXID(bo->vsl->wid));
VCL_backend_fetch_method(bo->vcl, wrk, NULL, bo, bo->bereq->ws);
bo->uncacheable = bo->do_pass;
if (wrk->handling == VCL_RET_ABANDON)
return (F_STP_FAIL);
assert (wrk->handling == VCL_RET_FETCH);
HTTP_Setup(bo->beresp, bo->ws, bo->vsl, SLT_BerespMethod);
assert(bo->state <= BOS_REQ_DONE);
i = VDI_GetHdr(wrk, bo);
now = W_TIM_real(wrk);
VSLb_ts_busyobj(bo, "Beresp", now);
if (i) {
assert(bo->director_state == DIR_S_NULL);
return (F_STP_ERROR);
}
http_VSL_log(bo->beresp);
if (!http_GetHdr(bo->beresp, H_Date, NULL)) {
/*
* RFC 2616 14.18 Date: The Date general-header field
* represents the date and time at which the message was
* originated, having the same semantics as orig-date in
* RFC 822. ... A received message that does not have a
* Date header field MUST be assigned one by the recipient
* if the message will be cached by that recipient or
* gatewayed via a protocol which requires a Date.
*
* If we didn't get a Date header, we assign one here.
*/
VTIM_format(now, time_str);
http_PrintfHeader(bo->beresp, "Date: %s", time_str);
}
/*
* These two headers can be spread over multiple actual headers
* and we rely on their content outside of VCL, so collect them
* into one line here.
*/
http_CollectHdr(bo->beresp, H_Cache_Control);
http_CollectHdr(bo->beresp, H_Vary);
/*
* Figure out how the fetch is supposed to happen, before the
* headers are adultered by VCL
*/
if (!strcasecmp(http_GetMethod(bo->bereq), "head")) {
/*
* A HEAD request can never have a body in the reply,
* no matter what the headers might say.
* [RFC2516 4.3 p33]
*/
wrk->stats->fetch_head++;
bo->htc->body_status = BS_NONE;
} else if (http_GetStatus(bo->beresp) <= 199) {
/*
* 1xx responses never have a body.
* [RFC2616 4.3 p33]
* ... but we should never see them.
*/
wrk->stats->fetch_1xx++;
bo->htc->body_status = BS_ERROR;
} else if (http_IsStatus(bo->beresp, 204)) {
/*
* 204 is "No Content", obviously don't expect a body.
* [RFC2616 10.2.5 p60]
*/
wrk->stats->fetch_204++;
bo->htc->body_status = BS_NONE;
} else if (http_IsStatus(bo->beresp, 304)) {
/*
* 304 is "Not Modified" it has no body.
* [RFC2616 10.3.5 p63]
*/
//.........这里部分代码省略.........
示例14: vbf_stp_condfetch
static enum fetch_step
vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
{
unsigned l;
uint16_t nhttp;
struct object *obj;
struct objiter *oi;
void *sp;
ssize_t sl, al, tl;
struct storage *st;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
l = 0;
if (bo->ims_obj->vary != NULL)
l += VRY_Len(bo->ims_obj->vary);
l += http_EstimateWS(bo->ims_obj->http, 0, &nhttp);
bo->stats = &wrk->stats;
obj = STV_NewObject(bo, bo->storage_hint, l, nhttp);
if (obj == NULL) {
(void)VFP_Error(bo, "Could not get storage");
VDI_CloseFd(&bo->vbc);
return (F_STP_DONE);
}
bo->stats = NULL;
AZ(bo->fetch_obj);
bo->fetch_obj = obj;
obj->gziped = bo->ims_obj->gziped;
obj->gzip_start = bo->ims_obj->gzip_start;
obj->gzip_last = bo->ims_obj->gzip_last;
obj->gzip_stop = bo->ims_obj->gzip_stop;
/* XXX: ESI */
if (bo->ims_obj->vary != NULL)
obj->vary = (void *)WS_Copy(obj->http->ws,
bo->ims_obj->vary, VRY_Len(bo->ims_obj->vary));
obj->vxid = bo->vsl->wid;
obj->http->logtag = HTTP_Obj;
/* XXX: we should have our own HTTP_A_CONDFETCH */
http_FilterResp(bo->ims_obj->http, obj->http, HTTPH_A_INS);
http_CopyHome(obj->http);
if (!(bo->fetch_obj->objcore->flags & OC_F_PRIVATE)) {
EXP_Insert(obj);
AN(obj->objcore->ban);
}
AZ(bo->ws_o->overflow);
VBO_setstate(bo, BOS_FETCHING);
HSH_Unbusy(&wrk->stats, obj->objcore);
st = NULL;
al = 0;
oi = ObjIterBegin(wrk, bo->ims_obj);
while (1 == ObjIter(oi, &sp, &sl)) {
while (sl > 0) {
if (st == NULL) {
st = VFP_GetStorage(bo, bo->ims_obj->len - al);
XXXAN(st);
}
tl = sl;
if (tl > st->space - st->len)
tl = st->space - st->len;
memcpy(st->ptr + st->len, sp, tl);
st->len += tl;
al += tl;
sp = (char *)sp + tl;
sl -= tl;
VBO_extend(bo, al);
if (st->len == st->space)
st = NULL;
}
}
assert(al == bo->ims_obj->len);
assert(obj->len == al);
if (bo->state != BOS_FAILED)
VBO_setstate(bo, BOS_FINISHED);
HSH_Complete(obj->objcore);
return (F_STP_DONE);
}
示例15: WRW_Flush
unsigned
WRW_Flush(const struct worker *wrk)
{
ssize_t i;
struct wrw *wrw;
char cbuf[32];
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
wrw = wrk->wrw;
CHECK_OBJ_NOTNULL(wrw, WRW_MAGIC);
AN(wrw->wfd);
/* For chunked, there must be one slot reserved for the chunked tail */
if (wrw->ciov < wrw->siov)
assert(wrw->niov < wrw->siov);
if (*wrw->wfd >= 0 && wrw->liov > 0 && wrw->werr == 0) {
if (wrw->ciov < wrw->siov && wrw->cliov > 0) {
/* Add chunk head & tail */
bprintf(cbuf, "00%zx\r\n", wrw->cliov);
i = strlen(cbuf);
wrw->iov[wrw->ciov].iov_base = cbuf;
wrw->iov[wrw->ciov].iov_len = i;
wrw->liov += i;
wrw->iov[wrw->niov].iov_base = cbuf + i - 2;
wrw->iov[wrw->niov++].iov_len = 2;
wrw->liov += 2;
} else if (wrw->ciov < wrw->siov) {
wrw->iov[wrw->ciov].iov_base = cbuf;
wrw->iov[wrw->ciov].iov_len = 0;
}
i = writev(*wrw->wfd, wrw->iov, wrw->niov);
while (i != wrw->liov && i > 0) {
/* Remove sent data from start of I/O vector,
* then retry; we hit a timeout, but some data
* was sent.
*
* XXX: Add a "minimum sent data per timeout
* counter to prevent slowlaris attacks
*/
if (VTIM_real() - wrw->t0 > cache_param->send_timeout) {
VSLb(wrw->vsl, SLT_Debug,
"Hit total send timeout, "
"wrote = %zd/%zd; not retrying",
i, wrw->liov);
i = -1;
break;
}
VSLb(wrw->vsl, SLT_Debug,
"Hit send timeout, wrote = %zd/%zd; retrying",
i, wrw->liov);
wrw_prune(wrw, i);
i = writev(*wrw->wfd, wrw->iov, wrw->niov);
}
if (i <= 0) {
wrw->werr++;
VSLb(wrw->vsl, SLT_Debug,
"Write error, retval = %zd, len = %zd, errno = %s",
i, wrw->liov, strerror(errno));
}
}
wrw->liov = 0;
wrw->cliov = 0;
wrw->niov = 0;
if (wrw->ciov < wrw->siov)
wrw->ciov = wrw->niov++;
return (wrw->werr);
}