Move funcs to correct pos

This commit is contained in:
jun7 2018-06-04 12:32:27 +09:00
parent b15991043e
commit dacdcc601d

View File

@ -159,23 +159,12 @@ static gpointer pingt(gpointer p)
g_main_loop_run(g_main_loop_new(ctx, true)); g_main_loop_run(g_main_loop_new(ctx, true));
return NULL; return NULL;
} }
static gboolean quitif(gpointer p)
{
DD(quitif)
static int cnt = 0;
if (cnt++ > 30 /*3 sec*/ || !g_hash_table_size(orders)) quit(NULL);
return true;
}
static void monitorcb(GFileMonitor *m, GFile *f, GFile *o, GFileMonitorEvent e,
gpointer p)
{
if (e != G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT) return;
g_timeout_add(100, quitif, NULL);
}
void wyebwatch(char *exe, char *caller, wyebdataf func) void wyebwatch(char *exe, char *caller, wyebdataf func)
{ {
svrexe = exe; svrexe = exe;
dataf = func; dataf = func;
orders = g_hash_table_new(g_str_hash, g_str_equal);
until(DUNTIL); until(DUNTIL);
g_thread_new("ping", pingt, NULL); g_thread_new("ping", pingt, NULL);
@ -185,6 +174,18 @@ void wyebwatch(char *exe, char *caller, wyebdataf func)
fatal(1); fatal(1);
} }
static gboolean quitif(gpointer p)
{
static int cnt = 0;
if (cnt++ > 30 /* 3 secs */ || !g_hash_table_size(orders)) quit(NULL);
return true;
}
static void monitorcb(GFileMonitor *m, GFile *f, GFile *o, GFileMonitorEvent e,
gpointer p)
{
if (e == G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT)
g_timeout_add(100, quitif, NULL);
}
static gboolean svrinit(char *caller) static gboolean svrinit(char *caller)
{ {
wyebwatch(svrexe, caller, dataf); wyebwatch(svrexe, caller, dataf);
@ -501,9 +502,6 @@ void wyebclient(char *exe)
//@ipccb //@ipccb
gboolean ipccb(GIOChannel *ch, GIOCondition c, gpointer p) gboolean ipccb(GIOChannel *ch, GIOCondition c, gpointer p)
{ {
if (!orders)
orders = g_hash_table_new(g_str_hash, g_str_equal);
char *line; char *line;
g_io_channel_read_line(ch, &line, NULL, NULL, NULL); g_io_channel_read_line(ch, &line, NULL, NULL, NULL);
if (!line) return true; if (!line) return true;
@ -529,6 +527,7 @@ gboolean ipccb(GIOChannel *ch, GIOCondition c, gpointer p)
until(lastuntil = atoi(arg)); until(lastuntil = atoi(arg));
break; break;
case CSdata: case CSdata:
g_hash_table_add(orders, id); g_hash_table_add(orders, id);
getdata(id, arg); getdata(id, arg);
g_hash_table_remove(orders, id); g_hash_table_remove(orders, id);