Index: src/IRCConnection.h ================================================================== --- src/IRCConnection.h +++ src/IRCConnection.h @@ -27,10 +27,12 @@ @class IRCUser; @protocol IRCConnectionDelegate @optional - (void)connection: (IRCConnection*)connection + didCreateSocket: (OF_KINDOF(OFTCPSocket)*)socket; +- (void)connection: (IRCConnection*)connection didReceiveLine: (OFString*)line; - (void)connection: (IRCConnection*)connection didSendLine: (OFString*)line; - (void)connectionWasEstablished: (IRCConnection*)connection; - (void)connection: (IRCConnection*)connection @@ -70,18 +72,20 @@ - (void)connectionWasClosed: (IRCConnection*)connection; @end @interface IRCConnection: OFObject { - OFTCPSocket *_socket; + Class _socketClass; + OF_KINDOF(OFTCPSocket) *_socket; OFString *_server; uint16_t _port; OFString *_nickname, *_username, *_realname; OFMutableDictionary *_channels; id _delegate; } +@property (assign) Class socketClass; @property (copy) OFString *server; @property (assign) uint16_t port; @property (copy) OFString *nickname, *username, *realname; @property (assign) id delegate; @property (readonly, retain) OFTCPSocket *socket; Index: src/IRCConnection.m ================================================================== --- src/IRCConnection.m +++ src/IRCConnection.m @@ -36,10 +36,11 @@ #import "IRCConnection.h" #import "IRCUser.h" @implementation IRCConnection +@synthesize socketClass = _socketClass; @synthesize server = _server, port = _port; @synthesize nickname = _nickname, username = _username, realname = _realname; @synthesize delegate = _delegate, socket = _socket; + (instancetype)connection @@ -50,10 +51,11 @@ - init { self = [super init]; @try { + _socketClass = [OFTCPSocket class]; _channels = [[OFMutableDictionary alloc] init]; _port = 6667; } @catch (id e) { [self release]; @throw e; @@ -79,11 +81,16 @@ void *pool = objc_autoreleasePoolPush(); if (_socket != nil) @throw [OFAlreadyConnectedException exception]; - _socket = [[OFTCPSocket alloc] init]; + _socket = [[_socketClass alloc] init]; + if ([_delegate respondsToSelector: + @selector(connection:didCreateSocket:)]) + [_delegate connection: self + didCreateSocket: _socket]; + [_socket connectToHost: _server port: _port]; [self sendLineWithFormat: @"NICK %@", _nickname]; [self sendLineWithFormat: @"USER %@ * 0 :%@", _username, _realname];