khan: io driver skeleton

This commit is contained in:
Jōshin 2021-03-30 01:30:42 +00:00
parent 0102bb271f
commit f2df8b83d5
4 changed files with 106 additions and 0 deletions

View File

@ -601,6 +601,8 @@
# define c3__jet c3_s3('j','e','t')
# define c3__jetd c3_s4('j','e','t','d')
# define c3__just c3_s4('j','u','s','t')
# define c3__k c3_s1('k')
# define c3__khan c3_s4('k','h','a','n')
# define c3__keep c3_s4('k','e','e','p')
# define c3__kern c3_s4('k','e','r','n')
# define c3__kgo c3_s3('k','g','o')

View File

@ -1199,6 +1199,13 @@
u3_auto*
u3_cttp_io_init(u3_pier* pir_u);
/** Control plane.
**/
/* u3_khan_io_init(): initialize control plane I/O.
*/
u3_auto*
u3_khan_io_init(u3_pier* pir_u);
/** fore, first events
**/
/* u3_hind_io_init(): initialize fore

View File

@ -408,6 +408,7 @@ u3_auto_init(u3_pier* pir_u)
car_u = _auto_link(u3_hind_io_init(pir_u), pir_u, car_u);
car_u = _auto_link(u3_behn_io_init(pir_u), pir_u, car_u);
car_u = _auto_link(u3_khan_io_init(pir_u), pir_u, car_u);
car_u = _auto_link(u3_ames_io_init(pir_u), pir_u, car_u);
car_u = _auto_link(u3_http_io_init(pir_u), pir_u, car_u);
car_u = _auto_link(u3_cttp_io_init(pir_u), pir_u, car_u);

96
pkg/urbit/vere/io/khan.c Normal file
View File

@ -0,0 +1,96 @@
/* vere/khan.c
**
*/
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <dirent.h>
#include <uv.h>
#include <errno.h>
#include "all.h"
#include "vere/vere.h"
/* u3_khan: control plane socket
*/
typedef struct _u3_khan {
u3_auto car_u; // driver
c3_l sev_l; // instance number
} u3_khan;
/* _khan_io_talk(): notify %khan that we're live
*/
static void
_khan_io_talk(u3_auto* car_u)
{
u3_khan* cop_u = (u3_khan*)car_u;
u3_noun wir = u3nt(c3__khan,
u3dc("scot", c3__uv, cop_u->sev_l),
u3_nul);
u3_noun cad = u3nc(c3__born, u3_nul);
u3_auto_plan(car_u, u3_ovum_init(0, c3__k, wir, cad));
}
/* _khan_io_kick(): apply effects.
*/
static c3_o
_khan_io_kick(u3_auto* car_u, u3_noun wir, u3_noun cad)
{
u3_khan* cop_u = (u3_khan*)car_u;
u3_noun tag, dat, i_wir;
c3_o ret_o;
if ( (c3n == u3r_cell(wir, &i_wir, 0))
|| (c3n == u3r_cell(cad, &tag, &dat))
|| (c3__khan != i_wir) )
{
ret_o = c3n;
}
else {
ret_o = c3y;
// TODO do something
}
u3z(wir); u3z(cad);
return ret_o;
}
/* _khan_io_exit(): close socket.
*/
static void
_khan_io_exit(u3_auto* car_u)
{
u3_khan* cop_u = (u3_khan*)car_u;
// TODO close socket
}
/* u3_khan(): initialize control plane socket.
*/
u3_auto*
u3_khan_io_init(u3_pier* pir_u)
{
u3_khan* cop_u = c3_calloc(sizeof(*cop_u));
u3_auto* car_u = &cop_u->car_u;
car_u->nam_m = c3__khan;
car_u->io.talk_f = _khan_io_talk;
car_u->io.kick_f = _khan_io_kick;
car_u->io.exit_f = _khan_io_exit;
// TODO open socket
{
u3_noun now;
struct timeval tim_u;
gettimeofday(&tim_u, 0);
now = u3_time_in_tv(&tim_u);
cop_u->sev_l = u3r_mug(now);
u3z(now);
}
return car_u;
}