Permalink
Browse files

• when launching a task, write data to the input file handle in a bac…

…kground thread, as writeData: will block if we are writing more than 4 KB

git-svn-id: http://svn.textmate.org/trunk/Tools/CommitWindowProject@5856 dfb7d73b-c2ec-0310-8fea-fb051d288c6d
  • Loading branch information...
1 parent 5200154 commit 3533b4f6ae7d4440c4ce66d34a699a966dc58304 @sorbits sorbits committed Nov 1, 2006
Showing with 21 additions and 2 deletions.
  1. +21 −2 NSTask+CXAdditions.m
View
@@ -32,6 +32,22 @@ - (NSData *) reallyReadDataToEndOfFile
@implementation NSTask (CXAdditions)
+// helper method called in its own thread and writes data to a file descriptor
++ (void)writeDataToFileHandleAndClose:(id)someArguments
+{
+ NSAutoreleasePool* pool = [NSAutoreleasePool new];
+ NSFileHandle * fh = [someArguments objectForKey:@"fileHandle"];
+ NSData * data = [someArguments objectForKey:@"data"];
+
+ if( fh != nil && data != nil )
+ {
+ [fh writeData:data];
+ [fh closeFile];
+ }
+
+ [pool release];
+}
+
// Return a task (not yet launched) and optionally allocate stdout/stdin/stderr streams for communication with it
+ (NSTask *) taskWithArguments:(NSArray *)args
input:(NSFileHandle **)outWriteHandle
@@ -98,8 +114,11 @@ + (int) executeTaskWithArguments:(NSArray *)args
inputDataOrString = [inputDataOrString dataUsingEncoding:NSUTF8StringEncoding];
}
- [inputFile writeData:inputDataOrString];
- [inputFile closeFile];
+ NSDictionary* arguments = [NSDictionary dictionaryWithObjectsAndKeys:
+ inputFile, @"fileHandle",
+ inputDataOrString, @"data",
+ nil];
+ [NSThread detachNewThreadSelector:@selector(writeDataToFileHandleAndClose:) toTarget:self withObject:arguments];
}
[task launch];

0 comments on commit 3533b4f

Please sign in to comment.