diff --git a/xwords4/linux/linuxmain.c b/xwords4/linux/linuxmain.c index 5beb24bdc..1cb6e491d 100644 --- a/xwords4/linux/linuxmain.c +++ b/xwords4/linux/linuxmain.c @@ -806,6 +806,7 @@ typedef enum { ,CMD_SMSTEST ,CMD_REMATCH_ON_OVER ,CMD_STATUS_SOCKET_NAME + ,CMD_CMDS_SOCKET_NAME ,N_CMDS } XwLinuxCmd; @@ -969,8 +970,8 @@ static CmdInfoRec CmdInfoRecs[] = { ,{ CMD_REMATCH_ON_OVER, false, "rematch-when-done", "Rematch games if they end" } ,{ CMD_STATUS_SOCKET_NAME, true, "status-socket-name", - "Unix domain socket to which to write status" } - + "Unix domain socket to which to write status" }, + { CMD_CMDS_SOCKET_NAME, true, "cmd-socket-name", "Unix domain socket on which to listen for commands"}, }; static struct option* @@ -2553,6 +2554,43 @@ writeStatus( const char* statusSocket, const char* dbName ) } } +static gboolean +handle_gotcmd( GIOChannel* source, GIOCondition condition, + gpointer XP_UNUSED(data) ) +{ + // XP_LOGFF( "got something!!" ); + gboolean keep = TRUE; + + if ( 0 != (G_IO_IN & condition) ) { + int sock = g_io_channel_unix_get_fd( source ); + char buf[1024]; + ssize_t nread = read( sock, buf, sizeof(buf) ); + buf[nread] = '\0'; + XP_LOGFF( "read: %s", buf ); + } + + if ( 0 != ((G_IO_HUP) & condition) ) { + XP_LOGFF( "got G_IO_HUP; returning FALSE" ); + keep = FALSE; + } else if ( 0 != ((G_IO_ERR) & condition) ) { + XP_LOGFF( "got G_IO_ERR; returning FALSE" ); + } else if ( 0 != ((G_IO_NVAL) & condition) ) { + XP_LOGFF( "got G_IO_NVAL; returning FALSE" ); + } else { + XP_LOGFF( "something else: 0x%X", condition ); + } + return keep; +} + +static void +addCmdListener( LaunchParams* params ) +{ + if ( !!params->cmdsSocket ) { + int fifo = open( params->cmdsSocket, O_RDWR | O_NONBLOCK ); + ADD_SOCKET( params, fifo, handle_gotcmd ); + } +} + int main( int argc, char** argv ) { @@ -3143,12 +3181,18 @@ main( int argc, char** argv ) statusSocket = optarg; break; + case CMD_CMDS_SOCKET_NAME: + mainParams.cmdsSocket = optarg; + break; + default: done = true; break; } } + addCmdListener( &mainParams ); + /* add cur dir if dict search dir path is empty */ if ( !mainParams.dictDirs ) { mainParams.dictDirs = g_slist_append( mainParams.dictDirs, "./" ); diff --git a/xwords4/linux/main.h b/xwords4/linux/main.h index 1246e5a82..ec86feddf 100644 --- a/xwords4/linux/main.h +++ b/xwords4/linux/main.h @@ -79,6 +79,8 @@ typedef struct _LaunchParams { XP_Bool noAnonDevid; XP_UCHAR devIDStore[32]; #endif + const char* cmdsSocket; + VTableMgr* vtMgr; DictMgrCtxt* dictMgr; XW_DUtilCtxt* dutil; diff --git a/xwords4/linux/scripts/manygames.py b/xwords4/linux/scripts/manygames.py new file mode 100755 index 000000000..7645214f1 --- /dev/null +++ b/xwords4/linux/scripts/manygames.py @@ -0,0 +1,28 @@ +#!/usr/bin/python3 + +import os, subprocess, time + +gFIFO_NAME = '/tmp/fifo' + +def main(): + os.mkfifo(gFIFO_NAME) + # mkfifo + + # launch app in background + args = ['./obj_linux_memdbg/xwords', '--cmd-socket-name', gFIFO_NAME ] + subprocess.Popen(args, stdout = subprocess.DEVNULL) + + # Loop writing to fifo + for ii in range(5): + time.sleep(2) + print('calling open') + fifo_out = open( gFIFO_NAME, 'w' ) + print('open DONE') + fifo_out.write( 'message {}'.format(ii) ) + fifo_out.close() + + # Kill app + +############################################################################## +if __name__ == '__main__': + main()