示例#1
0
m2session* m2task_advertise(advert_tmpl* adv_tmpl, session_tmpl* s_tmpl, ot_app applet) {
/// This is a more complicated process than the others, because it actually 
/// creates two sessions: one for the flood and one for the request.
#   define _FLOOD_NETSTATE  (M2_NETFLAG_BG | M2_NETFLAG_STREAM | M2_NETSTATE_INIT | M2_NETSTATE_REQTX)
    m2session* next;
    
    /// Make sure there are at least two free sessions
    if (session_numfree() < 2) {
        return NULL;
    }

    /// Apply session flags
    sub_apply_subnet_flags(s_tmpl);
    
    /// Only add the flood if the user isn't an idiot (or an algorithm of some sort)
    if (adv_tmpl->duration != 0) {
        next        = session_new(&dll_default_applet, 0, adv_tmpl->channel, _FLOOD_NETSTATE);
        next->subnet= s_tmpl->subnet;
        next->flags = s_tmpl->flags;
    }
    
    next        = session_new(applet, adv_tmpl->duration, s_tmpl->channel, M2_NETSTATE_REQTX);
    next->subnet= s_tmpl->subnet;
    next->flags = s_tmpl->flags;
    
    return next;
    
#   undef _FLOOD_NETSTATE
}
示例#2
0
m2session* sub_newtask(session_tmpl* s_tmpl, ot_app applet, ot_u16 offset) {
    m2session* next;
    
    /// Make sure there is a free session... it is easiest this way
    if (session_numfree() < 1) {
        return NULL;
    }
    
    /// Create new session (session always begins with req tx)
    next = session_new(applet, offset, s_tmpl->channel, (M2_NETSTATE_INIT | M2_NETSTATE_REQTX));
    sub_apply_subnet_flags(s_tmpl);
    next->subnet    = s_tmpl->subnet;
    next->flags     = s_tmpl->flags;

    return next;
}
示例#3
0
OT_WEAK ot_u16 otapi_flush_sessions() {
    session_flush();
    return session_numfree();
}