[quake3-commits] r1921 - in trunk: . code/qcommon code/sys
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Wed Mar 9 20:01:28 EST 2011
Author: thilo
Date: 2011-03-09 20:01:27 -0500 (Wed, 09 Mar 2011)
New Revision: 1921
Modified:
trunk/README
trunk/code/qcommon/common.c
trunk/code/qcommon/files.c
trunk/code/qcommon/qcommon.h
trunk/code/sys/sys_unix.c
trunk/code/sys/sys_win32.c
Log:
(#4925) - com_pipefile to create a named pipe for sending commands from other processes, patch by Chris Schwarz
Modified: trunk/README
===================================================================
--- trunk/README 2011-03-09 23:34:15 UTC (rev 1920)
+++ trunk/README 2011-03-10 01:01:27 UTC (rev 1921)
@@ -158,6 +158,10 @@
com_maxfpsMinimized - Maximum frames per second when minimized
com_busyWait - Will use a busy loop to wait for rendering
next frame when set to non-zero value
+ com_pipefile - Specify filename to create a named pipe
+ through which other processes can control
+ the server while it is running.
+ Nonfunctional on Windows.
in_joystickNo - select which joystick to use
in_availableJoysticks - list of available Joysticks
Modified: trunk/code/qcommon/common.c
===================================================================
--- trunk/code/qcommon/common.c 2011-03-09 23:34:15 UTC (rev 1920)
+++ trunk/code/qcommon/common.c 2011-03-10 01:01:27 UTC (rev 1921)
@@ -50,6 +50,7 @@
FILE *debuglogfile;
+static fileHandle_t pipefile;
static fileHandle_t logfile;
fileHandle_t com_journalFile; // events are written here
fileHandle_t com_journalDataFile; // config files are written here
@@ -66,6 +67,7 @@
cvar_t *com_sv_running;
cvar_t *com_cl_running;
cvar_t *com_logfile; // 1 = buffer log, 2 = flush after each print
+cvar_t *com_pipefile;
cvar_t *com_showtrace;
cvar_t *com_version;
cvar_t *com_blood;
@@ -2768,9 +2770,36 @@
Com_Printf ("Altivec support is %s\n", com_altivec->integer ? "enabled" : "disabled");
#endif
+ com_pipefile = Cvar_Get( "com_pipefile", "", CVAR_ARCHIVE|CVAR_LATCH );
+ if( com_pipefile->string[0] )
+ {
+ pipefile = FS_FCreateOpenPipeFile( com_pipefile->string );
+ }
+
Com_Printf ("--- Common Initialization Complete ---\n");
}
+/*
+===============
+Com_ReadFromPipe
+
+Read whatever is in com_pipefile, if anything, and execute it
+===============
+*/
+void Com_ReadFromPipe( void )
+{
+ char buffer[MAX_STRING_CHARS] = {""};
+ qboolean read;
+
+ if( !pipefile )
+ return;
+
+ read = FS_Read( buffer, sizeof( buffer ), pipefile );
+ if( read )
+ Cbuf_ExecuteText( EXEC_APPEND, buffer );
+}
+
+
//==================================================================
void Com_WriteConfigToFile( const char *filename ) {
@@ -3097,6 +3126,8 @@
c_pointcontents = 0;
}
+ Com_ReadFromPipe( );
+
com_frameNumber++;
}
@@ -3116,6 +3147,11 @@
com_journalFile = 0;
}
+ if( pipefile ) {
+ FS_FCloseFile( pipefile );
+ FS_HomeRemove( com_pipefile->string );
+ }
+
}
//------------------------------------------------------------------------
Modified: trunk/code/qcommon/files.c
===================================================================
--- trunk/code/qcommon/files.c 2011-03-09 23:34:15 UTC (rev 1920)
+++ trunk/code/qcommon/files.c 2011-03-10 01:01:27 UTC (rev 1921)
@@ -907,6 +907,50 @@
/*
===========
+FS_FCreateOpenPipeFile
+
+===========
+*/
+fileHandle_t FS_FCreateOpenPipeFile( const char *filename ) {
+ char *ospath;
+ FILE *fifo;
+ fileHandle_t f;
+
+ if ( !fs_searchpaths ) {
+ Com_Error( ERR_FATAL, "Filesystem call made without initialization\n" );
+ }
+
+ f = FS_HandleForFile();
+ fsh[f].zipFile = qfalse;
+
+ Q_strncpyz( fsh[f].name, filename, sizeof( fsh[f].name ) );
+
+ // don't let sound stutter
+ S_ClearSoundBuffer();
+
+ ospath = FS_BuildOSPath( fs_homepath->string, fs_gamedir, filename );
+
+ if ( fs_debug->integer ) {
+ Com_Printf( "FS_FCreateOpenPipeFile: %s\n", ospath );
+ }
+
+ FS_CheckFilenameIsNotExecutable( ospath, __func__ );
+
+ fifo = Sys_Mkfifo( ospath );
+ if( fifo ) {
+ fsh[f].handleFiles.file.o = fifo;
+ fsh[f].handleSync = qfalse;
+ }
+ else
+ {
+ f = 0;
+ }
+
+ return f;
+}
+
+/*
+===========
FS_FilenameCompare
Ignore case and seprator char distinctions
Modified: trunk/code/qcommon/qcommon.h
===================================================================
--- trunk/code/qcommon/qcommon.h 2011-03-09 23:34:15 UTC (rev 1920)
+++ trunk/code/qcommon/qcommon.h 2011-03-10 01:01:27 UTC (rev 1921)
@@ -626,6 +626,7 @@
fileHandle_t FS_FOpenFileWrite( const char *qpath );
fileHandle_t FS_FOpenFileAppend( const char *filename );
+fileHandle_t FS_FCreateOpenPipeFile( const char *filename );
// will properly create any needed paths and deal with seperater character issues
fileHandle_t FS_SV_FOpenFileWrite( const char *filename );
@@ -1094,6 +1095,7 @@
void Sys_ShowIP(void);
qboolean Sys_Mkdir( const char *path );
+FILE *Sys_Mkfifo( const char *ospath );
char *Sys_Cwd( void );
void Sys_SetDefaultInstallPath(const char *path);
char *Sys_DefaultInstallPath(void);
Modified: trunk/code/sys/sys_unix.c
===================================================================
--- trunk/code/sys/sys_unix.c 2011-03-09 23:34:15 UTC (rev 1920)
+++ trunk/code/sys/sys_unix.c 2011-03-10 01:01:27 UTC (rev 1921)
@@ -249,6 +249,31 @@
/*
==================
+Sys_Mkfifo
+==================
+*/
+FILE *Sys_Mkfifo( const char *ospath )
+{
+ FILE *fifo;
+ int result;
+ int fn;
+
+ result = mkfifo( ospath, 0600 );
+ if( result != 0 )
+ return NULL;
+
+ fifo = fopen( ospath, "w+" );
+ if( fifo )
+ {
+ fn = fileno( fifo );
+ fcntl( fn, F_SETFL, O_NONBLOCK );
+ }
+
+ return fifo;
+}
+
+/*
+==================
Sys_Cwd
==================
*/
Modified: trunk/code/sys/sys_win32.c
===================================================================
--- trunk/code/sys/sys_win32.c 2011-03-09 23:34:15 UTC (rev 1920)
+++ trunk/code/sys/sys_win32.c 2011-03-10 01:01:27 UTC (rev 1921)
@@ -321,6 +321,17 @@
}
/*
+==================
+Sys_Mkfifo
+Noop on windows because named pipes do not function the same way
+==================
+*/
+FILE *Sys_Mkfifo( const char *ospath )
+{
+ return NULL;
+}
+
+/*
==============
Sys_Cwd
==============
More information about the quake3-commits
mailing list