+static struct timeval timeval_add(struct timeval a, struct timeval b)
+{
+ int usec = a.tv_usec + b.tv_usec;
+ a.tv_sec += b.tv_sec;
+ while (usec > 1000 * 1000) {
+ a.tv_sec += 1;
+ usec -= 1000 * 1000;
+ }
+ a.tv_usec = usec;
+ return a;
+}
+
+static int is_expired(struct timeval now, struct timeval expiry)
+{
+ return now.tv_sec > expiry.tv_sec
+ || (now.tv_sec == expiry.tv_sec && now.tv_usec > expiry.tv_usec);
+}
+