static int nn_xsurveyor_create (void *hint, struct nn_sockbase **sockbase) { struct nn_xsurveyor *self; self = nn_alloc (sizeof (struct nn_xsurveyor), "socket (xsurveyor)"); alloc_assert (self); nn_xsurveyor_init (self, &nn_xsurveyor_sockbase_vfptr, hint); *sockbase = &self->sockbase; return 0; }
static void nn_surveyor_init (struct nn_surveyor *self, const struct nn_sockbase_vfptr *vfptr, void *hint) { nn_xsurveyor_init (&self->xsurveyor, vfptr, hint); nn_fsm_init_root (&self->fsm, nn_surveyor_handler, nn_sockbase_getctx (&self->xsurveyor.sockbase)); self->state = NN_SURVEYOR_STATE_IDLE; /* Start assigning survey IDs beginning with a random number. This way there should be no key clashes even if the executable is re-started. */ nn_random_generate (&self->surveyid, sizeof (self->surveyid)); nn_timer_init (&self->timer, NN_SURVEYOR_SRC_DEADLINE_TIMER, &self->fsm); nn_msg_init (&self->tosend, 0); self->deadline = NN_SURVEYOR_DEFAULT_DEADLINE; /* Start the state machine. */ nn_fsm_start (&self->fsm); }
static int nn_surveyor_init (struct nn_surveyor *self, const struct nn_sockbase_vfptr *vfptr) { int rc; rc = nn_xsurveyor_init (&self->xsurveyor, vfptr); if (rc < 0) return rc; self->sink = &nn_surveyor_sink; self->flags = 0; /* Start assigning survey IDs beginning with a random number. This way there should be no key clashes even if the executable is re-started. */ nn_random_generate (&self->surveyid, sizeof (self->surveyid)); self->deadline = NN_SURVEYOR_DEFAULT_DEADLINE; nn_timer_init (&self->deadline_timer, &self->sink, nn_sockbase_getcp (&self->xsurveyor.sockbase)); return 0; }