#import <Foundation/Foundation.h>
+#import "ThreadSafeDeleage.h"
+
@protocol MessageQueueDelegate;
// MessageQueue operates a listening socket, that is connected to another
NSMutableArray* _queue;
// The delegate for this class.
- id<MessageQueueDelegate> _delegate;
+ ThreadSafeDeleage<MessageQueueDelegate>* _delegate;
// The socket that listens for new incoming connections.
CFSocketRef _socket;
if ((self = [super init])) {
_port = port;
_queue = [[NSMutableArray alloc] init];
- _delegate = delegate;
+ _delegate = (ThreadSafeDeleage<MessageQueueDelegate>*)
+ [[ThreadSafeDeleage alloc] initWithObject:delegate
+ protocol:@protocol(MessageQueueDelegate)
+ thread:[NSThread currentThread]
+ modes:@[ NSDefaultRunLoopMode ]];
}
return self;
}
- (void)dealloc {
[_queue release];
+ [_delegate release];
[super dealloc];
}
if (![_queue count])
return;
- if (![_delegate shouldSendMessage])
+ if (![(id<MessageQueueDelegate>)_delegate.object shouldSendMessage])
return;
if (!CFWriteStreamCanAcceptBytes(_writeStream))