Commit dd7083a2 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Make generic functions for OA's in double format.

parent c0f7ed64
......@@ -1065,8 +1065,9 @@ void *ObjSetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr,
ssize_t len);
int ObjCopyAttr(struct objcore *ocd, struct objcore *ocs, struct dstat *ds,
enum obj_attr attr);
int ObjSetLastModified(struct objcore *oc, struct dstat *ds, double t);
double ObjGetLastModified(struct objcore *oc, struct dstat *ds);
int ObjSetDouble(struct objcore *, struct dstat *, enum obj_attr, double);
int ObjGetDouble(struct objcore *, struct dstat *, enum obj_attr, double *);
/* cache_panic.c */
void PAN_Init(void);
......
......@@ -165,10 +165,10 @@ vbf_beresp2obj(struct busyobj *bo)
http_CopyHome(hp2);
if (http_GetHdr(hp, H_Last_Modified, &b))
AZ(ObjSetLastModified(bo->fetch_objcore, bo->stats,
AZ(ObjSetDouble(bo->fetch_objcore, bo->stats, OA_LASTMODIFIED,
VTIM_parse(b)));
else
AZ(ObjSetLastModified(bo->fetch_objcore, bo->stats,
AZ(ObjSetDouble(bo->fetch_objcore, bo->stats, OA_LASTMODIFIED,
floor(bo->fetch_objcore->exp.t_origin)));
/* Disassociate the obj from the bo's workspace */
......
......@@ -307,36 +307,43 @@ ObjGetXID(struct objcore *oc, struct dstat *ds)
}
/*--------------------------------------------------------------------
* NB: Copying double <--> uint64_t for endian encoding is unverified
* There is no well-defined byteorder for IEEE-754 double and the
* correct solution (frexp(3) and manual encoding) is more work
* than our (weak) goal of being endian-agnostic requires at this point.
* We give it a shot by memcpy'ing doubles over a uint64_t and then
* BE encode that.
*/
int
ObjSetLastModified(struct objcore *oc, struct dstat *ds, double t)
ObjSetDouble(struct objcore *oc, struct dstat *ds, enum obj_attr a, double t)
{
void *vp;
uint64_t u;
assert(sizeof t == sizeof u);
memcpy(&u, &t, sizeof u);
vp = ObjSetattr(oc, ds, OA_LASTMODIFIED, sizeof u);
vp = ObjSetattr(oc, ds, a, sizeof u);
if (vp == NULL)
return (-1);
vbe64enc(vp, u);
return (0);
}
double
ObjGetLastModified(struct objcore *oc, struct dstat *ds)
int
ObjGetDouble(struct objcore *oc, struct dstat *ds, enum obj_attr a, double *d)
{
void *vp;
uint64_t u;
double d;
ssize_t l;
vp = ObjGetattr(oc, ds, OA_LASTMODIFIED, &l);
AN(vp);
assert(l == sizeof u);
u = vbe64dec(vp);
memcpy(&d, &u, sizeof d);
return (d);
assert(sizeof *d == sizeof u);
vp = ObjGetattr(oc, ds, a, &l);
if (vp == NULL)
return (-1);
if (d != NULL) {
assert(l == sizeof u);
u = vbe64dec(vp);
memcpy(d, &u, sizeof *d);
}
return (0);
}
......@@ -355,7 +355,8 @@ RFC2616_Do_Cond(const struct req *req)
ims = VTIM_parse(p);
if (ims > req->t_req) /* [RFC2616 14.25] */
return (0);
lm = ObjGetLastModified(req->objcore, &req->wrk->stats);
AZ(ObjGetDouble(req->objcore, &req->wrk->stats,
OA_LASTMODIFIED, &lm));
if (lm > ims)
return (0);
do_cond = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment