mirror of
https://github.com/ksherlock/TwoTerm.git
synced 2025-02-01 12:30:16 +00:00
remove ChildMonitor
git-svn-id: svn://qnap.local/TwoTerm/branches/gcd_dispatch@3107 5590a31f-7b70-45f8-8c82-aa3a8e5f4507
This commit is contained in:
parent
d35fc38d6d
commit
5ef9d70940
@ -41,7 +41,6 @@
|
||||
B61EF7D71482FB6D008C1891 /* titlebar-center.png in Resources */ = {isa = PBXBuildFile; fileRef = B61EF7D41482FB6D008C1891 /* titlebar-center.png */; };
|
||||
B61EF7D81482FB6D008C1891 /* titlebar-left.png in Resources */ = {isa = PBXBuildFile; fileRef = B61EF7D51482FB6D008C1891 /* titlebar-left.png */; };
|
||||
B61EF7D91482FB6D008C1891 /* titlebar-right.png in Resources */ = {isa = PBXBuildFile; fileRef = B61EF7D61482FB6D008C1891 /* titlebar-right.png */; };
|
||||
B627333B12E3FF5B00A14C94 /* ChildMonitor.m in Sources */ = {isa = PBXBuildFile; fileRef = B627333A12E3FF5B00A14C94 /* ChildMonitor.m */; };
|
||||
B638188214A179D60027D007 /* ColorView.m in Sources */ = {isa = PBXBuildFile; fileRef = B638188114A179D60027D007 /* ColorView.m */; };
|
||||
B66412391480A070003BC8D3 /* EmulatorWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = B66412381480A070003BC8D3 /* EmulatorWindow.m */; };
|
||||
B676063B11DEAD3500D6B66C /* TermWindowController.mm in Sources */ = {isa = PBXBuildFile; fileRef = B676063A11DEAD3500D6B66C /* TermWindowController.mm */; };
|
||||
@ -139,8 +138,6 @@
|
||||
B61EF7D41482FB6D008C1891 /* titlebar-center.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "titlebar-center.png"; sourceTree = "<group>"; };
|
||||
B61EF7D51482FB6D008C1891 /* titlebar-left.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "titlebar-left.png"; sourceTree = "<group>"; };
|
||||
B61EF7D61482FB6D008C1891 /* titlebar-right.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "titlebar-right.png"; sourceTree = "<group>"; };
|
||||
B627333912E3FF5B00A14C94 /* ChildMonitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChildMonitor.h; sourceTree = "<group>"; };
|
||||
B627333A12E3FF5B00A14C94 /* ChildMonitor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ChildMonitor.m; sourceTree = "<group>"; };
|
||||
B638188014A179D60027D007 /* ColorView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ColorView.h; sourceTree = "<group>"; };
|
||||
B638188114A179D60027D007 /* ColorView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ColorView.m; sourceTree = "<group>"; };
|
||||
B66412371480A070003BC8D3 /* EmulatorWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EmulatorWindow.h; sourceTree = "<group>"; };
|
||||
@ -176,8 +173,6 @@
|
||||
080E96DDFE201D6D7F000001 /* Classes */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
B627333912E3FF5B00A14C94 /* ChildMonitor.h */,
|
||||
B627333A12E3FF5B00A14C94 /* ChildMonitor.m */,
|
||||
B61D0D5E125B7ACA001C713B /* NewTerminalWindowController.h */,
|
||||
B61D0D5F125B7ACA001C713B /* NewTerminalWindowController.m */,
|
||||
256AC3D80F4B6AC300CF3369 /* TwoTermAppDelegate.h */,
|
||||
@ -448,7 +443,6 @@
|
||||
B612F47112DD5E02005D1B77 /* EmulatorView.mm in Sources */,
|
||||
B612F47412DDEBA9005D1B77 /* Screen_obsolete.cpp in Sources */,
|
||||
B612F47512DDEBA9005D1B77 /* Screen_TextPort.cpp in Sources */,
|
||||
B627333B12E3FF5B00A14C94 /* ChildMonitor.m in Sources */,
|
||||
B68E632A12FF909D00EAFF5F /* ExampleView.m in Sources */,
|
||||
B66412391480A070003BC8D3 /* EmulatorWindow.m in Sources */,
|
||||
B612870E1480B4F6002E04DF /* TermContentView.m in Sources */,
|
||||
|
@ -1,44 +0,0 @@
|
||||
//
|
||||
// ChildMonitor.h
|
||||
// 2Term
|
||||
//
|
||||
// Created by Kelvin Sherlock on 1/16/2011.
|
||||
// Copyright 2011 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
/*
|
||||
* An NSThread to monitor a pid and fd.
|
||||
* requires 10.5+
|
||||
*
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class ChildMonitor;
|
||||
|
||||
@protocol ChildMonitorDelegate
|
||||
|
||||
-(void)childDataAvailable: (ChildMonitor *)monitor;
|
||||
-(void)childFinished: (ChildMonitor *)monitor;
|
||||
|
||||
@end
|
||||
|
||||
@interface ChildMonitor : NSThread {
|
||||
|
||||
pid_t _childPID;
|
||||
int _fd;
|
||||
int _childStatus;
|
||||
BOOL _childFinished;
|
||||
|
||||
id<ChildMonitorDelegate> _delegate;
|
||||
|
||||
}
|
||||
|
||||
@property (assign) BOOL childFinished;
|
||||
@property (assign) int childStatus;
|
||||
@property (nonatomic, assign) pid_t childPID;
|
||||
@property (nonatomic, assign) int fd;
|
||||
|
||||
@property (nonatomic, assign) id<ChildMonitorDelegate> delegate;
|
||||
|
||||
@end
|
102
ChildMonitor.m
102
ChildMonitor.m
@ -1,102 +0,0 @@
|
||||
//
|
||||
// ChildMonitor.m
|
||||
// 2Term
|
||||
//
|
||||
// Created by Kelvin Sherlock on 1/16/2011.
|
||||
// Copyright 2011 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ChildMonitor.h"
|
||||
|
||||
#include <sys/wait.h>
|
||||
#include <sys/select.h>
|
||||
#include <signal.h>
|
||||
|
||||
@implementation ChildMonitor
|
||||
|
||||
@synthesize childFinished = _childFinished;
|
||||
@synthesize childStatus = _childStatus;
|
||||
@synthesize childPID = _childPID;
|
||||
@synthesize fd = _fd;
|
||||
@synthesize delegate = _delegate;
|
||||
|
||||
-(BOOL)wait
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
if (waitpid(_childPID, &status, WNOHANG) == _childPID)
|
||||
{
|
||||
[self setChildStatus: status];
|
||||
[self setChildFinished: YES];
|
||||
|
||||
[(NSObject *)_delegate performSelectorOnMainThread: @selector(childFinished:)
|
||||
withObject: self
|
||||
waitUntilDone: NO];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
-(void)main
|
||||
{
|
||||
int fd = _fd;
|
||||
|
||||
// poll(2) does not work for ptys.
|
||||
// todo -- check if kqueue works with ptys
|
||||
// kqueue can also monitor the child process.
|
||||
|
||||
|
||||
for(;;)
|
||||
{
|
||||
int n;
|
||||
|
||||
struct timeval tm;
|
||||
|
||||
fd_set read_set;
|
||||
fd_set error_set;
|
||||
|
||||
|
||||
if ([self isCancelled]) break;
|
||||
|
||||
|
||||
FD_ZERO(&read_set);
|
||||
FD_SET(fd, &read_set);
|
||||
FD_ZERO(&error_set);
|
||||
FD_SET(fd, &error_set);
|
||||
|
||||
// 10 second timeout...
|
||||
tm.tv_sec = 10;
|
||||
tm.tv_usec = 0;
|
||||
|
||||
errno = 0;
|
||||
n = select(fd + 1, &read_set, NULL, &error_set, &tm);
|
||||
|
||||
//NSLog(@"select: %d %d", n, errno);
|
||||
if (n == 0) continue;
|
||||
if (n < 0) break;
|
||||
|
||||
if (FD_ISSET(fd, &error_set)) break;
|
||||
// ?
|
||||
|
||||
if (FD_ISSET(fd, &read_set))
|
||||
{
|
||||
[_delegate childDataAvailable: self];
|
||||
}
|
||||
|
||||
if ([self wait]) break;
|
||||
|
||||
}
|
||||
|
||||
if (!_childFinished) [self wait];
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc {
|
||||
|
||||
if (!_childFinished) kill(_childPID, 9);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
@ -10,9 +10,6 @@
|
||||
#import "EmulatorView.h"
|
||||
#import "CurveView.h"
|
||||
|
||||
#import "ChildMonitor.h"
|
||||
|
||||
|
||||
#import "VT52.h"
|
||||
#import "PTSE.h"
|
||||
|
||||
@ -203,7 +200,7 @@
|
||||
dispatch_source_set_event_handler(_wait_source, ^{
|
||||
|
||||
int status = 0;
|
||||
int ok = waitpid(pid, &status, WNOHANG);
|
||||
waitpid(pid, &status, WNOHANG);
|
||||
|
||||
_pid = 0;
|
||||
//dispatch_async(dispatch_get_main_queue(), ^(){
|
||||
|
@ -9,7 +9,6 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include "Emulator.h"
|
||||
#include "ChildMonitor.h"
|
||||
|
||||
#include "iGeometry.h"
|
||||
|
||||
|
@ -133,6 +133,10 @@
|
||||
#pragma mark -
|
||||
#pragma mark properties
|
||||
|
||||
-(int)fd {
|
||||
return _fd;
|
||||
}
|
||||
|
||||
-(void)setFd: (int)fd
|
||||
{
|
||||
_fd = fd;
|
||||
|
Loading…
x
Reference in New Issue
Block a user