waituntil(c(sv)->last_start + c(sv)->period);
}
+static void daemon_init(service_t to)
+{
+ /* create ->classinfo with defaults */
+ daemon_t n;
+
+ n = (daemon_t)malloc(sizeof(struct daemon_opts));
+ n->min = 0;
+ n->period = 0;
+ n->last_start = 0;
+ to->classinfo = n;
+}
+
static void daemon_copy(service_t from, service_t to)
{
- /* copy the classinfo - min and period */
- daemon_t n; // o;
- if (from)
- {
- /* no special state to copy
- * the new service should have parsed its own args
- * - simonb 11nov2003
- */
- //o = from->classinfo;
- //n->min = o->min;
- //n->period = o->period;
- //n->last_start = o->last_start;
- }
- else
- {
- n = (daemon_t)malloc(sizeof(struct daemon_opts));
- n->min = 0;
- n->period = 0;
- n->last_start = 0;
- to->classinfo = n;
- }
+ /* copy the 'state' classinfo - last_start */
+
+ c(to)->last_start = c(from)->last_start;
}
static void daemon_freestate(service_t sv)
.c_process_opt = daemon_opt,
.register_service = daemon_register,
.c_check_service= daemon_check,
+ .init_state = daemon_init,
.copy_state = daemon_copy,
.free_state = daemon_freestate,
.send_class = daemon_send,
int (*c_process_opt)(); /* function to processes options */
void (*register_service)(); /* register the service if necessary */
void (*c_check_service)(); /* check if anything needs to be done for a service */
+ void (*init_state)(); /* copy state from old service struct to new */
void (*copy_state)(); /* copy state from old service struct to new */
void (*free_state)(); /* free class dependant state */
void (*send_class)(); /* send class info */
sv->pending = 0;
sv->proc_list = skip_new(proc_cmp, NULL, NULL);
sv->next_hold = 2;
- (*class->copy_state)(NULL, sv);
+ (*class->init_state)(sv);
return sv;
}
return 0;
}
-static void stream_copy(service_t from, service_t to)
+static void stream_init(service_t to)
{
- stream_t n,o;
+ /* set up defaults */
+ stream_t n;
n = (stream_t)malloc(sizeof(struct stream_opts));
- if (from) {
- o = from->classinfo;
- n->proto = o->proto;
- n->port = o->port;
- n->sock = o->sock;
- n->backlog = o->backlog;
- o->sock = -1;
- n->newsock = -1;
- } else {
- n->proto = IPPROTO_TCP;
- n->backlog = 10;
- n->port = 0;
- n->sock = -1;
- n->newsock = -1;
- }
+
+ n->proto = IPPROTO_TCP;
+ n->backlog = 10;
+ n->port = 0;
+ n->sock = -1;
+ n->newsock = -1;
+
to->classinfo = n;
}
+static void stream_copy(service_t from, service_t to)
+{
+ /* copy state */
+
+ c(to)->sock = c(from)->sock;
+ c(from)->sock = -1;
+}
+
static void stream_freestate(service_t sv)
{
stream_t s = sv->classinfo;
.c_process_opt = stream_opt,
.register_service= stream_register,
.c_check_service= stream_check,
+ .init_state = stream_init,
.copy_state = stream_copy,
.free_state = stream_freestate,
.send_class = stream_send,