IRCConnection: Make the socket class configurable

This makes using TLS possible.

FossilOrigin-Name: 38de3de8ed2056e1116492cc44443d814ff115d85b81ba5c9014d0bf925a0f83
This commit is contained in:
Jonathan Schleifer 2017-01-22 17:24:17 +00:00
parent 47e0929527
commit 21784a8d30
2 changed files with 13 additions and 2 deletions

View file

@ -28,6 +28,8 @@
@protocol IRCConnectionDelegate <OFObject> @protocol IRCConnectionDelegate <OFObject>
@optional @optional
- (void)connection: (IRCConnection*)connection
didCreateSocket: (OF_KINDOF(OFTCPSocket)*)socket;
- (void)connection: (IRCConnection*)connection - (void)connection: (IRCConnection*)connection
didReceiveLine: (OFString*)line; didReceiveLine: (OFString*)line;
- (void)connection: (IRCConnection*)connection - (void)connection: (IRCConnection*)connection
@ -72,7 +74,8 @@
@interface IRCConnection: OFObject @interface IRCConnection: OFObject
{ {
OFTCPSocket *_socket; Class _socketClass;
OF_KINDOF(OFTCPSocket) *_socket;
OFString *_server; OFString *_server;
uint16_t _port; uint16_t _port;
OFString *_nickname, *_username, *_realname; OFString *_nickname, *_username, *_realname;
@ -80,6 +83,7 @@
id <IRCConnectionDelegate> _delegate; id <IRCConnectionDelegate> _delegate;
} }
@property (assign) Class socketClass;
@property (copy) OFString *server; @property (copy) OFString *server;
@property (assign) uint16_t port; @property (assign) uint16_t port;
@property (copy) OFString *nickname, *username, *realname; @property (copy) OFString *nickname, *username, *realname;

View file

@ -38,6 +38,7 @@
#import "IRCUser.h" #import "IRCUser.h"
@implementation IRCConnection @implementation IRCConnection
@synthesize socketClass = _socketClass;
@synthesize server = _server, port = _port; @synthesize server = _server, port = _port;
@synthesize nickname = _nickname, username = _username, realname = _realname; @synthesize nickname = _nickname, username = _username, realname = _realname;
@synthesize delegate = _delegate, socket = _socket; @synthesize delegate = _delegate, socket = _socket;
@ -52,6 +53,7 @@
self = [super init]; self = [super init];
@try { @try {
_socketClass = [OFTCPSocket class];
_channels = [[OFMutableDictionary alloc] init]; _channels = [[OFMutableDictionary alloc] init];
_port = 6667; _port = 6667;
} @catch (id e) { } @catch (id e) {
@ -81,7 +83,12 @@
if (_socket != nil) if (_socket != nil)
@throw [OFAlreadyConnectedException exception]; @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 [_socket connectToHost: _server
port: _port]; port: _port];