• 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
Re: straight-C DNS lookup with timeout?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: straight-C DNS lookup with timeout?


  • Subject: Re: straight-C DNS lookup with timeout?
  • From: Philip George <email@hidden>
  • Date: Thu, 2 Jan 2003 04:18:14 -0600

Not sure. I just hit the hammer icon in Project Builder. :)

Where's your .m file? I'm calling the functions from an Objective-C method in a Cocoa app. That's the problem. When I put the code into a straight-C app, it works like a champ.

Here's the code:

void handle_sigalrm(int signal_number) {
siglongjmp(timeout_env, signal_number);
}

int dns_function(unsigned int timeout) {
int x;
if (sigsetjmp(timeout_env, 0) != 0) {
errno = ETIMEDOUT;
return 0;
}
if (signal(SIGALRM, handle_sigalrm) == SIG_ERR) {
return 0;
}
(void)alarm(timeout);
mydnshost = gethostbyaddr((const void*)&MYaddr, sizeof(struct in_addr), AF_INET);
(void)alarm(0);
return 0;
}

- (NSString *)DNSLookup:(NSString *)string {
inet_aton([string cString], &MYaddr);
dns_function(3);
if (mydnshost && (mydnshost->h_name)) {
return [NSString stringWithCString:mydnshost->h_name];
} else {
return @"n/a";
}
}



On Tuesday, December 31, 2002, at 06:58 AM, Andrew wrote:

On Tue, 31 Dec 2002, Philip George wrote:

Thanks, Andrew. The code you linked to works perfectly in a 100% C
app. However, if i call it from Obj-C, it fails with signal 10, if and
only if the alarm function gets called.

It seems to work for me...how are you compiling it?

gcc -Wall -x objective-c longjmp.c -lobjc

Andrew
_______________________________________________
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.
_______________________________________________
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:
    • Re: straight-C DNS lookup with timeout?
      • From: Andrew <email@hidden>
  • Prev by Date: Re: [basic] retain an NSTextView object and update a window
  • Next by Date: drawing custom button in cocoa
  • Previous by thread: Re: Icon in NSOutlineView
  • Next by thread: Re: straight-C DNS lookup with timeout?
  • Index(es):
    • Date
    • Thread