diff --git a/Makefile b/Makefile index 7a52d5c082..3bb1aab675 100644 --- a/Makefile +++ b/Makefile @@ -263,6 +263,7 @@ V_OFILES=\ v/raft.o \ v/reck.o \ v/sist.o \ + v/temp.o \ v/term.o \ v/time.o \ v/unix.o \ diff --git a/include/c/motes.h b/include/c/motes.h index b0a7cb8311..e8c6785c04 100644 --- a/include/c/motes.h +++ b/include/c/motes.h @@ -1001,6 +1001,7 @@ # define c3__teal c3_s4('t','e','a','l') # define c3__teck c3_s4('t','e','c','k') # define c3__tell c3_s4('t','e','l','l') +# define c3__temp c3_s4('t','e','m','p') # define c3__terg c3_s4('t','e','r','g') # define c3__term c3_s4('t','e','r','m') # define c3__test c3_s4('t','e','s','t') @@ -1008,6 +1009,7 @@ # define c3__this c3_s4('t','h','i','s') # define c3__thin c3_s4('t','h','i','n') # define c3__thud c3_s4('t','h','u','d') +# define c3__time c3_s4('t','i','m','e') # define c3__tgbn c3_s4('t','g','b','n') # define c3__tgbr c3_s4('t','g','b','r') # define c3__tgdg c3_s4('t','g','d','g') diff --git a/include/v/vere.h b/include/v/vere.h index 267b222b37..23a44d29b2 100644 --- a/include/v/vere.h +++ b/include/v/vere.h @@ -349,9 +349,7 @@ /* u3_unix: clay support system, also */ typedef struct _u3_unix { - uv_timer_t tim_u; // clay timer uv_check_t syn_u; // fs sync check - u3_bean alm; // alarm u3_uhot* hot_u; // host state u3_usig* sig_u; // signal list #ifdef SYNCLOG @@ -368,12 +366,20 @@ /* u3_batz: just a timer for now */ typedef struct _u3_batz { - uv_timer_t tim_u; // clay timer + uv_timer_t tim_u; // batz timer c3_w run_w; // run of consecutive alarms u3_bean alm; // alarm } u3_batz; - /* u3_utfo: unix terminfo strings. + /* u3_temp: just a timer for ever + */ + typedef struct _u3_temp { + uv_timer_t tim_u; // temp timer + c3_w run_w; // run of consecutive alarms + u3_bean alm; // alarm + } u3_temp; + + /* u2_utfo: unix terminfo strings. */ typedef struct { struct { @@ -552,6 +558,7 @@ u3_opts ops_u; // commandline options u3_unix unx_u; // sync and clay u3_batz beh_u; // batz timer + u3_temp teh_u; // temp timer u3_bean liv; // if u3_no, shut down c3_i xit_i; // exit code for shutdown void* ssl_u; // struct SSL_CTX* @@ -974,6 +981,24 @@ u3_batz_io_poll(void); + /** Temp, just a timer. + **/ + /* u2_temp_io_init(): initialize temp timer. + */ + void + u2_temp_io_init(void); + + /* u2_temp_io_exit(): terminate timer. + */ + void + u2_temp_io_exit(void); + + /* u2_temp_io_poll(): update temp IO state. + */ + void + u2_temp_io_poll(void); + + /** HTTP server. **/ /* u3_http_ef_thou(): send %thou effect to http. @@ -1098,6 +1123,23 @@ void u3_sist_get(const c3_c* key_c, c3_y* val_y); + /** New timer system. + **/ + /* u3_temp_io_init(): initialize time timer. + */ + void + u3_temp_io_init(void); + + /* u3_temp_io_exit(): terminate timer. + */ + void + u3_temp_io_exit(void); + + /* u3_temp_io_poll(): update temp IO state. + */ + void + u3_temp_io_poll(void); + /** HTTP client. **/ diff --git a/v/loop.c b/v/loop.c index 2449c4be25..b4d032cac0 100644 --- a/v/loop.c +++ b/v/loop.c @@ -174,6 +174,7 @@ _lo_init() u3_cttp_io_init(); u3_save_io_init(); u3_batz_io_init(); + u3_temp_io_init(); } /* _lo_talk(): bring up listeners across the process. @@ -199,6 +200,7 @@ u3_lo_exit(void) u3_cttp_io_exit(); u3_save_io_exit(); u3_batz_io_exit(); + u3_temp_io_exit(); } /* _lo_poll(): reset event flags across the process. @@ -212,6 +214,7 @@ _lo_poll(void) u3_save_io_poll(); u3_unix_io_poll(); u3_batz_io_poll(); + u3_temp_io_poll(); } #if 0 @@ -225,6 +228,7 @@ _lo_how(u3_noun how) case c3__ames: return "ames"; case c3__batz: return "batz"; + case c3__temp: return "temp"; case c3__term: return "cons"; case c3__htcn: return "http-conn"; case c3__htls: return "http-lisn"; diff --git a/v/raft.c b/v/raft.c index 538a17baca..9d07ac88e3 100644 --- a/v/raft.c +++ b/v/raft.c @@ -1562,6 +1562,7 @@ _raft_punk(u3_noun ovo) // if ( c3__wake != u3h(u3t(ovo)) ) { u3_Host.beh_u.run_w = 0; + u3_Host.teh_u.run_w = 0; } #ifdef GHETTO diff --git a/v/temp.c b/v/temp.c new file mode 100644 index 0000000000..d6ad3222ba --- /dev/null +++ b/v/temp.c @@ -0,0 +1,91 @@ +/* v/temp.c +** +** This file is in the public domain. +*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "all.h" +#include "v/vere.h" + +/* u3_temp(): initialize time timer. +*/ +void +u3_temp_io_init(void) +{ + u3_temp* teh_u = &u3_Host.teh_u; + + uv_timer_init(u3L, &teh_u->tim_u); + teh_u->alm = u3_no; +} + +/* u3_temp_io_exit(): terminate timer. +*/ +void +u3_temp_io_exit(void) +{ +} + +/* _temp_time_cb(): timer callback. +*/ +static void +_temp_time_cb(uv_timer_t* tim_u) +{ + u3_temp* teh_u = &u3_Host.teh_u; + if(teh_u->run_w < 1024) { + teh_u->run_w++; + } + + u3_lo_open(); + { + u3_cv_plan + (u3nt(u3_blip, c3__temp, u3_nul), + u3nc(c3__wake, u3_nul)); + } + u3_lo_shut(u3_no); +} + +/* u3_temp_io_poll(): update temp IO state. +*/ +void +u3_temp_io_poll(void) +{ + u3_temp* teh_u = &u3_Host.teh_u; + u3_noun wen = u3_cv_keep(u3nt(u3_blip, c3__temp, u3_nul)); + + if ( (u3_nul != wen) && + (u3_yes == u3du(wen)) && + (u3_yes == u3ud(u3t(wen))) ) + { + c3_d gap_d = u3_time_gap_ms(u3k(u3A->now), u3k(u3t(wen))); + + gap_d += teh_u->run_w; + + if ( u3_yes == teh_u->alm ) { + uv_timer_stop(&teh_u->tim_u); + } + else teh_u->alm = u3_yes; + + uv_timer_start(&teh_u->tim_u, _temp_time_cb, gap_d, 0); + } + else { + if ( u3_yes == teh_u->alm ) { + uv_timer_stop(&teh_u->tim_u); + } + teh_u->alm = u3_no; + } + u3z(wen); +} diff --git a/v/unix.c b/v/unix.c index 857add6c8e..5923870a39 100644 --- a/v/unix.c +++ b/v/unix.c @@ -1427,20 +1427,6 @@ _unix_ef_sync(uv_check_t* han_u) u3_lo_shut(u3_yes); } -/* _unix_time_cb(): timer callback. -*/ -static void -_unix_time_cb(uv_timer_t* tim_u) -{ - u3_lo_open(); - { - u3_cv_plan - (u3nt(u3_blip, c3__clay, u3_nul), - u3nc(c3__wake, u3_nul)); - } - u3_lo_shut(u3_no); -} - /* _unix_sign_cb: signal callback. */ static void @@ -1499,9 +1485,6 @@ u3_unix_io_init(void) { u3_unix* unx_u = &u3_Host.unx_u; - uv_timer_init(u3L, &unx_u->tim_u); - unx_u->alm = u3_no; - { u3_usig* sig_u; @@ -1576,27 +1559,4 @@ u3_unix_io_exit(void) void u3_unix_io_poll(void) { - u3_unix* unx_u = &u3_Host.unx_u; - u3_noun wen = u3_cv_keep(u3nt(u3_blip, c3__clay, u3_nul)); - - if ( (u3_nul != wen) && - (u3_yes == u3du(wen)) && - (u3_yes == u3ud(u3t(wen))) ) - { - c3_d gap_d = u3_time_gap_ms(u3k(u3A->now), u3k(u3t(wen))); - - if ( u3_yes == unx_u->alm ) { - uv_timer_stop(&unx_u->tim_u); - } - else unx_u->alm = u3_yes; - - uv_timer_start(&unx_u->tim_u, _unix_time_cb, gap_d, 0); - } - else { - if ( u3_yes == unx_u->alm ) { - uv_timer_stop(&unx_u->tim_u); - } - unx_u->alm = u3_no; - } - u3z(wen); }