• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Compiler skipping code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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 readData:message] )
{
// Read until buffer is full
}

// Display response in context textview

strMsg = [[[NSString alloc] initWithData: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.

  • Follow-Ups:
    • Double clicking rows vs. column headers
      • From: Paul Ferguson <email@hidden>
    • Re: Compiler skipping code
      • From: Sherm Pendley <email@hidden>
  • Prev by Date: Re: NSQueue equivalent?
  • Next by Date: Cut & past support in NSTableView
  • Previous by thread: Re: NSLayoutManager question
  • Next by thread: Re: Compiler skipping code
  • Index(es):
    • Date
    • Thread