static void ses_req_pool_task(struct worker *wrk, void *arg) { struct req *req; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CAST_OBJ_NOTNULL(req, arg, REQ_MAGIC); THR_SetRequest(req); AZ(wrk->aws->r); wrk->lastused = NAN; HTTP1_Session(wrk, req); WS_Assert(wrk->aws); AZ(wrk->wrw); if (DO_DEBUG(DBG_VCLREL) && wrk->vcl != NULL) VCL_Rel(&wrk->vcl); THR_SetRequest(NULL); }
/*------------------------------------------------------------------------------ * function: AttrProj::ReadRec * Read a record from the data source, and project it onto the attribute * combinations corresponding to this object. */ DevStatus AttrProj::ReadRec(RecId recId, VectorArray &vecArray) { DO_DEBUG(printf("AttrProj::ReadRec(%d)\n", (int) recId)); int dataSize; int numRecs; DevStatus result = StatusOk; TData::TDHandle handle = _tDataP->InitGetRecs(recId, recId); if (!_tDataP->GetRecs(handle, _recBuf, _recBufSize, recId, numRecs, dataSize)) { result = StatusFailed; } else { AttrList * attrListP = _tDataP->GetAttrList(); int projNum = 0; Projection * projP = _projList.GetFirstProj(); while (projP != NULL) { Vector * vectorP = vecArray.GetVector(projNum); int projAttrNum; for (projAttrNum = 0; projAttrNum < projP->attrCount; projAttrNum++) { int attrNum = projP->attrList[projAttrNum]; AttrInfo * attrInfoP = attrListP->Get(attrNum); vectorP->value[projAttrNum] = AttrToDouble(attrInfoP->type, _recBuf + attrInfoP->offset); } projP = _projList.GetNextProj(); projNum++; } } _tDataP->DoneGetRecs(handle); return result; }
/*------------------------------------------------------------------------------ * function: AttrProj::AttrProj * AttrProj constructor. */ AttrProj::AttrProj(char *schemaFile, char *attrProjFile, char *dataFile) { DO_DEBUG(printf("AttrProj::AttrProj(%s, %s, %s)\n", schemaFile, attrProjFile, dataFile)); DOASSERT(dataFile != NULL, "Can't have NULL datafile"); // Provision for having the schema in the data file. if ((schemaFile == NULL) || !strcmp(schemaFile, "")) { schemaFile = dataFile; } // strdups because TData destructor will try to free all of these // strings -- make sure they're dynamic. schemaFile = strdup(schemaFile); attrProjFile = strdup(attrProjFile); dataFile = strdup(dataFile); DataSeg::Set(schemaFile, dataFile, 0, 0); char *schemaName = ApParseCat(schemaFile, dataFile, _tDataP); DOASSERT(schemaName != NULL, "Can' parse schema"); DevStatus ppRes = ParseProjection(attrProjFile); DOASSERT(ppRes.IsComplete(), "Can't parse projection"); _recBufSize = _tDataP->RecSize(); _recBuf = new char[_recBufSize]; _attrCounts = new int[_projList.GetProjCount()]; _projSizes = new int[_projList.GetProjCount()]; int projNum = 0; Projection * projP = _projList.GetFirstProj(); while (projP != NULL) { _attrCounts[projNum] = projP->attrCount; _projSizes[projNum] = projP->attrCount * sizeof(VECTOR_TYPE); projP = _projList.GetNextProj(); projNum++; } }
SES_Proto_Req(struct worker *wrk, void *arg) { struct req *req; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CAST_OBJ_NOTNULL(req, arg, REQ_MAGIC); THR_SetRequest(req); AZ(wrk->aws->r); if (req->sp->sess_step < S_STP_H1_LAST) { HTTP1_Session(wrk, req); AZ(wrk->v1l); } else { WRONG("Wrong session step"); } WS_Assert(wrk->aws); if (DO_DEBUG(DBG_VCLREL) && wrk->vcl != NULL) VCL_Rel(&wrk->vcl); THR_SetRequest(NULL); }
/*------------------------------------------------------------------------------ * function: AttrProj::CreateRecordList * Creates a record list (VectorArray) that can hold the projected * records specified in the attribute projection file. */ DevStatus AttrProj::CreateRecordList(VectorArray *&vecArrayP) { DO_DEBUG(printf("AttrProj::CreateRecordList()\n")); DevStatus result = StatusOk; vecArrayP = new VectorArray(_projList.GetProjCount()); int projNum = 0; Projection * projP = _projList.GetFirstProj(); while (projP != NULL) { vecArrayP->Init(projNum, projP->attrCount); projP = _projList.GetNextProj(); projNum++; } return result; }
vfp_esi_gzip_pull(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p, ssize_t *lp) { enum vfp_status vp; ssize_t d, l; struct vef_priv *vef; CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC); CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC); CAST_OBJ_NOTNULL(vef, vfe->priv1, VEF_MAGIC); AN(p); AN(lp); *lp = 0; l = vef->ibuf_sz - (vef->ibuf_i - vef->ibuf); if (DO_DEBUG(DBG_ESI_CHOP)) { d = (random() & 3) + 1; if (d < l) l = d; } vp = VFP_Suck(vc, vef->ibuf_i, &l); if (l > 0) { VEP_Parse(vef->vep, vef->ibuf_i, l); vef->ibuf_i += l; assert(vef->ibuf_o >= vef->ibuf && vef->ibuf_o <= vef->ibuf_i); if (vef->error) { errno = vef->error; return (VFP_ERROR); } l = vef->ibuf_i - vef->ibuf_o; if (l > 0) memmove(vef->ibuf, vef->ibuf_o, l); vef->ibuf_o = vef->ibuf; vef->ibuf_i = vef->ibuf + l; } if (vp == VFP_END) { vp = vfp_esi_end(vc, vef, vp); vfe->priv1 = NULL; } return (vp); }
/*------------------------------------------------------------------------------ * function: AttrProj::GetWholeRecSize * Returns information about the size of data that will be produced when * an entire record (not its projections) is read. */ DevStatus AttrProj::GetWholeRecSize(int &attrCount, int &recSize) { DO_DEBUG(printf("AttrProj::GetWholeRecSize()\n")); DevStatus result = StatusOk; attrCount = 0; recSize = 0; AttrList *attrListP = _tDataP->GetAttrList(); attrListP->InitIterator(); while (attrListP->More()) { AttrInfo *attrInfoP = attrListP->Next(); attrCount++; recSize += sizeof(VECTOR_TYPE); } attrListP->DoneIterator(); return result; }
/*------------------------------------------------------------------------------ * function: AttrProj::ReadWholeRec * Read an entire record (not its projections). */ DevStatus AttrProj::ReadWholeRec(RecId recId, Vector &vector) { DO_DEBUG(printf("AttrProj::ReadWholeRec()\n")); DevStatus result = StatusOk; TData::TDHandle handle = _tDataP->InitGetRecs(recId, recId); int dataSize; int numRecs; if (!_tDataP->GetRecs(handle, _recBuf, _recBufSize, recId, numRecs, dataSize)) { result = StatusFailed; } else { AttrList * attrListP = _tDataP->GetAttrList(); int attrNum = 0; attrListP->InitIterator(); while (attrListP->More()) { AttrInfo *attrInfoP = attrListP->Next(); vector.value[attrNum] = AttrToDouble(attrInfoP->type, _recBuf + attrInfoP->offset); attrNum++; } attrListP->DoneIterator(); } _tDataP->DoneGetRecs(handle); return result; }
/*------------------------------------------------------------------------------ * function: VectorArray::~VectorArray * VectorArray destructor. */ VectorArray::~VectorArray() { DO_DEBUG(printf("VectorArray::~VectorArray()\n")); delete [] _vectors; }
/*------------------------------------------------------------------------------ * function: DataSourceFileDesc::~DataSourceFileDesc * DataSourceFileDesc destructor. */ DataSourceFileDesc::~DataSourceFileDesc() { DO_DEBUG(printf("DataSourceFileDesc::~DataSourceFileDesc()\n")); if (_fd >= 0) close(_fd); }
void V1D_Deliver(struct req *req, struct busyobj *bo) { const char *r; enum objiter_status ois; CHECK_OBJ_NOTNULL(req, REQ_MAGIC); CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC); req->res_mode = 0; /* * Determine ESI status first. Not dependent on wantbody, because * we want ESI to supress C-L in HEAD too. */ if (!req->disable_esi && ObjGetattr(req->wrk, req->objcore, OA_ESIDATA, NULL) != NULL) req->res_mode |= RES_ESI; /* * ESI-childen don't care about headers -> early escape */ if (req->esi_level > 0) { ESI_DeliverChild(req, bo); return; } if (req->res_mode & RES_ESI) { RFC2616_Weaken_Etag(req->resp); } else if (http_IsStatus(req->resp, 304)) { http_Unset(req->resp, H_Content_Length); req->wantbody = 0; } else if (bo == NULL && !http_GetHdr(req->resp, H_Content_Length, NULL)) { http_PrintfHeader(req->resp, "Content-Length: %ju", (uintmax_t)ObjGetLen( req->wrk, req->objcore)); } if (cache_param->http_gzip_support && ObjCheckFlag(req->wrk, req->objcore, OF_GZIPED) && !RFC2616_Req_Gzip(req->http)) { /* * We don't know what it uncompresses to * XXX: we could cache that, but would still deliver * XXX: with multiple writes because of the gunzip buffer */ req->res_mode |= RES_GUNZIP; VDP_push(req, VDP_gunzip, NULL, 0); } if (req->res_mode & RES_ESI) { /* Gunzip could have added back a C-L */ http_Unset(req->resp, H_Content_Length); } /* * Range comes after the others and pushes on bottom because it * can generate a correct C-L header. */ if (cache_param->http_range_support && http_IsStatus(req->resp, 200)) { http_SetHeader(req->resp, "Accept-Ranges: bytes"); if (req->wantbody && http_GetHdr(req->http, H_Range, &r)) VRG_dorange(req, bo, r); } if (http_GetHdr(req->resp, H_Content_Length, NULL)) req->res_mode |= RES_LEN; if (req->wantbody && !(req->res_mode & RES_LEN)) { if (req->http->protover >= 11) { req->res_mode |= RES_CHUNKED; http_SetHeader(req->resp, "Transfer-Encoding: chunked"); } else { req->res_mode |= RES_EOF; req->doclose = SC_TX_EOF; } } VSLb(req->vsl, SLT_Debug, "RES_MODE %x", req->res_mode); if (req->doclose) { if (!http_HdrIs(req->resp, H_Connection, "close")) { http_Unset(req->resp, H_Connection); http_SetHeader(req->resp, "Connection: close"); } } else if (!http_GetHdr(req->resp, H_Connection, NULL)) http_SetHeader(req->resp, "Connection: keep-alive"); VDP_push(req, v1d_bytes, NULL, 1); V1L_Reserve(req->wrk, req->ws, &req->sp->fd, req->vsl, req->t_prev); req->acct.resp_hdrbytes += HTTP1_Write(req->wrk, req->resp, HTTP1_Resp); if (DO_DEBUG(DBG_FLUSH_HEAD)) (void)V1L_Flush(req->wrk); ois = OIS_DONE; if (req->wantbody) { if (req->res_mode & RES_CHUNKED) V1L_Chunked(req->wrk); ois = VDP_DeliverObj(req); (void)VDP_bytes(req, VDP_FLUSH, NULL, 0); if (ois == OIS_DONE && (req->res_mode & RES_CHUNKED)) V1L_EndChunk(req->wrk); } if ((V1L_FlushRelease(req->wrk) || ois != OIS_DONE) && req->sp->fd >= 0) SES_Close(req->sp, SC_REM_CLOSE); VDP_close(req); }
/*------------------------------------------------------------------------------ * function: AttrProj::ParseProjection * Parse the attribute projection file and build up the corresponding * data structures. */ DevStatus AttrProj::ParseProjection(char *attrProjFile) { DO_DEBUG(printf("AttrProj::ParseProjection()\n")); DevStatus result = StatusOk; FILE * file = fopen(attrProjFile, "r"); if (file == NULL) { fprintf(stderr, "Can't open attribute projection file\n"); result = StatusFailed; } else { const int bufSize = 4096; char buf[bufSize]; char separators[] = " \t"; /* Get each line in the attribute projection file. */ while (fgets(buf, bufSize, file) != NULL) { DOASSERT(buf[strlen(buf)-1] == '\n', "Projection file line too long"); /* TEMPTEMP -- we should look for some kind of comment char. */ StripTrailingNewline(buf); DO_DEBUG(printf("%s\n", buf)); Projection projection; char * token = strtok(buf, separators); if (token == NULL) continue; projection.attrCount = atoi(token); DO_DEBUG(printf("projection.attrCount = %d\n", projection.attrCount)); projection.attrList = new int[projection.attrCount]; AttrList * attrListP = _tDataP->GetAttrList(); int attrCount = attrListP->NumAttrs(); int projAttrNum = 0; /* Find each attribute specified for this projection. */ while ((token = strtok(NULL, separators)) != NULL) { projection.attrList[projAttrNum] = illegalAttr; DO_DEBUG(printf(" token = %s", token)); int attrNum; /* Now find the attribute in the TData corresponding to * the name specified in the projection. */ for (attrNum = 0; attrNum < attrCount; attrNum++) { AttrInfo * attrInfoP = attrListP->Get(attrNum); if (!strcmp(token, attrInfoP->name)) { DO_DEBUG(printf(" attrNum = %d\n", attrNum)); projection.attrList[projAttrNum] = attrNum; break; } } DOASSERT(projection.attrList[projAttrNum] != illegalAttr, "Illegal attribute name in attribute projection file"); projAttrNum++; } DOASSERT(projAttrNum == projection.attrCount, "Incorrect number of attributes in projection file"); _projList.AddProjection(projection); } fclose(file); } return result; }