static void ses_setup(struct sessmem *sm) { struct sess *sp; CHECK_OBJ_NOTNULL(sm, SESSMEM_MAGIC); sp = &sm->sess; memset(sp, 0, sizeof *sp); /* We assume that the sess has been zeroed by the time we get here */ AZ(sp->magic); sp->magic = SESS_MAGIC; sp->mem = sm; sp->sockaddr = (void*)(&sm->sockaddr[0]); sp->sockaddrlen = sizeof(sm->sockaddr[0]); sp->mysockaddr = (void*)(&sm->sockaddr[1]); sp->mysockaddrlen = sizeof(sm->sockaddr[1]); sp->sockaddr->ss_family = sp->mysockaddr->ss_family = PF_UNSPEC; sp->t_open = NAN; sp->t_req = NAN; sp->t_resp = NAN; sp->t_end = NAN; EXP_Clr(&sp->exp); WS_Init(sp->ws, "sess", sm->wsp, sm->workspace); sp->http = sm->http[0]; sp->http0 = sm->http[1]; }
static struct sess * ses_new(struct sesspool *pp) { struct sess *sp; unsigned sz; char *p, *e; CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC); sp = MPL_Get(pp->mpl_sess, &sz); sp->magic = SESS_MAGIC; sp->sesspool = pp; e = (char*)sp + sz; p = (char*)(sp + 1); p = (void*)PRNDUP(p); assert(p < e); WS_Init(sp->ws, "ses", p, e - p); sp->addrs = (void*)WS_Alloc(sp->ws, vsa_suckaddr_len * 2); sp->t_open = NAN; sp->t_idle = NAN; Lck_New(&sp->mtx, lck_sess); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); return (sp); }
struct sess * SES_New(struct pool *pp) { struct sess *sp; unsigned sz; char *p, *e; CHECK_OBJ_NOTNULL(pp, POOL_MAGIC); sp = MPL_Get(pp->mpl_sess, &sz); sp->magic = SESS_MAGIC; sp->pool = pp; sp->refcnt = 1; memset(sp->sattr, 0xff, sizeof sp->sattr); e = (char*)sp + sz; p = (char*)(sp + 1); p = (void*)PRNDUP(p); assert(p < e); WS_Init(sp->ws, "ses", p, e - p); sp->t_open = NAN; sp->t_idle = NAN; Lck_New(&sp->mtx, lck_sess); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); return (sp); }
static void * wrk_thread_real(void *priv, unsigned thread_workspace) { struct worker *w, ww; unsigned char ws[thread_workspace]; THR_SetName("cache-worker"); w = &ww; memset(w, 0, sizeof *w); w->magic = WORKER_MAGIC; w->lastused = NAN; AZ(pthread_cond_init(&w->cond, NULL)); WS_Init(w->aws, "wrk", ws, thread_workspace); VSL(SLT_WorkThread, 0, "%p start", w); Pool_Work_Thread(priv, w); AZ(w->pool); VSL(SLT_WorkThread, 0, "%p end", w); if (w->vcl != NULL) VCL_Rel(&w->vcl); AZ(pthread_cond_destroy(&w->cond)); if (w->nvbo != NULL) VBO_Free(&w->nvbo); HSH_Cleanup(w); WRK_SumStat(w); return (NULL); }
extern "C" __declspec(dllexport) int Load(void) { mir_getLP(&pluginInfo); mir_getCLI(); hmiranda = GetModuleHandle(NULL); INITCOMMONCONTROLSEX ctrls = {0}; ctrls.dwSize = sizeof(INITCOMMONCONTROLSEX); ctrls.dwICC = ICC_DATE_CLASSES; InitCommonControlsEx(&ctrls); hRichedDll = LoadLibrary(_T("Msftedit.dll")); if (!hRichedDll) { if (MessageBox(0, TranslateT("Miranda could not load the Notes & Reminders plugin, Msftedit.dll is missing. If you are using WINE, please make sure you have Msftedit.dll installed. Press 'Yes' to continue loading Miranda."), _T(SECTIONNAME), MB_YESNO | MB_ICONINFORMATION) != IDYES) return 1; return 0; } InitServices(); WS_Init(); hkModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); InitIcons(); return 0; }
void SES_GetReq(struct sess *sp) { struct sesspool *pp; uint16_t nhttp; unsigned sz, hl; char *p, *e; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); pp = sp->sesspool; CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC); AN(pp->pool); AZ(sp->req); sp->req = MPL_Get(pp->mpl_req, &sz); AN(sp->req); sp->req->magic = REQ_MAGIC; e = (char*)sp->req + sz; p = (char*)(sp->req + 1); p = (void*)PRNDUP(p); assert(p < e); nhttp = (uint16_t)cache_param->http_max_hdr; hl = HTTP_estimate(nhttp); sp->req->http = HTTP_create(p, nhttp); p += hl; p = (void*)PRNDUP(p); assert(p < e); sp->req->http0 = HTTP_create(p, nhttp); p += hl; p = (void*)PRNDUP(p); assert(p < e); sp->req->resp = HTTP_create(p, nhttp); p += hl; p = (void*)PRNDUP(p); assert(p < e); sz = cache_param->workspace_thread; VSL_Setup(sp->req->vsl, p, sz); sp->req->vsl->wid = sp->vsl_id; p += sz; p = (void*)PRNDUP(p); assert(p < e); WS_Init(sp->req->ws, "req", p, e - p); }
static void * server_bgthread(struct worker *wrk, void *priv) { struct vmod_fsdirector_file_system *fs; struct sockaddr_storage addr_s; socklen_t len; struct http_conn *htc; int fd; enum htc_status_e htc_status; CAST_OBJ_NOTNULL(fs, priv, VMOD_FSDIRECTOR_MAGIC); assert(fs->sock >= 0); htc = &fs->htc; fs->wrk = wrk; WS_Init(wrk->aws, fs->ws_name, malloc(WS_LEN), WS_LEN); while (1) { do { fd = accept(fs->sock, (void*)&addr_s, &len); } while (fd < 0 && errno == EAGAIN); if (fd < 0) { continue; } HTTP1_Init(htc, wrk->aws, fd, NULL, HTTP1_BUF, HTTP1_MAX_HDR); htc_status = HTTP1_Rx(htc); switch (htc_status) { case HTTP1_OVERFLOW: case HTTP1_ERROR_EOF: case HTTP1_ALL_WHITESPACE: case HTTP1_NEED_MORE: prepare_answer(htc, 400); prepare_body(htc); break; case HTTP1_COMPLETE: answer_appropriate(fs); break; } WS_Reset(wrk->aws, NULL); close(fd); } pthread_exit(0); NEEDLESS_RETURN(NULL); }
static void * wrk_thread_real(void *priv, unsigned shm_workspace, unsigned sess_workspace, uint16_t nhttp, unsigned http_space, unsigned siov) { struct worker *w, ww; uint32_t wlog[shm_workspace / 4]; /* XXX: can we trust these to be properly aligned ? */ unsigned char ws[sess_workspace]; unsigned char http0[http_space]; unsigned char http1[http_space]; unsigned char http2[http_space]; struct iovec iov[siov]; struct SHA256Context sha256; THR_SetName("cache-worker"); w = &ww; memset(w, 0, sizeof *w); w->magic = WORKER_MAGIC; w->lastused = NAN; w->wlb = w->wlp = wlog; w->wle = wlog + (sizeof wlog) / 4; w->sha256ctx = &sha256; w->bereq = HTTP_create(http0, nhttp); w->beresp = HTTP_create(http1, nhttp); w->resp = HTTP_create(http2, nhttp); w->wrw.iov = iov; w->wrw.siov = siov; w->wrw.ciov = siov; AZ(pthread_cond_init(&w->cond, NULL)); WS_Init(w->ws, "wrk", ws, sess_workspace); VSL(SLT_WorkThread, 0, "%p start", w); Pool_Work_Thread(priv, w); AZ(w->pool); VSL(SLT_WorkThread, 0, "%p end", w); if (w->vcl != NULL) VCL_Rel(&w->vcl); AZ(pthread_cond_destroy(&w->cond)); HSH_Cleanup(w); WRK_SumStat(w); return (NULL); }
void WRK_Thread(struct pool *qp, size_t stacksize, unsigned thread_workspace) { struct worker *w, ww; unsigned char ws[thread_workspace]; uintptr_t u; AN(qp); AN(stacksize); AN(thread_workspace); THR_SetName("cache-worker"); w = &ww; INIT_OBJ(w, WORKER_MAGIC); w->lastused = NAN; AZ(pthread_cond_init(&w->cond, NULL)); WS_Init(w->aws, "wrk", ws, thread_workspace); u = getpagesize(); AN(u); u -= 1U; w->stack_start = (((uintptr_t)&qp) + u) & ~u; /* XXX: assuming stack grows down. */ w->stack_end = w->stack_start - stacksize; VSL(SLT_WorkThread, 0, "%p start", w); Pool_Work_Thread(qp, w); AZ(w->pool); VSL(SLT_WorkThread, 0, "%p end", w); if (w->vcl != NULL) VCL_Rel(&w->vcl); AZ(pthread_cond_destroy(&w->cond)); if (w->nbo != NULL) VBO_Free(&w->nbo); HSH_Cleanup(w); Pool_Sumstat(w); }
struct busyobj * VBO_GetBusyObj(struct worker *wrk, const struct req *req) { struct busyobj *bo = NULL; uint16_t nhttp; unsigned sz; char *p; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); if (wrk->nbo != NULL) { bo = wrk->nbo; wrk->nbo = NULL; } if (bo == NULL) bo = vbo_New(); CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); AZ(bo->refcount); bo->refcount = 1; p = (void*)(bo + 1); p = (void*)PRNDUP(p); assert(p < bo->end); nhttp = (uint16_t)cache_param->http_max_hdr; sz = HTTP_estimate(nhttp); bo->bereq0 = HTTP_create(p, nhttp); p += sz; p = (void*)PRNDUP(p); assert(p < bo->end); bo->bereq = HTTP_create(p, nhttp); p += sz; p = (void*)PRNDUP(p); assert(p < bo->end); bo->beresp = HTTP_create(p, nhttp); p += sz; p = (void*)PRNDUP(p); assert(p < bo->end); sz = cache_param->vsl_buffer; VSL_Setup(bo->vsl, p, sz); bo->vsl->wid = VXID_Get(wrk, VSL_BACKENDMARKER); p += sz; p = (void*)PRNDUP(p); assert(p < bo->end); WS_Init(bo->ws, "bo", p, bo->end - p); bo->do_stream = 1; bo->director = req->director_hint; bo->vcl = req->vcl; VCL_Ref(bo->vcl); bo->t_first = bo->t_prev = NAN; bo->content_length = -1; bo->doclose = SC_NULL; return (bo); }
struct busyobj * VBO_GetBusyObj(struct worker *wrk, struct req *req) { struct busyobj *bo = NULL; uint16_t nhttp; unsigned sz; char *p; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); if (wrk->nbo != NULL) { bo = wrk->nbo; wrk->nbo = NULL; } if (bo == NULL) bo = vbo_New(); CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); AZ(bo->refcount); bo->refcount = 1; p = (void*)(bo + 1); p = (void*)PRNDUP(p); assert(p < bo->end); nhttp = (uint16_t)cache_param->http_max_hdr; sz = HTTP_estimate(nhttp); bo->bereq0 = HTTP_create(p, nhttp); p += sz; p = (void*)PRNDUP(p); assert(p < bo->end); bo->bereq = HTTP_create(p, nhttp); p += sz; p = (void*)PRNDUP(p); assert(p < bo->end); bo->beresp = HTTP_create(p, nhttp); p += sz; p = (void*)PRNDUP(p); assert(p < bo->end); sz = cache_param->vsl_buffer; VSL_Setup(bo->vsl, p, sz); bo->vsl->wid = VXID_Get(&wrk->vxid_pool) | VSL_BACKENDMARKER; VSLb(bo->vsl, SLT_Begin, "bereq %u", req->vsl->wid & VSL_IDENTMASK); VSLb(req->vsl, SLT_Link, "bereq %u", bo->vsl->wid & VSL_IDENTMASK); p += sz; p = (void*)PRNDUP(p); assert(p < bo->end); WS_Init(bo->ws, "bo", p, bo->end - p); bo->do_stream = 1; bo->director = req->director; bo->vcl = req->vcl; VCL_Ref(bo->vcl); bo->t_fetch = req->t_req; return (bo); }
struct req * SES_GetReq(const struct worker *wrk, struct sess *sp) { struct sesspool *pp; struct req *req; uint16_t nhttp; unsigned sz, hl; char *p, *e; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); pp = sp->sesspool; CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC); AN(pp->pool); req = MPL_Get(pp->mpl_req, &sz); AN(req); req->magic = REQ_MAGIC; req->sp = sp; e = (char*)req + sz; p = (char*)(req + 1); p = (void*)PRNDUP(p); assert(p < e); nhttp = (uint16_t)cache_param->http_max_hdr; hl = HTTP_estimate(nhttp); req->http = HTTP_create(p, nhttp); p += hl; p = (void*)PRNDUP(p); assert(p < e); req->http0 = HTTP_create(p, nhttp); p += hl; p = (void*)PRNDUP(p); assert(p < e); req->resp = HTTP_create(p, nhttp); p += hl; p = (void*)PRNDUP(p); assert(p < e); sz = cache_param->vsl_buffer; VSL_Setup(req->vsl, p, sz); p += sz; p = (void*)PRNDUP(p); assert(p < e); WS_Init(req->ws, "req", p, e - p); req->req_bodybytes = 0; req->resp_hdrbytes = 0; req->resp_bodybytes = 0; req->t_first = NAN; req->t_prev = NAN; req->t_req = NAN; return (req); }
struct req * Req_New(const struct worker *wrk, struct sess *sp) { struct pool *pp; struct req *req; uint16_t nhttp; unsigned sz, hl; char *p, *e; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); pp = sp->pool; CHECK_OBJ_NOTNULL(pp, POOL_MAGIC); req = MPL_Get(pp->mpl_req, &sz); AN(req); req->magic = REQ_MAGIC; req->sp = sp; e = (char*)req + sz; p = (char*)(req + 1); p = (void*)PRNDUP(p); assert(p < e); nhttp = (uint16_t)cache_param->http_max_hdr; hl = HTTP_estimate(nhttp); req->http = HTTP_create(p, nhttp, hl); p += hl; p = (void*)PRNDUP(p); assert(p < e); req->http0 = HTTP_create(p, nhttp, hl); p += hl; p = (void*)PRNDUP(p); assert(p < e); req->resp = HTTP_create(p, nhttp, hl); p += hl; p = (void*)PRNDUP(p); assert(p < e); sz = cache_param->vsl_buffer; VSL_Setup(req->vsl, p, sz); p += sz; p = (void*)PRNDUP(p); req->vfc = (void*)p; INIT_OBJ(req->vfc, VFP_CTX_MAGIC); p = (void*)PRNDUP(p + sizeof(*req->vfc)); req->htc = (void*)p; p = (void*)PRNDUP(p + sizeof(*req->htc)); req->vdc = (void*)p; INIT_OBJ(req->vdc, VDP_CTX_MAGIC); VTAILQ_INIT(&req->vdc->vdp); p = (void*)PRNDUP(p + sizeof(*req->vdc)); req->htc = (void*)p; INIT_OBJ(req->htc, HTTP_CONN_MAGIC); p = (void*)PRNDUP(p + sizeof(*req->htc)); assert(p < e); WS_Init(req->ws, "req", p, e - p); req->t_first = NAN; req->t_prev = NAN; req->t_req = NAN; req->topreq = req; return (req); }
struct req * SES_GetReq(struct worker *wrk, struct sess *sp) { struct sesspool *pp; struct req *req; uint16_t nhttp; unsigned sz, hl; char *p, *e; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); pp = sp->sesspool; CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC); AN(pp->pool); req = MPL_Get(pp->mpl_req, &sz); AN(req); req->magic = REQ_MAGIC; req->sp = sp; e = (char*)req + sz; p = (char*)(req + 1); p = (void*)PRNDUP(p); assert(p < e); nhttp = (uint16_t)cache_param->http_max_hdr; hl = HTTP_estimate(nhttp); req->http = HTTP_create(p, nhttp); p += hl; p = (void*)PRNDUP(p); assert(p < e); req->http0 = HTTP_create(p, nhttp); p += hl; p = (void*)PRNDUP(p); assert(p < e); req->resp = HTTP_create(p, nhttp); p += hl; p = (void*)PRNDUP(p); assert(p < e); sz = cache_param->vsl_buffer; VSL_Setup(req->vsl, p, sz); req->vsl->wid = VXID_Get(&wrk->vxid_pool) | VSL_CLIENTMARKER; VSLb(req->vsl, SLT_Begin, "req %u", sp->vxid & VSL_IDENTMASK); VSL(SLT_Link, req->sp->vxid, "req %u", req->vsl->wid & VSL_IDENTMASK); p += sz; p = (void*)PRNDUP(p); assert(p < e); WS_Init(req->ws, "req", p, e - p); req->t_req = NAN; req->t_resp = NAN; VTAILQ_INIT(&req->body); return (req); }