[NSHost currentHost] halts app for 2s on Leopard

  • Hi list,
    I've tracked why my app seems to halt for about 2s.

    Culprit is [NSHost currentHost] on Leopard (on Tiger that was fast).

    Does anybody know another way of getting the current host ip and name?

    Cheers
    Mark
  • On Nov 8, 2007, at 8:19 AM, Mark wrote:

    > Hi list,
    > I've tracked why my app seems to halt for about 2s.
    >
    > Culprit is [NSHost currentHost] on Leopard (on Tiger that was fast).
    >
    > Does anybody know another way of getting the current host ip and name?

    Confirmed here for 10.5.0 and 10.5.1. It also seems to involve a DNS
    lookup, and if there is a DNS problem, the delay will be a lot longer.

    In my code I replaced it with the code below. Note that it is not
    equivalent (read the applicable manual pages), but for many situations
    sufficient, and always fast.

    Gerd

    - (NSString *)currentHost {

    char  s[_POSIX_HOST_NAME_MAX+1];

    gethostname(s,_POSIX_HOST_NAME_MAX);

    return [NSString stringWithCString:s encoding:NSUTF8StringEncoding];
    }
  • I'd note that +NSString stringWithUTF8String: will do the same thing
    as your +NSString stringWithCString:encoding:, and goes back a lot
    further, old-OS-compatibility-wise.

    On Nov 17, 2007, at 10:02 AM, Gerd Knops wrote:

    >
    > On Nov 8, 2007, at 8:19 AM, Mark wrote:
    >
    >> Hi list,
    >> I've tracked why my app seems to halt for about 2s.
    >>
    >> Culprit is [NSHost currentHost] on Leopard (on Tiger that was fast).
    >>
    >> Does anybody know another way of getting the current host ip and
    >> name?
    >
    > Confirmed here for 10.5.0 and 10.5.1. It also seems to involve a
    > DNS lookup, and if there is a DNS problem, the delay will be a lot
    > longer.
    >
    > In my code I replaced it with the code below. Note that it is not
    > equivalent (read the applicable manual pages), but for many
    > situations sufficient, and always fast.
    >
    > Gerd
    >
    >
    > - (NSString *)currentHost {
    >
    > char        s[_POSIX_HOST_NAME_MAX+1];
    >
    > gethostname(s,_POSIX_HOST_NAME_MAX);
    >
    > return [NSString stringWithCString:s encoding:NSUTF8StringEncoding];
    > }
  • On 18/11/2007, at 4:02 AM, Gerd Knops wrote:

    > Confirmed here for 10.5.0 and 10.5.1. It also seems to involve a DNS
    > lookup, and if there is a DNS problem, the delay will be a lot longer.
    >
    > In my code I replaced it with the code below. Note that it is not
    > equivalent (read the applicable manual pages), but for many
    > situations sufficient, and always fast.

    In one of the earlier builds of Leopard, Xcode was stalling for maybe
    a minute at launch. When I profiled it, it turned out it was stalling
    on [NSHost currentHost] when it was registering for distributed builds.

    The stall only happened when I was disconnected from a network. It
    sounds like it's very likely that this problem is still there,
    although I have not experienced it in the release build.

    --
    Rob Keniger
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today