1994-11-04 16:29:24 +00:00
|
|
|
|
1996-04-17 18:40:03 +00:00
|
|
|
#include <gnustep/base/Connection.h>
|
1994-11-04 16:29:24 +00:00
|
|
|
#include "first-server.h"
|
1997-01-12 19:28:07 +00:00
|
|
|
#include <Foundation/NSString.h>
|
1997-09-01 21:59:51 +00:00
|
|
|
#include <Foundation/NSRunLoop.h>
|
1996-10-31 17:55:35 +00:00
|
|
|
#include <sys/file.h>
|
|
|
|
|
|
|
|
|
|
|
|
@interface MyIo: NSObject <FdListening,FdSpeaking>
|
|
|
|
{
|
|
|
|
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
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
@implementation FirstServer
|
|
|
|
- sayHiTo: (char *)name
|
|
|
|
{
|
|
|
|
printf("Hello, %s.\n", name);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
id s, c;
|
1996-10-31 17:55:35 +00:00
|
|
|
MyIo* myIo;
|
|
|
|
NSString* m;
|
|
|
|
id r;
|
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
r = [NSRunLoop currentInstance];
|
|
|
|
m = [NSRunLoop currentMode];
|
1996-10-31 17:55:35 +00:00
|
|
|
myIo = [[MyIo alloc] initForRunLoop: r andMode: m];
|
|
|
|
|
|
|
|
[r addReadDescriptor: 0 object: myIo forMode: m];
|
1994-11-04 16:29:24 +00:00
|
|
|
|
|
|
|
/* Create our server object */
|
|
|
|
s = [[FirstServer alloc] init];
|
|
|
|
|
|
|
|
/* Register a connection that provides the server object to the network */
|
|
|
|
printf("Registering a connection for the server using name `firstserver'\n");
|
1995-03-23 03:58:37 +00:00
|
|
|
c = [Connection newRegisteringAtName:@"firstserver"
|
1994-11-04 16:29:24 +00:00
|
|
|
withRootObject:s];
|
|
|
|
|
|
|
|
/* Run the connection */
|
|
|
|
printf("Running the connection... (until you interrupt with control-C)\n");
|
|
|
|
[c runConnection]; /* This runs until interrupt. */
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|