mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
remove obsolete test code
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@27732 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
c22bfff738
commit
5239f962dc
85 changed files with 22 additions and 11242 deletions
152
Examples/diningPhilosophers.m
Normal file
152
Examples/diningPhilosophers.m
Normal file
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
diningPhilosophers.h
|
||||
|
||||
Five hungry philosophers testing locks and threads
|
||||
This program loops indefinitely.
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Scott Christley <scottc@net-community.com>
|
||||
Date: 1996
|
||||
|
||||
This file is part of the GNUstep Application Kit Library.
|
||||
|
||||
This file is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3 of the License, or (at your option) any later version.
|
||||
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public
|
||||
License along with this file; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/NSLock.h>
|
||||
#include <Foundation/NSThread.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
|
||||
// Conditions
|
||||
#define NO_FOOD 1
|
||||
#define FOOD_SERVED 2
|
||||
|
||||
// NSLocks ... umm I mean forks
|
||||
id forks[5];
|
||||
id fork_lock;
|
||||
|
||||
//
|
||||
// A class of hungry philosophers
|
||||
//
|
||||
@interface Philosopher : NSObject
|
||||
|
||||
{
|
||||
int chair;
|
||||
}
|
||||
|
||||
// Instance methods
|
||||
- (void)sitAtChair:(NSNumber*)position;
|
||||
- (int)chair;
|
||||
|
||||
@end
|
||||
|
||||
@implementation Philosopher
|
||||
|
||||
// Instance methods
|
||||
- (void)sitAtChair:(NSNumber*)position
|
||||
{
|
||||
int i;
|
||||
|
||||
// Sit down
|
||||
chair = [position intValue];
|
||||
|
||||
// Its a constant battle to feed yourself
|
||||
while (1)
|
||||
{
|
||||
|
||||
[fork_lock lockWhenCondition:FOOD_SERVED];
|
||||
|
||||
// Get the fork to our left
|
||||
[forks[chair] lockWhenCondition:FOOD_SERVED];
|
||||
|
||||
// Get the fork to our right
|
||||
[forks[(chair + 1) % 5] lockWhenCondition:FOOD_SERVED];
|
||||
|
||||
[fork_lock unlock];
|
||||
|
||||
// Start eating!
|
||||
printf("Philosopher %d can start eating.\n", chair); fflush(stdout);
|
||||
|
||||
for (i = 0;i < 100000; ++i)
|
||||
{
|
||||
if ((i % 10000) == 0)
|
||||
printf("Philosopher %d is eating.\n", chair); fflush(stdout);
|
||||
}
|
||||
|
||||
// Done eating
|
||||
printf("Philosopher %d is done eating.\n", chair); fflush(stdout);
|
||||
|
||||
// Drop the fork to our left
|
||||
[forks[chair] unlock];
|
||||
|
||||
// Drop the fork to our right
|
||||
[forks[(chair + 1) % 5] unlock];
|
||||
|
||||
// Wait until we are hungry again
|
||||
for (i = 0;i < 1000000 * (chair + 1); ++i) ;
|
||||
}
|
||||
|
||||
// We never get here, but this is what we should do
|
||||
[NSThread exit];
|
||||
}
|
||||
|
||||
- (int)chair
|
||||
{
|
||||
return chair;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
//
|
||||
// my main for the test app
|
||||
//
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
int i;
|
||||
id p[5];
|
||||
|
||||
// Create the locks
|
||||
for (i = 0;i < 5; ++i)
|
||||
{
|
||||
forks[i] = [[NSConditionLock alloc]
|
||||
initWithCondition:NO_FOOD];
|
||||
[forks[i] lock];
|
||||
}
|
||||
|
||||
fork_lock = [[NSConditionLock alloc]
|
||||
initWithCondition:NO_FOOD];
|
||||
[fork_lock lock];
|
||||
|
||||
// Create the philosophers
|
||||
for (i = 0;i < 5; ++i)
|
||||
p[i] = [[Philosopher alloc] init];
|
||||
|
||||
// Have them sit at the table
|
||||
for (i = 0;i < 5; ++i)
|
||||
[NSThread detachNewThreadSelector:@selector(sitAtChair:)
|
||||
toTarget:p[i] withObject: [NSNumber numberWithInt: i]];
|
||||
|
||||
// Now let them all eat
|
||||
[fork_lock unlockWithCondition:FOOD_SERVED];
|
||||
for (i = 0;i < 5; ++i)
|
||||
[forks[i] unlockWithCondition:FOOD_SERVED];
|
||||
|
||||
while (1);
|
||||
[arp release];
|
||||
}
|
||||
|
110
Examples/nsconnection.m
Normal file
110
Examples/nsconnection.m
Normal file
|
@ -0,0 +1,110 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#define STRICT_OPENSTEP 1
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
id myServer;
|
||||
|
||||
@interface Tester : NSObject
|
||||
{
|
||||
}
|
||||
+ (void) connectWithPorts: (NSArray*)portArray;
|
||||
+ (void) setServer: (id)anObject;
|
||||
+ (void) startup;
|
||||
- (int) doIt;
|
||||
- (void) testPerform: (id)anObject;
|
||||
@end
|
||||
|
||||
@implementation Tester
|
||||
+ (void) connectWithPorts: (NSArray*)portArray
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
NSConnection *serverConnection;
|
||||
Tester *serverObject;
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
serverConnection = [NSConnection
|
||||
connectionWithReceivePort: [portArray objectAtIndex: 0]
|
||||
sendPort: [portArray objectAtIndex: 1]];
|
||||
|
||||
serverObject = [[self alloc] init];
|
||||
[serverObject performSelectorOnMainThread: @selector(testPerform:)
|
||||
withObject: @"84"
|
||||
waitUntilDone: NO];
|
||||
|
||||
[(id)[serverConnection rootProxy] setServer: serverObject];
|
||||
[serverObject release];
|
||||
|
||||
[[NSRunLoop currentRunLoop] run];
|
||||
[pool release];
|
||||
[NSThread exit];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
+ (void) setServer: (id)anObject
|
||||
{
|
||||
myServer = [anObject retain];
|
||||
NSLog(@"Got %d", [myServer doIt]);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
+ (void) startup
|
||||
{
|
||||
NSPort *port1;
|
||||
NSPort *port2;
|
||||
NSArray *portArray;
|
||||
NSConnection *conn;
|
||||
|
||||
port1 = [NSPort port];
|
||||
port2 = [NSPort port];
|
||||
|
||||
conn = [[NSConnection alloc] initWithReceivePort: port1 sendPort: port2];
|
||||
[conn setRootObject: self];
|
||||
|
||||
/* Ports switched here. */
|
||||
portArray = [NSArray arrayWithObjects: port2, port1, nil];
|
||||
|
||||
[NSThread detachNewThreadSelector: @selector(connectWithPorts:)
|
||||
toTarget: self
|
||||
withObject: portArray];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
- (int) doIt
|
||||
{
|
||||
return 42;
|
||||
}
|
||||
|
||||
- (void) testPerform: (id)anObject
|
||||
{
|
||||
NSLog(@"Test perform: %@", anObject);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
int
|
||||
main(int argc, char *argv[], char **env)
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
|
||||
#if LIB_FOUNDATION_LIBRARY || defined(GS_PASS_ARGUMENTS)
|
||||
[NSProcessInfo initializeWithArguments:argv count:argc environment:env];
|
||||
#endif
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
[Tester startup];
|
||||
[[NSRunLoop currentRunLoop] run];
|
||||
[pool release];
|
||||
return 0;
|
||||
}
|
646
Examples/nsconnection_client.m
Normal file
646
Examples/nsconnection_client.m
Normal file
|
@ -0,0 +1,646 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <Foundation/NSObject.h>
|
||||
#include <Foundation/NSConnection.h>
|
||||
#include <Foundation/NSDistantObject.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSRunLoop.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSDate.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include <Foundation/NSProcessInfo.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <assert.h>
|
||||
#include "server.h"
|
||||
|
||||
#include "wgetopt.h"
|
||||
|
||||
/*
|
||||
* Dummy declaration with different bycopy/byref info from the one
|
||||
* in the server ... we expect the info from the server to be used.
|
||||
*/
|
||||
@interface Dummy : NSObject
|
||||
- (id) quietBycopy: (byref id)a;
|
||||
@end
|
||||
|
||||
@interface CallbackClient : NSObject <ClientProtocol>
|
||||
- (BOOL) callback;
|
||||
@end
|
||||
|
||||
@implementation CallbackClient
|
||||
- (BOOL) callback
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@interface Auth : NSObject
|
||||
@end
|
||||
|
||||
@implementation Auth
|
||||
- (BOOL) authenticateComponents: (NSMutableArray*)components
|
||||
withData: (NSData*)authData
|
||||
{
|
||||
unsigned count = [components count];
|
||||
|
||||
while (count-- > 0)
|
||||
{
|
||||
id obj = [components objectAtIndex: count];
|
||||
|
||||
if ([obj isKindOfClass: [NSData class]] == YES)
|
||||
{
|
||||
NSMutableData *d = [obj mutableCopy];
|
||||
unsigned l = [d length];
|
||||
char *p = (char*)[d mutableBytes];
|
||||
|
||||
while (l-- > 0)
|
||||
p[l] ^= 42;
|
||||
[components replaceObjectAtIndex: count withObject: d];
|
||||
RELEASE(d);
|
||||
}
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
@end
|
||||
|
||||
int con_data (id prx)
|
||||
{
|
||||
id pool;
|
||||
BOOL b, br;
|
||||
unsigned char uc, ucr;
|
||||
char c, cr;
|
||||
short s, sr;
|
||||
int i, ir;
|
||||
long l, lr;
|
||||
float flt, fltr;
|
||||
double dbl, dblr;
|
||||
char *str;
|
||||
id obj;
|
||||
small_struct small = {12};
|
||||
foo ffoo = {'Z', 1234.5678, 99, "cow", 9876543};
|
||||
int a3[3] = {66,77,88};
|
||||
struct myarray ma = {{55,66,77}};
|
||||
|
||||
printf("Testing data sending\n");
|
||||
|
||||
printf("Boolean:\n");
|
||||
b = YES;
|
||||
printf(" sending %d", b);
|
||||
br = [prx sendBoolean: b];
|
||||
printf(" got %d", br);
|
||||
if (b == !br)
|
||||
printf(" ...ok\n");
|
||||
else
|
||||
printf(" *** ERROR ***\n");
|
||||
br = b = YES;
|
||||
printf(" sending ptr to %d", br);
|
||||
[prx getBoolean: &br];
|
||||
printf(" got %d", br);
|
||||
if (b == !br)
|
||||
printf(" ...ok\n");
|
||||
else
|
||||
printf(" *** ERROR ***\n");
|
||||
printf(" error is ok (due to incorrect encoding by gcc)\n");
|
||||
|
||||
#define TEST_CALL(test, send, got, sendp, var, varr, val, msg1, msg2) \
|
||||
pool = [NSAutoreleasePool new]; \
|
||||
printf(test); \
|
||||
var = val; \
|
||||
printf(send, var); \
|
||||
varr = [prx msg1 var]; \
|
||||
printf(got, varr); \
|
||||
if (varr != (var+ADD_CONST)) \
|
||||
printf(" *** ERROR ***\n"); \
|
||||
else \
|
||||
printf(" ...ok\n"); \
|
||||
varr = var = val+1; \
|
||||
printf(sendp, varr); \
|
||||
[prx msg2 &varr]; \
|
||||
printf(got, varr); \
|
||||
if (varr != (var+ADD_CONST)) \
|
||||
printf(" *** ERROR ***\n"); \
|
||||
else \
|
||||
printf(" ...ok\n"); \
|
||||
[pool release];
|
||||
|
||||
#define TEST_FCALL(test, send, got, sendp, var, varr, val, msg1, msg2) \
|
||||
pool = [NSAutoreleasePool new]; \
|
||||
printf(test); \
|
||||
var = val; \
|
||||
printf(send, var); \
|
||||
varr = [prx msg1 var]; \
|
||||
printf(got, varr); \
|
||||
if (varr - (var+ADD_CONST) > 1e-3) \
|
||||
printf(" *** ERROR ***\n"); \
|
||||
else \
|
||||
printf(" ...ok\n"); \
|
||||
varr = var = val+1; \
|
||||
printf(sendp, varr); \
|
||||
[prx msg2 &varr]; \
|
||||
printf(got, varr); \
|
||||
if (varr - (var+ADD_CONST) > 1e-3) \
|
||||
printf(" *** ERROR ***\n"); \
|
||||
else \
|
||||
printf(" ...ok\n"); \
|
||||
[pool release];
|
||||
|
||||
TEST_CALL("UChar:\n", " sending %d", " got %d", " sending ptr to %d",
|
||||
uc, ucr, 23, sendUChar:, getUChar:)
|
||||
printf(" error is ok (due to incorrect encoding by gcc)\n");
|
||||
|
||||
TEST_CALL("Char:\n", " sending %d", " got %d", " sending ptr to %d",
|
||||
c, cr, 23, sendChar:, getChar:)
|
||||
printf(" error is ok (due to incorrect encoding by gcc)\n");
|
||||
|
||||
TEST_CALL("Short:\n", " sending %hd", " got %hd", " sending ptr to %hd",
|
||||
s, sr, 23, sendShort:, getShort:)
|
||||
|
||||
TEST_CALL("Int:\n", " sending %d", " got %d", " sending ptr to %d",
|
||||
i, ir, 23, sendInt:, getInt:)
|
||||
|
||||
TEST_CALL("Long:\n", " sending %ld", " got %ld", " sending ptr to %ld",
|
||||
l, lr, 23, sendLong:, getLong:)
|
||||
|
||||
TEST_FCALL("Float:\n", " sending %f", " got %f", " sending ptr to %f",
|
||||
flt, fltr, 23.2, sendFloat:, getFloat:)
|
||||
|
||||
TEST_FCALL("Double:\n", " sending %g", " got %g", " sending ptr to %g",
|
||||
dbl, dblr, 23.2, sendDouble:, getDouble:)
|
||||
|
||||
flt = 2.718;
|
||||
dbl = 3.14159265358979323846264338327;
|
||||
printf(" sending double %f, float %f\n", dbl, flt);
|
||||
[prx sendDouble:dbl andFloat:flt];
|
||||
|
||||
|
||||
pool = [NSAutoreleasePool new];
|
||||
printf("String:\n");
|
||||
str = "My String 1";
|
||||
printf(" sending (%s)", str);
|
||||
str = [prx sendString: str];
|
||||
printf(" got (%s)\n", str);
|
||||
[pool release];
|
||||
|
||||
pool = [NSAutoreleasePool new];
|
||||
str = "My String 3";
|
||||
printf(" sending ptr to (%s)", str);
|
||||
[prx getString: &str];
|
||||
printf(" got (%s)\n", str);
|
||||
[pool release];
|
||||
|
||||
pool = [NSAutoreleasePool new];
|
||||
printf("Small Struct:\n");
|
||||
//printf(" sending %x", small.z);
|
||||
//small = [prx sendSmallStruct: small];
|
||||
//printf(" got %x\n", small.z);
|
||||
printf(" sending ptr to %x", small.z);
|
||||
[prx getSmallStruct: &small];
|
||||
printf(" got %x\n", small.z);
|
||||
[pool release];
|
||||
|
||||
#if 1 || !defined(__MINGW32__)
|
||||
pool = [NSAutoreleasePool new];
|
||||
printf("Struct:\n");
|
||||
printf(" sending c='%c',d=%g,i=%d,s=%s,l=%ld",
|
||||
ffoo.c, ffoo.d, ffoo.i, ffoo.s, ffoo.l);
|
||||
ffoo = [prx sendStruct: ffoo];
|
||||
printf(" got c='%c',d=%g,i=%d,s=%s,l=%ld\n",
|
||||
ffoo.c, ffoo.d, ffoo.i, ffoo.s, ffoo.l);
|
||||
printf(" sending ptr to c='%c',d=%g,i=%d,s=%s,l=%ld",
|
||||
ffoo.c, ffoo.d, ffoo.i, ffoo.s, ffoo.l);
|
||||
[prx getStruct: &ffoo];
|
||||
printf(" got c='%c',d=%g,i=%d,s=%s,l=%ld\n",
|
||||
ffoo.c, ffoo.d, ffoo.i, ffoo.s, ffoo.l);
|
||||
[pool release];
|
||||
#endif
|
||||
|
||||
pool = [NSAutoreleasePool new];
|
||||
printf("Object:\n");
|
||||
obj = [NSObject new];
|
||||
[prx addObject: obj]; // FIXME: Why is this needed?
|
||||
printf(" sending %s", [[obj description] cString]);
|
||||
obj = [prx sendObject: obj];
|
||||
printf(" got %s\n", [[obj description] cString]);
|
||||
printf(" sending ptr to %s", [[obj description] cString]);
|
||||
[prx getObject: &obj];
|
||||
printf(" got %s\n", [[obj description] cString]);
|
||||
[pool release];
|
||||
|
||||
printf("Many Arguments:\n");
|
||||
[prx manyArgs:1 :2 :3 :4 :5 :6 :7 :8 :9 :10 :11 :12];
|
||||
|
||||
printf("Done\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
con_messages (id prx)
|
||||
{
|
||||
id obj;
|
||||
Protocol *pc = @protocol(ClientProtocol);
|
||||
Protocol *ps = @protocol(ServerProtocol);
|
||||
|
||||
obj = [NSObject new];
|
||||
|
||||
printf("Conforms to protocol (remote) should be 1: %d\n",
|
||||
[prx conformsToProtocol: ps]);
|
||||
printf("Conforms to protocol (remote) should be 0: %d\n",
|
||||
[prx conformsToProtocol: pc]);
|
||||
|
||||
[prx setProtocolForProxy: ps];
|
||||
|
||||
printf("Conforms to protocol (local) should be 1: %d\n",
|
||||
[prx conformsToProtocol: ps]);
|
||||
printf("Conforms to protocol (local) should be 0: %d\n",
|
||||
[prx conformsToProtocol: pc]);
|
||||
|
||||
printf("Oneway Void message:\n");
|
||||
[prx shout];
|
||||
printf(" ok\n");
|
||||
|
||||
printf("Testing exception in method with return value:\n");
|
||||
NS_DURING
|
||||
{
|
||||
[prx exceptionTest1];
|
||||
printf(" ERROR\n");
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
printf(" ok ... %s\n", [[localException description] cString]);
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
|
||||
printf("Testing exception in method with void return:\n");
|
||||
NS_DURING
|
||||
{
|
||||
[prx exceptionTest2];
|
||||
printf(" ERROR\n");
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
printf(" ok ... %s\n", [[localException description] cString]);
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
|
||||
printf("Testing exception in oneway void method:\n");
|
||||
NS_DURING
|
||||
{
|
||||
[prx exceptionTest3];
|
||||
printf(" ok\n");
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
printf(" ERROR ... %s\n", [[localException description] cString]);
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* this next line doesn't actually test callbacks, it tests
|
||||
sending the same object twice in the same message. */
|
||||
printf("Send same object twice in message\n");
|
||||
[prx sendObject: prx];
|
||||
printf(" ok\n");
|
||||
|
||||
printf("performSelector:\n");
|
||||
if (prx != [prx performSelector: GSSelectorFromName("self")])
|
||||
printf(" ERROR\n");
|
||||
else
|
||||
printf(" ok\n");
|
||||
|
||||
printf("Testing bycopy/byref:\n");
|
||||
[prx sendBycopy: obj];
|
||||
[prx quietBycopy: obj];
|
||||
|
||||
#ifdef _F_BYREF
|
||||
[prx sendByref: obj];
|
||||
[prx sendByref: @"hello"];
|
||||
[prx sendByref: [NSDate date]];
|
||||
{
|
||||
NSMutableString *str = [NSMutableString string];
|
||||
|
||||
[prx modifyByref: str];
|
||||
printf(" Modified '%s'\n", [str lossyCString]);
|
||||
}
|
||||
#endif
|
||||
printf(" ok\n");
|
||||
|
||||
printf("Done\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
con_benchmark (id prx)
|
||||
{
|
||||
int i;
|
||||
NSDate *d = [NSDate date];
|
||||
NSMutableData *sen = [NSMutableData data];
|
||||
id localObj;
|
||||
id rep;
|
||||
|
||||
printf("Benchmarking\n");
|
||||
[sen setLength: 100000];
|
||||
rep = [prx sendObject: sen];
|
||||
printf(" Sent: 0x%p, Reply: 0x%p, Length: %d\n", sen, rep, [rep length]);
|
||||
|
||||
localObj = [[NSObject alloc] init];
|
||||
[prx addObject: localObj]; // FIXME: Why is this needed?
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
#if 0
|
||||
k = [prx count];
|
||||
for (j = 0; j < k; j++)
|
||||
{
|
||||
id remote_peer_obj = [prx objectAt: j];
|
||||
}
|
||||
#endif
|
||||
[prx echoObject: localObj];
|
||||
}
|
||||
|
||||
printf(" Delay is %f\n", [d timeIntervalSinceNow]);
|
||||
printf("Done\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
con_statistics (id prx)
|
||||
{
|
||||
int j;
|
||||
id localObj, cobj, a, o;
|
||||
|
||||
printf("------------------------------------------------------------\n");
|
||||
printf("Printing Statistics\n");
|
||||
localObj = [[NSObject alloc] init];
|
||||
[prx outputStats: localObj];
|
||||
printf(" >>list proxy's hash is 0x%d\n", [prx hash]);
|
||||
printf(" >>list proxy's self is 0x%p = 0x%p\n", [prx self], prx);
|
||||
printf(" >>proxy's description is (%s)\n", [[prx description] lossyCString]);
|
||||
|
||||
cobj = [prx connectionForProxy];
|
||||
o = [cobj statistics];
|
||||
a = [o allKeys];
|
||||
|
||||
for (j = 0; j < [a count]; j++)
|
||||
{
|
||||
id k = [a objectAtIndex:j];
|
||||
id v = [o objectForKey:k];
|
||||
|
||||
printf(" %s - %s\n", [k cString], [[v description] cString]);
|
||||
}
|
||||
printf("------------------------------------------------------------\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
con_loop (id prx)
|
||||
{
|
||||
NSAutoreleasePool *arp;
|
||||
id cobj;
|
||||
|
||||
arp = [NSAutoreleasePool new];
|
||||
[prx addObject: [NSObject new]]; // So loss of this connection is logged.
|
||||
cobj = [prx connectionForProxy];
|
||||
printf("%d\n", [cobj retainCount]);
|
||||
printf("%s\n", [[[cobj statistics] description] cString]);
|
||||
//printf("%s\n", GSDebugAllocationList(YES));
|
||||
|
||||
printf("loop left running idle for 30 seconds\n");
|
||||
[[NSRunLoop currentRunLoop] runUntilDate:
|
||||
[NSDate dateWithTimeIntervalSinceNow: 30]];
|
||||
[cobj invalidate];
|
||||
[arp release];
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
con_objects (id prx)
|
||||
{
|
||||
int j, k;
|
||||
id localObj;
|
||||
|
||||
localObj = [NSObject new];
|
||||
[prx addObject:localObj];
|
||||
k = [prx count];
|
||||
for (j = 0; j < k; j++)
|
||||
{
|
||||
id remote_peer_obj = [prx objectAt:j];
|
||||
printf("triangle %d object proxy's hash is 0x%x\n",
|
||||
j, (unsigned)[remote_peer_obj hash]);
|
||||
|
||||
#if 0
|
||||
/* xxx look at this again after we use release/retain everywhere */
|
||||
if ([remote_peer_obj isProxy])
|
||||
[remote_peer_obj release];
|
||||
#endif
|
||||
remote_peer_obj = [prx objectAt:j];
|
||||
printf("repeated triangle %d object proxy's hash is 0x%x\n",
|
||||
j, (unsigned)[remote_peer_obj hash]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
con_callback (id prx)
|
||||
{
|
||||
int j, k;
|
||||
id localObj;
|
||||
|
||||
localObj = [CallbackClient new];
|
||||
[prx registerClient: localObj];
|
||||
k = 1000;
|
||||
for (j = 0; j < k; j++)
|
||||
{
|
||||
CREATE_AUTORELEASE_POOL(arp);
|
||||
[prx unregisterClient: localObj];
|
||||
[prx registerClient: localObj];
|
||||
[prx tryClientCallback];
|
||||
if (j < 10 || j %10 == 0)
|
||||
printf("repeated client registration and callback %d\n", j);
|
||||
RELEASE(arp);
|
||||
}
|
||||
printf("repeated client registration and callback %d\n", j);
|
||||
RELEASE(localObj);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
usage(const char *program)
|
||||
{
|
||||
printf("Usage: %s [-ds] [t|b|m|l|o] [host] [server]\n", program);
|
||||
printf(" -d - Debug connection\n");
|
||||
printf(" -s - Print Statistics\n");
|
||||
printf(" -t - Data type test [default]\n");
|
||||
printf(" -b - Benchmark test\n");
|
||||
printf(" -m - Messaging test\n");
|
||||
printf(" -l - Loop test\n");
|
||||
printf(" -o - Objects test\n");
|
||||
printf(" -c - Connect test\n");
|
||||
printf(" -r - Registration and callback test\n");
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
NO_TEST, TYPE_TEST, BENCHMARK_TEST, MESSAGE_TEST,
|
||||
LOOP_TEST, OBJECT_TEST, CONNECT_TEST, CALLBACK_TEST
|
||||
} test_t;
|
||||
|
||||
int main (int argc, char *argv[], char **env)
|
||||
{
|
||||
int c, debug, stats;
|
||||
test_t type_test;
|
||||
id cobj, prx;
|
||||
unsigned connect_attempts;
|
||||
NSAutoreleasePool *arp;
|
||||
Auth *auth;
|
||||
#ifndef __MINGW32__
|
||||
extern int optind;
|
||||
extern char *optarg;
|
||||
#endif
|
||||
|
||||
[NSProcessInfo initializeWithArguments: argv count: argc environment: env];
|
||||
arp = [NSAutoreleasePool new];
|
||||
auth = [Auth new];
|
||||
GSDebugAllocationActive(YES);
|
||||
|
||||
setvbuf(stdout, 0, _IONBF, 0);
|
||||
debug = 0;
|
||||
type_test = 0;
|
||||
stats = 0;
|
||||
while ((c = getopt(argc, argv, "hdtbmslocr")) != EOF)
|
||||
switch (c)
|
||||
{
|
||||
case 'd':
|
||||
debug++;
|
||||
break;
|
||||
case 't':
|
||||
type_test = TYPE_TEST;
|
||||
break;
|
||||
case 'b':
|
||||
type_test = BENCHMARK_TEST;
|
||||
break;
|
||||
case 'm':
|
||||
type_test = MESSAGE_TEST;
|
||||
break;
|
||||
case 's':
|
||||
stats = 1;
|
||||
break;
|
||||
case 'l':
|
||||
type_test = LOOP_TEST;
|
||||
break;
|
||||
case 'o':
|
||||
type_test = OBJECT_TEST;
|
||||
break;
|
||||
case 'c':
|
||||
type_test = CONNECT_TEST;
|
||||
break;
|
||||
case 'r':
|
||||
type_test = CALLBACK_TEST;
|
||||
break;
|
||||
case 'h':
|
||||
usage(argv[0]);
|
||||
exit(0);
|
||||
break;
|
||||
default:
|
||||
#if 0
|
||||
usage(argv[0]);
|
||||
exit(1);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
if (type_test == NO_TEST)
|
||||
type_test = TYPE_TEST;
|
||||
|
||||
if (type_test == CONNECT_TEST)
|
||||
connect_attempts = 100000;
|
||||
else
|
||||
connect_attempts = 1;
|
||||
|
||||
if (debug > 0)
|
||||
{
|
||||
[NSConnection setDebug: debug];
|
||||
[NSDistantObject setDebug: debug];
|
||||
[NSObject enableDoubleReleaseCheck: YES];
|
||||
}
|
||||
|
||||
while (connect_attempts-- > 0)
|
||||
{
|
||||
if (optind < argc)
|
||||
{
|
||||
if (optind+1 < argc)
|
||||
prx = [NSConnection rootProxyForConnectionWithRegisteredName:
|
||||
[NSString stringWithCString: argv[optind+1]]
|
||||
host: [NSString stringWithCString:argv[optind]]];
|
||||
else
|
||||
prx = [NSConnection rootProxyForConnectionWithRegisteredName:
|
||||
@"test2server"
|
||||
host:[NSString stringWithCString:argv[optind]]];
|
||||
}
|
||||
else
|
||||
prx = [NSConnection rootProxyForConnectionWithRegisteredName:
|
||||
@"test2server" host: @""];
|
||||
if (prx == nil)
|
||||
{
|
||||
printf("ERROR: Failed to connect to server\n");
|
||||
return -1;
|
||||
}
|
||||
if (type_test == CONNECT_TEST)
|
||||
{
|
||||
NSLog(@"Made connection\n");
|
||||
if (connect_attempts > 0)
|
||||
{
|
||||
RELEASE(arp);
|
||||
arp = [NSAutoreleasePool new];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cobj = [prx connectionForProxy];
|
||||
[cobj setDelegate:auth];
|
||||
[cobj setRequestTimeout:180.0];
|
||||
[cobj setReplyTimeout:180.0];
|
||||
|
||||
[prx print: "This is a message from the client. Starting Tests!"];
|
||||
|
||||
switch (type_test)
|
||||
{
|
||||
case TYPE_TEST:
|
||||
con_data (prx);
|
||||
break;
|
||||
case BENCHMARK_TEST:
|
||||
con_benchmark (prx);
|
||||
break;
|
||||
case MESSAGE_TEST:
|
||||
con_messages (prx);
|
||||
break;
|
||||
case LOOP_TEST:
|
||||
con_loop (prx);
|
||||
break;
|
||||
case OBJECT_TEST:
|
||||
con_objects (prx);
|
||||
break;
|
||||
case CALLBACK_TEST:
|
||||
con_callback (prx);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (stats)
|
||||
con_statistics (prx);
|
||||
|
||||
[cobj invalidate];
|
||||
|
||||
[arp release];
|
||||
return 0;
|
||||
}
|
550
Examples/nsconnection_server.m
Normal file
550
Examples/nsconnection_server.m
Normal file
|
@ -0,0 +1,550 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSConnection.h>
|
||||
#include <Foundation/NSDistantObject.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSNotification.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSRunLoop.h>
|
||||
#include <Foundation/NSProcessInfo.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSProtocolChecker.h>
|
||||
|
||||
#define IN_SERVER 1
|
||||
#include "server.h"
|
||||
|
||||
#include "wgetopt.h"
|
||||
|
||||
@implementation Server
|
||||
|
||||
- (NSData*) authenticationDataForComponents: (NSMutableArray*)components
|
||||
{
|
||||
unsigned count = [components count];
|
||||
|
||||
while (count-- > 0)
|
||||
{
|
||||
id obj = [components objectAtIndex: count];
|
||||
|
||||
if ([obj isKindOfClass: [NSData class]] == YES)
|
||||
{
|
||||
NSMutableData *d = [obj mutableCopy];
|
||||
unsigned l = [d length];
|
||||
char *p = (char*)[d mutableBytes];
|
||||
|
||||
while (l-- > 0)
|
||||
p[l] ^= 42;
|
||||
[components replaceObjectAtIndex: count withObject: d];
|
||||
RELEASE(d);
|
||||
}
|
||||
}
|
||||
return [NSData data];
|
||||
}
|
||||
|
||||
- init
|
||||
{
|
||||
the_array = [[NSMutableArray alloc] init];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (unsigned) count
|
||||
{
|
||||
return [the_array count];
|
||||
}
|
||||
|
||||
- (void) addObject: o
|
||||
{
|
||||
[the_array addObject:o];
|
||||
}
|
||||
|
||||
- objectAt: (unsigned)i
|
||||
{
|
||||
if (i < [the_array count])
|
||||
return [the_array objectAtIndex: i];
|
||||
else
|
||||
return nil;
|
||||
}
|
||||
|
||||
- echoObject: obj
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
|
||||
- (int) exceptionTest1
|
||||
{
|
||||
[NSException raise: @"Test1" format: @"exception1"];
|
||||
return 111;
|
||||
}
|
||||
|
||||
- (void) exceptionTest2
|
||||
{
|
||||
[NSException raise: @"Test2" format: @"exception2"];
|
||||
}
|
||||
|
||||
- (void) exceptionTest3
|
||||
{
|
||||
[NSException raise: @"Test3" format: @"exception3"];
|
||||
}
|
||||
|
||||
- print: (const char *)msg
|
||||
{
|
||||
printf(">>%s<<\n", msg);
|
||||
fflush(stdout);
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL) sendBoolean: (BOOL)b
|
||||
{
|
||||
printf("(%s) got %d, returning %d\n", GSNameFromSelector(_cmd), (int)b, (int)(!b));
|
||||
fflush(stdout);
|
||||
return !b;
|
||||
}
|
||||
|
||||
/* This causes problems, because the runtime encodes this as "*", a string! */
|
||||
- (void) getBoolean: (BOOL*)bp
|
||||
{
|
||||
BOOL rbp = !(*bp);
|
||||
printf("(%s) got %d, returning %d\n", GSNameFromSelector(_cmd),
|
||||
(int)*bp, (int)rbp);
|
||||
fflush(stdout);
|
||||
*bp = rbp;
|
||||
}
|
||||
|
||||
- (unsigned char) sendUChar: (unsigned char)num
|
||||
{
|
||||
unsigned char rnum = num + ADD_CONST;
|
||||
printf("(%s) got %d, returning %d\n", GSNameFromSelector(_cmd),
|
||||
(int)num, (int)rnum);
|
||||
fflush(stdout);
|
||||
return rnum;
|
||||
}
|
||||
|
||||
/* This causes problems, because the runtime encodes this as "*", a string! */
|
||||
- (void) getUChar: (unsigned char *)num
|
||||
{
|
||||
unsigned char rnum = *num + ADD_CONST;
|
||||
printf("(%s) got %d, returning %d\n", GSNameFromSelector(_cmd),
|
||||
(int)(*num), (int)rnum);
|
||||
*num = rnum;
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
- (char) sendChar: (char)num
|
||||
{
|
||||
char rnum = num + ADD_CONST;
|
||||
printf("(%s) got %d, returning %d\n", GSNameFromSelector(_cmd),
|
||||
(int)num, (int)rnum);
|
||||
fflush(stdout);
|
||||
return rnum;
|
||||
}
|
||||
|
||||
- (void) getChar: (char *)num
|
||||
{
|
||||
char rnum = *num + ADD_CONST;
|
||||
printf("(%s) got %d, returning %d\n", GSNameFromSelector(_cmd),
|
||||
(int)(*num), (int)rnum);
|
||||
*num = rnum;
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
- (short) sendShort: (short)num
|
||||
{
|
||||
short rnum = num + ADD_CONST;
|
||||
printf("(%s) got %hd, returning %hd\n", GSNameFromSelector(_cmd),
|
||||
num, rnum);
|
||||
fflush(stdout);
|
||||
return rnum;
|
||||
}
|
||||
|
||||
- (void) getShort: (short *)num
|
||||
{
|
||||
short rnum = *num + ADD_CONST;
|
||||
printf("(%s) got %hd, returning %hd\n", GSNameFromSelector(_cmd),
|
||||
(*num), rnum);
|
||||
*num = rnum;
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
- (int) sendInt: (int)num
|
||||
{
|
||||
int rnum = num + ADD_CONST;
|
||||
printf("(%s) got %d, returning %d\n", GSNameFromSelector(_cmd), num, rnum);
|
||||
fflush(stdout);
|
||||
return rnum;
|
||||
}
|
||||
|
||||
- (void) getInt: (int *)num
|
||||
{
|
||||
int rnum = *num + ADD_CONST;
|
||||
printf("(%s) got %d, returning %d\n", GSNameFromSelector(_cmd), *num, rnum);
|
||||
*num = rnum;
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
- (long) sendLong: (long)num
|
||||
{
|
||||
long rnum = num + ADD_CONST;
|
||||
printf("(%s) got %ld, returning %ld\n", GSNameFromSelector(_cmd), num, rnum);
|
||||
fflush(stdout);
|
||||
return rnum;
|
||||
}
|
||||
|
||||
- (void) getLong: (long *)num
|
||||
{
|
||||
long rnum = *num + ADD_CONST;
|
||||
printf("(%s) got %ld, returning %ld\n", GSNameFromSelector(_cmd), *num, rnum);
|
||||
*num = rnum;
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
- (float) sendFloat: (float)num
|
||||
{
|
||||
float rnum = num + ADD_CONST;
|
||||
printf("(%s) got %f, returning %f\n", GSNameFromSelector(_cmd), num, rnum);
|
||||
fflush(stdout);
|
||||
return rnum;
|
||||
}
|
||||
|
||||
- (void) getFloat: (float *)num
|
||||
{
|
||||
float rnum = *num + ADD_CONST;
|
||||
printf("(%s) got %f, returning %f\n", GSNameFromSelector(_cmd), *num, rnum);
|
||||
*num = rnum;
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
- (double) sendDouble: (double)num
|
||||
{
|
||||
double rnum = num + ADD_CONST;
|
||||
printf("(%s) got %g, returning %g\n", GSNameFromSelector(_cmd), num, rnum);
|
||||
fflush(stdout);
|
||||
return rnum;
|
||||
}
|
||||
|
||||
- (void) getDouble: (double *)num
|
||||
{
|
||||
double rnum = *num + ADD_CONST;
|
||||
printf("(%s) got %g, returning %g\n", GSNameFromSelector(_cmd), *num, rnum);
|
||||
*num = rnum;
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
- (small_struct) sendSmallStruct: (small_struct)str
|
||||
{
|
||||
char rnum = str.z + ADD_CONST;
|
||||
printf("(%s) got %d, returning %d\n", GSNameFromSelector(_cmd), str.z, rnum);
|
||||
fflush(stdout);
|
||||
str.z = rnum;
|
||||
return str;
|
||||
}
|
||||
|
||||
- (void) getSmallStruct: (small_struct *)str
|
||||
{
|
||||
char rnum = str->z + ADD_CONST;
|
||||
printf("(%s) got %d, returning %d\n", GSNameFromSelector(_cmd), str->z, rnum);
|
||||
fflush(stdout);
|
||||
str->z = rnum;
|
||||
}
|
||||
|
||||
- (foo) sendStruct: (foo)f
|
||||
{
|
||||
foo f2 = {'A', 123.456, 1, "horse", 987654};
|
||||
printf("(%s) got c='%c', d=%g, i=%d, s=%s, l=%lu",
|
||||
GSNameFromSelector(_cmd), f.c, f.d, f.i, f.s, f.l);
|
||||
fflush(stdout);
|
||||
printf(" returning c='%c', d=%g, i=%d, s=%s, l=%lu\n",
|
||||
f2.c, f2.d, f2.i, f2.s, f2.l);
|
||||
fflush(stdout);
|
||||
return f2;
|
||||
}
|
||||
|
||||
- (void) getStruct: (foo *)f
|
||||
{
|
||||
foo f2 = {'A', 123.456, 1, "horse", 987654};
|
||||
printf("(%s) got c='%c', d=%g, i=%d, s=%s, l=%lu",
|
||||
GSNameFromSelector(_cmd), f->c, f->d, f->i, f->s, f->l);
|
||||
fflush(stdout);
|
||||
printf(" returning c='%c', d=%g, i=%d, s=%s, l=%lu\n",
|
||||
f2.c, f2.d, f2.i, f2.s, f2.l);
|
||||
fflush(stdout);
|
||||
*f = f2;
|
||||
}
|
||||
|
||||
- sendObject: (id)str
|
||||
{
|
||||
printf ("(%s) got object (%s)\n", GSNameFromSelector(_cmd),
|
||||
GSClassNameFromObject(str));
|
||||
fflush(stdout);
|
||||
return str;
|
||||
}
|
||||
|
||||
- (void) getObject: (id *)str
|
||||
{
|
||||
printf ("(%s) got object (%s)\n", GSNameFromSelector(_cmd),
|
||||
GSClassNameFromObject(*str));
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
- (char *) sendString: (char *)str
|
||||
{
|
||||
printf ("(%s) got string (%s)", GSNameFromSelector(_cmd), str);
|
||||
str[0] = 'N';
|
||||
printf(" returning (%s)\n", str);
|
||||
fflush(stdout);
|
||||
return str;
|
||||
}
|
||||
|
||||
- (void) getString: (char **)str
|
||||
{
|
||||
printf ("(%s) got string (%s)", GSNameFromSelector(_cmd), *str);
|
||||
(*str)[0] = 'N';
|
||||
printf(" returning (%s)\n", *str);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
- (oneway void) shout
|
||||
{
|
||||
printf ("(%s) got it\n", GSNameFromSelector(_cmd));
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
/* sender must also respond to 'bounce:count:' */
|
||||
- bounce: sender count: (int)c
|
||||
{
|
||||
printf ("(%s) got message %d, bouncing back %d", GSNameFromSelector(_cmd), c, c-1);
|
||||
fflush(stdout);
|
||||
if (--c)
|
||||
[sender bounce:self count:c];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) outputStats:obj
|
||||
{
|
||||
id c = [obj connectionForProxy];
|
||||
id o = [c statistics];
|
||||
id a = [o allKeys];
|
||||
int j;
|
||||
|
||||
printf("------------------------------------------------------------\n");
|
||||
printf("Printing Statistics\n");
|
||||
printf(" Number of connections - %d\n", [[NSConnection allConnections] count]);
|
||||
printf(" This connection -\n");
|
||||
for (j = 0; j < [a count]; j++)
|
||||
{
|
||||
id k = [a objectAtIndex:j];
|
||||
id v = [o objectForKey:k];
|
||||
printf(" %s - %s\n", [k cString], [[v description] cString]);
|
||||
}
|
||||
printf("------------------------------------------------------------\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
/* Doesn't work because GCC generates the wrong encoding: "@0@+8:+12^i+16" */
|
||||
- sendArray: (int[3])a
|
||||
{
|
||||
printf(" >> array %d %d %d\n", a[0], a[1], a[2]);
|
||||
fflush(stdout);
|
||||
return self;
|
||||
}
|
||||
|
||||
- sendStructArray: (struct myarray)ma
|
||||
{
|
||||
printf(" >>struct array %d %d %d\n", ma.a[0], ma.a[1], ma.a[2]);
|
||||
fflush(stdout);
|
||||
return self;
|
||||
}
|
||||
|
||||
- sendDouble: (double)d andFloat: (float)f
|
||||
{
|
||||
printf("(%s) got double %f, float %f\n", GSNameFromSelector(_cmd), d, f);
|
||||
fflush(stdout);
|
||||
return self;
|
||||
}
|
||||
|
||||
- quietBycopy: (bycopy id)o
|
||||
{
|
||||
printf(" >> quiet bycopy class is %s\n", GSClassNameFromObject(o));
|
||||
fflush(stdout);
|
||||
return self;
|
||||
}
|
||||
|
||||
- sendBycopy: (bycopy id)o
|
||||
{
|
||||
printf(" >> bycopy class is %s\n", GSClassNameFromObject(o));
|
||||
fflush(stdout);
|
||||
return self;
|
||||
}
|
||||
|
||||
#ifdef _F_BYREF
|
||||
- sendByref: (byref id)o
|
||||
{
|
||||
printf(" >> byref class is %s\n", GSClassNameFromObject(o));
|
||||
fflush(stdout);
|
||||
return self;
|
||||
}
|
||||
- modifyByref: (byref NSMutableString *)o
|
||||
{
|
||||
printf(" >> byref class is %s\n", GSClassNameFromObject(o));
|
||||
fflush(stdout);
|
||||
[o appendString: @"hello"];
|
||||
return self;
|
||||
}
|
||||
#endif
|
||||
|
||||
- manyArgs: (int)i1 : (int)i2 : (int)i3 : (int)i4 : (int)i5 : (int)i6
|
||||
: (int)i7 : (int)i8 : (int)i9 : (int)i10 : (int)i11 : (int)i12
|
||||
{
|
||||
printf("manyArgs: got %d %d %d %d %d %d %d %d %d %d %d %d\n",
|
||||
i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12);
|
||||
fflush(stdout);
|
||||
return self;
|
||||
}
|
||||
|
||||
- connectionBecameInvalid: notification
|
||||
{
|
||||
id anObj = [notification object];
|
||||
if ([anObj isKindOfClass: [NSConnection class]])
|
||||
{
|
||||
int i, count = [the_array count];
|
||||
for (i = count-1; i >= 0; i--)
|
||||
{
|
||||
id o = [the_array objectAtIndex: i];
|
||||
if ([o isProxy] && [o connectionForProxy] == anObj)
|
||||
[the_array removeObjectAtIndex: i];
|
||||
}
|
||||
if (count != [the_array count])
|
||||
printf("$$$$$ connectionBecameInvalid: removed from the_array\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
[self error:"non Connection is invalid"];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSConnection*) connection: ancestor didConnect: newConn
|
||||
{
|
||||
printf("%s\n", GSNameFromSelector(_cmd));
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver: self
|
||||
selector: @selector(connectionBecameInvalid:)
|
||||
name: NSConnectionDidDieNotification
|
||||
object: newConn];
|
||||
[newConn setDelegate: self];
|
||||
return newConn;
|
||||
}
|
||||
|
||||
- (oneway void) registerClient: (id<ClientProtocol>)client
|
||||
{
|
||||
ASSIGN(registered_client, client);
|
||||
}
|
||||
|
||||
- (oneway void) unregisterClient: (id<ClientProtocol>)client
|
||||
{
|
||||
DESTROY(registered_client);
|
||||
}
|
||||
|
||||
- (BOOL) tryClientCallback
|
||||
{
|
||||
return [registered_client callback];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
void
|
||||
usage(const char *program)
|
||||
{
|
||||
printf("Usage: %s [-d -t#] [server_name]\n", program);
|
||||
printf(" -d - Debug connection\n");
|
||||
printf(" -t - Timeout after # seconds\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[], char **env)
|
||||
{
|
||||
int i, debug, timeout;
|
||||
id s = [[Server alloc] init];
|
||||
id l;
|
||||
id o = [[NSObject alloc] init];
|
||||
NSConnection *c;
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
#ifndef __MINGW32__
|
||||
extern int optind;
|
||||
extern char *optarg;
|
||||
#endif
|
||||
|
||||
l = [NSProtocolChecker protocolCheckerWithTarget: s
|
||||
protocol: @protocol(ServerProtocol)];
|
||||
|
||||
[NSProcessInfo initializeWithArguments: argv count: argc environment: env];
|
||||
debug = 0;
|
||||
timeout = 0;
|
||||
while ((i = getopt(argc, argv, "hdt:")) != EOF)
|
||||
switch (i)
|
||||
{
|
||||
case 'd':
|
||||
debug++;
|
||||
break;
|
||||
case 't':
|
||||
timeout = atoi(optarg);;
|
||||
break;
|
||||
case 'h':
|
||||
usage(argv[0]);
|
||||
exit(0);
|
||||
break;
|
||||
default:
|
||||
#if 0
|
||||
usage(argv[0]);
|
||||
exit(1);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
#if NeXT_runtime
|
||||
[NSDistantObject setProtocolForProxies:@protocol(AllProxies)];
|
||||
#endif
|
||||
|
||||
if (debug > 0)
|
||||
{
|
||||
[NSDistantObject setDebug: debug];
|
||||
[NSConnection setDebug: debug];
|
||||
[NSObject enableDoubleReleaseCheck: YES];
|
||||
}
|
||||
c = [NSConnection defaultConnection];
|
||||
[c setRootObject: l];
|
||||
|
||||
if (optind < argc)
|
||||
[c registerName: [NSString stringWithUTF8String: argv[optind]]];
|
||||
else
|
||||
[c registerName: @"test2server"];
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver: s
|
||||
selector: @selector(connectionBecameInvalid:)
|
||||
name: NSConnectionDidDieNotification
|
||||
object: c];
|
||||
[c setDelegate: s];
|
||||
|
||||
[s addObject: o];
|
||||
printf(" list's hash is 0x%x\n", (unsigned)[l hash]);
|
||||
printf(" object's hash is 0x%x\n", (unsigned)[o hash]);
|
||||
printf("Running...\n");
|
||||
|
||||
if (timeout)
|
||||
[[NSRunLoop currentRunLoop] runUntilDate:
|
||||
[NSDate dateWithTimeIntervalSinceNow: timeout]];
|
||||
else
|
||||
[[NSRunLoop currentRunLoop] run];
|
||||
printf("Finished\n");
|
||||
|
||||
[arp release];
|
||||
exit(0);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue