Hi,
I noticed the following kernel message in system log:
Nov 28 20:10:42 TK-MB kernel[0]: CommandDroplet[1993] uses send/
recv on a
pipe
CommandDroplet is the application that I develop as part of
OnMyCommand
which wraps Unix or AppleScript scripts with some GUI. I have been
experimenting with it recently trying to make popen execution non-
blocking.
The problem is with pipe caching (you cannot work it around) which
locks the
reading and you get stuck in in fread (or fgets). I wanted to
improve it but
nothing seemed to work until I created a CFSocket on the file
description
from the stream. It works beautifully as a CFRunLoop source -
providing a
data in callback and not blocking.
But the kernel message is a signal that there might be something
wrong with
it. See below for the code I used. When I #undef USE_CFSOCKET the
kernel
does not complain. I would really hate to go back to the previous
synchronous/blocking code.
Thanks,
Tom
http://www.abracode.com/free/cmworkshop/
bool
POpenExecutor::Execute( const char *inCommand )
{
if(inCommand == NULL)
return true;
FILE *fp = popen( inCommand, "r" );
if ( fp != NULL )
{
#ifdef USE_CFSOCKET
CFSocketContext context;
context.version = 0;
context.info = this;
context.retain = NULL;
context.release = NULL;
context.copyDescription = NULL;
int fileDesc = fileno(fp);
mFileDescSocket = ::CFSocketCreateWithNative(
kCFAllocatorDefault,
fileDesc, kCFSocketDataCallBack,
PopenCFSocketCallback,
&context);
if(mFileDescSocket != NULL)
{
mSource = ::CFSocketCreateRunLoopSource
(kCFAllocatorDefault,
mFileDescSocket, 0);
if(mSource != NULL)
::CFRunLoopAddSource( ::CFRunLoopGetCurrent(),
mSource,
kCFRunLoopDefaultMode );
}
return false; //not finished yet
#else //USE_CFSOCKET
static char oneLine[1024];
oneLine[0] = 0;
do
{
fgets (oneLine, sizeof(oneLine), fp);
}
while( feof(fp) == 0 );
(void) pclose( fp );
return true; //finished
#endif //USE_CFSOCKET
}
return true; //error condition. finished
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40apple.com
This email sent to email@hidden