File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -45,8 +45,8 @@ - (id)init
45
45
// Or we could use a dedicated dispatch queue, which could be helpful if we were doing a lot of processing.
46
46
//
47
47
// 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 );
50
50
51
51
listenSocket = [[GCDAsyncSocket alloc ] initWithDelegate: self delegateQueue: socketQueue];
52
52
@@ -204,6 +204,8 @@ - (void)socket:(GCDAsyncSocket *)sock didAcceptNewSocket:(GCDAsyncSocket *)newSo
204
204
205
205
- (void )socket : (GCDAsyncSocket *)sock didWriteDataWithTag : (long )tag
206
206
{
207
+ // This method is executed on the socketQueue (not the main thread)
208
+
207
209
if (tag == ECHO_MSG)
208
210
{
209
211
[sock readDataToData: [GCDAsyncSocket CRLFData ] withTimeout: READ_TIMEOUT tag: 0 ];
@@ -212,6 +214,8 @@ - (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag
212
214
213
215
- (void )socket : (GCDAsyncSocket *)sock didReadData : (NSData *)data withTag : (long )tag
214
216
{
217
+ // This method is executed on the socketQueue (not the main thread)
218
+
215
219
dispatch_async (dispatch_get_main_queue (), ^{
216
220
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc ] init ];
217
221
You can’t perform that action at this time.
0 commit comments