Compiler skipping code
Compiler skipping code
- Subject: Compiler skipping code
- From: Daniel Byer <email@hidden>
- Date: Tue, 19 Feb 2002 20:08:50 -0600
I was having some major problems with creating a separate thread so I
can have a socket application (somehow a while() loop doesn't do too
well in a single threaded application...), and am using code from
smallsockets.
When debugging my application, the compiler completely skips over this
line of code, not even executing it:
[[[NSThread alloc] init]
detachNewThreadSelector:@selector(threadCommunicate:) toTarget:self
withObject:nil];
This supposedly calls the threadCommunicate method, which continuously
reads data from the socket:
// This code copied and modified from the ServerController class, part
of the BufferedSocket example application,
// part of the SmallSockets project.
// Created by Rainer Kupke (email@hidden) on Thu Jul 26 2001.
// Copyright (c) 2001 Rainer Kupke.
- (void)threadCommunicate:(Socket*)sock
{
NSAutoreleasePool *apool = [[NSAutoreleasePool alloc] init];
NSMutableData *message;
NSString *strMsg;
NS_DURING // I don't even know what this is, but it works for the
original program, so I keep it.
while( [socket isConnected] )
{
NSAutoreleasePool *apool = [[NSAutoreleasePool alloc] init];
message = [[[NSMutableData alloc] init] autorelease];
if ( !message )
break;
strMsg = @"";
while ( [socket read
Data:message] )
{
// Read until buffer is full
}
// Display response in context textview
strMsg = [[[NSString alloc] initWith
Data:message
encoding:[NSString defaultCStringEncoding]] autorelease];
[messageReceived setString:strMsg]; // messageReceived
is NSTextView
[apool release];
}
NS_HANDLER
NSLog([NSString stringWithFormat: @"Exception in
threadCommunicate: %@",[localException reason]]);
NS_ENDHANDLER
[apool release];
}
Now, I'm also pretty sure I need a Connection in here to connect the
threads, but I doubt that'd cause the compiler to just skip that line of
code.
Thanks in advance for any suggestions!
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.