Skip to content

Commit f69fa44

Browse files
committed
Fixing echo server
1 parent 2de0621 commit f69fa44

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

GCD/Xcode/EchoServer/EchoServerAppDelegate.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ - (id)init
4545
// Or we could use a dedicated dispatch queue, which could be helpful if we were doing a lot of processing.
4646
//
4747
// The best approach for your application will depend upon convenience, requirements and performance.
48-
//
49-
// For this simple example, we're just going to use the main thread.
48+
49+
socketQueue = dispatch_queue_create("socketQueue", NULL);
5050

5151
listenSocket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:socketQueue];
5252

@@ -204,6 +204,8 @@ - (void)socket:(GCDAsyncSocket *)sock didAcceptNewSocket:(GCDAsyncSocket *)newSo
204204

205205
- (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag
206206
{
207+
// This method is executed on the socketQueue (not the main thread)
208+
207209
if (tag == ECHO_MSG)
208210
{
209211
[sock readDataToData:[GCDAsyncSocket CRLFData] withTimeout:READ_TIMEOUT tag:0];
@@ -212,6 +214,8 @@ - (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag
212214

213215
- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
214216
{
217+
// This method is executed on the socketQueue (not the main thread)
218+
215219
dispatch_async(dispatch_get_main_queue(), ^{
216220
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
217221

0 commit comments

Comments
 (0)