/* Too bad Objective-C doesn't have class variables... */
static NSMutableSet *servsockets;
-static NSTimer *timer;
+
@interface ITInetServerSocket(Private)
+(void)registerSocket:(ITInetServerSocket*)sock;
+(void)unregisterSocket:(ITInetServerSocket*)sock;
-(void)stopConnection;
-(void)setupRendezvousAdvertising;
-(void)stopRendezvousAdvertising;
-+(void)setupTimer;
-+(void)stopTimer;
+-(void)setupTimer;
+-(void)stopTimer;
+(void)globalTimerFunc:(NSTimer*)timer;
--(void)timerFunc;
+-(void)timerFunc:(NSTimer*)timer;
@end
@implementation ITInetServerSocket
+ (void)initialize
{
servsockets = [[NSMutableSet alloc] init];
- [self setupTimer];
+ //[self setupTimer];
}
- (id)init
service = nil;
port = 0;
rndType = rndName = nil;
+ timer = nil;
}
return self;
}
service = nil;
port = 0;
rndType = rndName = nil;
+ timer = nil;
}
return self;
}
listen(sockfd, SOMAXCONN);
fcntl(sockfd,F_SETFL,O_NONBLOCK);
[self setupRendezvousAdvertising];
+ [self setupTimer];
}
- (void)stopConnection
service = nil;
}
-+ (void)setupTimer
+- (void)setupTimer
{
- if (!timer) timer = [NSTimer timerWithTimeInterval:0 target:self selector:@selector(globalTimerFunc:) userInfo:nil repeats:YES];
+ if (!timer) timer = [NSTimer timerWithTimeInterval:0 target:self selector:@selector(timerFunc:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
}
-+ (void)stopTimer
+- (void)stopTimer
{
[timer invalidate];
[timer release];
[servsockets makeObjectsPerformSelector:@selector(timerFunc)];
}
-- (void)timerFunc
+- (void)timerFunc:(NSTimer*)timer
{
if (sockfd != -1)
{
else {perror("Too bad I haven't implemented error checking yet");}
}
else {
- ITInetSocket *csocket = [[[ITInetSocket alloc] initWithFD:cfd delegate:self] autorelease];
+ ITInetSocket *csocket = [[ITInetSocket alloc] initWithFD:cfd delegate:self];
[clients addObject:csocket];
[delegate newClientJoined:csocket];
}