git.ithinksw.org
/
ITFoundation.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Made dumper output a real IPv6 address
[ITFoundation.git]
/
ITInetServerSocket.m
diff --git
a/ITInetServerSocket.m
b/ITInetServerSocket.m
index
8f75326
..
c37ec4f
100755
(executable)
--- a/
ITInetServerSocket.m
+++ b/
ITInetServerSocket.m
@@
-9,6
+9,7
@@
#import "ITInetServerSocket.h"
#import "ITInetSocket.h"
#import <sys/types.h>
#import "ITInetServerSocket.h"
#import "ITInetSocket.h"
#import <sys/types.h>
+#import <sys/time.h>
#import <arpa/inet.h>
#import <netinet/in.h>
#import <sys/socket.h>
#import <arpa/inet.h>
#import <netinet/in.h>
#import <sys/socket.h>
@@
-17,8
+18,7
@@
#import <unistd.h>
/* Too bad Objective-C doesn't have class variables... */
#import <unistd.h>
/* Too bad Objective-C doesn't have class variables... */
-static NSMutableDictionary *servsockets;
-static NSTimer *timer;
+static NSMutableSet *servsockets;
@interface ITInetServerSocket(Private)
+(void)registerSocket:(ITInetServerSocket*)sock;
@interface ITInetServerSocket(Private)
+(void)registerSocket:(ITInetServerSocket*)sock;
@@
-28,17
+28,17
@@
static NSTimer *timer;
-(void)stopConnection;
-(void)setupRendezvousAdvertising;
-(void)stopRendezvousAdvertising;
-(void)stopConnection;
-(void)setupRendezvousAdvertising;
-(void)stopRendezvousAdvertising;
-
+
(void)setupTimer;
-
+
(void)stopTimer;
+
-
(void)setupTimer;
+
-
(void)stopTimer;
+(void)globalTimerFunc:(NSTimer*)timer;
+(void)globalTimerFunc:(NSTimer*)timer;
--(
BOOL)timerFunc
;
+-(
void)timerFunc:(NSTimer*)timer
;
@end
@implementation ITInetServerSocket
+ (void)initialize
{
@end
@implementation ITInetServerSocket
+ (void)initialize
{
- servsockets = [[NSMutable
Dictionary
alloc] init];
- [self setupTimer];
+ servsockets = [[NSMutable
Set
alloc] init];
+
//
[self setupTimer];
}
- (id)init
}
- (id)init
@@
-51,6
+51,7
@@
static NSTimer *timer;
service = nil;
port = 0;
rndType = rndName = nil;
service = nil;
port = 0;
rndType = rndName = nil;
+ timer = nil;
}
return self;
}
}
return self;
}
@@
-65,6
+66,7
@@
static NSTimer *timer;
service = nil;
port = 0;
rndType = rndName = nil;
service = nil;
port = 0;
rndType = rndName = nil;
+ timer = nil;
}
return self;
}
}
return self;
}
@@
-133,13
+135,13
@@
static NSTimer *timer;
+(void)registerSocket:(ITInetServerSocket*)sock
{
[sock setupConnection];
+(void)registerSocket:(ITInetServerSocket*)sock
{
[sock setupConnection];
- [servsockets
setObject:sock forKey:[NSString stringWithFormat:@"%lu",[sock port]]
];
+ [servsockets
addObject:sock
];
}
+(void)unregisterSocket:(ITInetServerSocket*)sock
{
[sock stopConnection];
}
+(void)unregisterSocket:(ITInetServerSocket*)sock
{
[sock stopConnection];
- [servsockets removeObject
ForKey:[NSString stringWithFormat:@"%lu",[sock port]]
];
+ [servsockets removeObject
:sock
];
}
-(short)lookupPortForServiceType:(NSString*)name
}
-(short)lookupPortForServiceType:(NSString*)name
@@
-175,6
+177,7
@@
static NSTimer *timer;
listen(sockfd, SOMAXCONN);
fcntl(sockfd,F_SETFL,O_NONBLOCK);
[self setupRendezvousAdvertising];
listen(sockfd, SOMAXCONN);
fcntl(sockfd,F_SETFL,O_NONBLOCK);
[self setupRendezvousAdvertising];
+ [self setupTimer];
}
- (void)stopConnection
}
- (void)stopConnection
@@
-199,13
+202,13
@@
static NSTimer *timer;
service = nil;
}
service = nil;
}
-
+
(void)setupTimer
+
-
(void)setupTimer
{
{
- if (!timer) timer = [NSTimer timerWithTimeInterval:0 target:self selector:@selector(
globalT
imerFunc:) userInfo:nil repeats:YES];
+ if (!timer) timer = [NSTimer timerWithTimeInterval:0 target:self selector:@selector(
t
imerFunc:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
}
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
}
-
+
(void)stopTimer
+
-
(void)stopTimer
{
[timer invalidate];
[timer release];
{
[timer invalidate];
[timer release];
@@
-214,16
+217,10
@@
static NSTimer *timer;
+ (void)globalTimerFunc:(NSTimer*)timer
{
+ (void)globalTimerFunc:(NSTimer*)timer
{
- NSEnumerator *enume = [servsockets objectEnumerator];
- id obj;
-
- while (obj = [enume nextObject])
- {
- [obj timerFunc];
- }
+ [servsockets makeObjectsPerformSelector:@selector(timerFunc)];
}
}
-- (
BOOL)timerFunc
+- (
void)timerFunc:(NSTimer*)timer
{
if (sockfd != -1)
{
{
if (sockfd != -1)
{
@@
-232,16
+229,14
@@
static NSTimer *timer;
signed int cfd;
cfd = accept(sockfd,(struct sockaddr*)&csa,&csalen);
if (cfd == -1) {
signed int cfd;
cfd = accept(sockfd,(struct sockaddr*)&csa,&csalen);
if (cfd == -1) {
- if (errno == EWOULDBLOCK)
return NO
;
+ if (errno == EWOULDBLOCK) ;
else {perror("Too bad I haven't implemented error checking yet");}
}
else {
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];
[clients addObject:csocket];
[delegate newClientJoined:csocket];
- return YES;
}
}
}
}
- return NO;
}
@end
\ No newline at end of file
}
@end
\ No newline at end of file