From b2db27dcadf76361b69346d288dd66be2a27a263 Mon Sep 17 00:00:00 2001 From: mccallum Date: Thu, 31 Oct 1996 17:55:35 +0000 Subject: [PATCH] Added test of RunLoop FD listening. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1891 72102866-910b-0410-8b05-ffd578937521 --- Examples/first-server.m | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/Examples/first-server.m b/Examples/first-server.m index aeff2f6cc..0fe778cd6 100644 --- a/Examples/first-server.m +++ b/Examples/first-server.m @@ -2,6 +2,43 @@ #include #include "first-server.h" #include +#include +#include + + +@interface MyIo: NSObject +{ + id runLoop; + id mode; + char c; +} +- initForRunLoop: r andMode: m; +- (void) readyForReadingOnFileDescriptor: (int)fd; +- (void) readyForWritingOnFileDescriptor: (int)fd; +@end + +@implementation MyIo +- initForRunLoop: r andMode: m +{ + runLoop = r; + mode = m; + return self; +} +- (void) readyForReadingOnFileDescriptor: (int)fd +{ + if (read(fd, &c, 1) == 1) { + [runLoop addWriteDescriptor: 1 object: self forMode: mode]; + [runLoop removeReadDescriptor: fd forMode: mode]; + } +} +- (void) readyForWritingOnFileDescriptor: (int)fd +{ + if (write(fd, &c, 1) == 1) { + [runLoop addReadDescriptor: 0 object: self forMode: mode]; + [runLoop removeWriteDescriptor: fd forMode: mode]; + } +} +@end @implementation FirstServer - sayHiTo: (char *)name @@ -14,6 +51,15 @@ int main() { id s, c; + MyIo* myIo; + NSString* m; + id r; + + r = [RunLoop currentInstance]; + m = [RunLoop currentMode]; + myIo = [[MyIo alloc] initForRunLoop: r andMode: m]; + + [r addReadDescriptor: 0 object: myIo forMode: m]; /* Create our server object */ s = [[FirstServer alloc] init];