|
From: creedon <icr...@us...> - 2006-01-29 19:54:05
|
Update of /cvsroot/frontierkernel/Frontier/Common/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27608 Modified Files: CallMachOFrameWork.c Log Message: fread now reads in non-blocking mode, no error checking Index: CallMachOFrameWork.c =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/source/CallMachOFrameWork.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** CallMachOFrameWork.c 15 Jan 2005 16:43:10 -0000 1.7 --- CallMachOFrameWork.c 29 Jan 2006 19:53:53 -0000 1.8 *************** *** 28,45 **** #include "frontier.h" #include "standard.h" #include "CallMachOFrameWork.h" #include "memory.h" ! /*System.framework functions: popen, pclose, and fread.*/ typedef FILE* (*popenptr) (const char* command, const char *type); typedef int (*pcloseptr) (FILE* f); typedef size_t (*freadptr) (void *ptr, size_t size, size_t nobj, FILE* f); ! static popenptr popenfunc; static pcloseptr pclosefunc; static freadptr freadfunc; static boolean unixshellcallinited = false; --- 28,55 ---- #include "frontier.h" #include "standard.h" + #include "threads.h" + #include "shell.h" + #include "lang.h" #include "CallMachOFrameWork.h" #include "memory.h" + #include "fcntl.h" /* 2006-01-10 creedon */ ! /*System.framework functions: popen, pclose, fread, fcntl, feof, and fileno.*/ typedef FILE* (*popenptr) (const char* command, const char *type); typedef int (*pcloseptr) (FILE* f); typedef size_t (*freadptr) (void *ptr, size_t size, size_t nobj, FILE* f); ! typedef int (*fcntlptr) (int fd, int cmd, int arg); /* 2006-01-10 creedon */ ! typedef int (*feofptr) (FILE *f); /* 2006-01-10 creedon */ ! typedef int (*filenoptr) (FILE *f); /* 2006-01-10 creedon */ ! static popenptr popenfunc; static pcloseptr pclosefunc; static freadptr freadfunc; + static fcntlptr fcntlfunc; /* 2006-01-10 creedon */ + static feofptr feoffunc; /* 2006-01-10 creedon */ + static filenoptr filenofunc; /* 2006-01-10 creedon */ static boolean unixshellcallinited = false; *************** *** 47,51 **** ! static boolean unixshellcallinit (void); /* forward declaration */ --- 57,63 ---- ! /* prototypes */ ! static boolean unixshellcallinit (void); ! static boolean unixshellcallbackgroundtask (void); *************** *** 53,66 **** /* ! 7.0b51: Call the UNIX popen command, which evaluates a string as if it were typed ! on the command line. Verb: sys.unixShellCommand. ! Code adapted by Timothy Paustian from Apple sample code. ! This routine by PBS. */ FILE *f; ! char buf [256]; long ct = 0; ! if (!unixshellcallinit ()) return (false); --- 65,85 ---- /* ! 2006-01-10 creedon: laid down the groundwork for a timeoutsecs parameter, what is a good default? longinfinity? several minutes? I know that some commands I've done have taken 15 - 30 minutes ! fread now reads in non-blocking mode, no error checking ! ! 2005-10-02 creedon: changed buf size from 256 to 32, makes envrionment more responsive ! added call to new unixshellcallbackgroundtask function so kernel doesn't lock up while waiting for a lot of data to be read ! ! 7.0b51: Call the UNIX popen command, which evaluates a string as if it were typed on the command line. Verb: sys.unixShellCommand. ! Code adapted by Timothy Paustian from Apple sample code. ! This routine by PBS. */ FILE *f; ! char buf [32]; long ct = 0; ! // unsigned long timeoutsecs = 60 * 5; ! // long timeoutticks = gettickcount () + (timeoutsecs * 60); ! if (!unixshellcallinit ()) return (false); *************** *** 75,88 **** unlockhandle (hcommand); while (true) { ct = freadfunc (buf, 1, sizeof buf, f); /*fread*/ ! if (ct > 0) if (!insertinhandle (hreturn, gethandlesize (hreturn), buf, ct)) break; ! if (ct < sizeof (buf)) break; } /*while*/ --- 94,120 ---- unlockhandle (hcommand); + fcntlfunc (filenofunc (f), F_SETFL, fcntlfunc (filenofunc (f), F_GETFL, 0) | O_NONBLOCK); + while (true) { ct = freadfunc (buf, 1, sizeof buf, f); /*fread*/ ! if (ct > 0) // { ! if (!insertinhandle (hreturn, gethandlesize (hreturn), buf, ct)) break; + + // timeoutticks = gettickcount () + (timeoutsecs * 60); + // } ! if (feoffunc (f)) break; + + /* if (gettickcount () > timeoutticks) + break; */ + + if (!unixshellcallbackgroundtask ()) + break; + } /*while*/ *************** *** 96,99 **** --- 128,133 ---- /* + 2006-01-10 creedon: added fcntlfunc, feoffunc and filenofunc + 7.0b51 PBS: load the bundle and get the function pointers the first time called. */ *************** *** 121,124 **** --- 155,173 ---- return (false); + fcntlfunc = (fcntlptr) CFBundleGetFunctionPointerForName (sysBundle, CFSTR ("fcntl")); + + if (fcntlfunc == nil) + return (false); + + feoffunc = (feofptr) CFBundleGetFunctionPointerForName (sysBundle, CFSTR ("feof")); + + if (feoffunc == nil) + return (false); + + filenofunc = (filenoptr) CFBundleGetFunctionPointerForName (sysBundle, CFSTR ("fileno")); + + if (filenofunc == nil) + return (false); + unixshellcallinited = true; *************** *** 266,267 **** --- 315,339 ---- } /*disposecfmfuncptr*/ + + static boolean unixshellcallbackgroundtask (void) { + + /* + 2005-10-02 creedon: created, cribbed from OpenTransportNetEvents.c: fwsbackgroundtask + */ + + boolean fl = true; + + if (inmainthread ()) { + EventRecord ev; + short mask = osMask|activMask|mDownMask|keyDownMask; //|highLevelEventMask|updateMask + long sleepTime = 6; // 1/10 of a second by default + + if (WaitNextEvent (mask, &ev, sleepTime, nil)) /* might return false to indicate a null event, but that's not an error */ + fl = shellprocessevent (&ev); + } + else + fl = langbackgroundtask (true); + + return (fl); + }/* unixshellcallbackgroundtask */ + |