edmessage
edmessage copied to clipboard
APIs block forever.
I'm trying out the API, but it can't get past the first line:
EDMailAgent *mailAgent = [EDMailAgent mailAgentForRelayHostWithName:@"smtp.me.com"];
It seems that it blocks inside of [NSHost currentHost] for ages.
According to this: http://www.mail-archive.com/[email protected]/msg43541.html
People should avoid [NSHost currentHost] like the plague. It would be good if someone could figure out why this is called and find a more appropriate API.
From having a brief look at it, this problem seems completely unnecessary. It looks to me like if you set host and port, everything is fine. But if you set only host, it first calls no parameter init which sets the current host as the relay, and then changes the relay to be the other host. The solution is just add another init method that takes a host so that it doesn't unnecessarily set the current host as relay first.
OK, looks like the problem also occurs when setting host and port. But solution should be the same. Calls to NSHost currentHost are completely unnecessary since they are immediately overwritten with calls to setRelayHostByName:, and since currrentHost is a VERY slow API, taking multiple minutes to complete, it should be avoided.
Suggested fix: remove line setting host in init and add it to getter:
- (id)init { [super init]; // relayHost = [[NSHost currentHost] retain]; port = 25; return self; }
- (NSHost *)relayHost { if (nil == relayHost) { relayHost = [[NSHost currentHost] retain]; } return relayHost; }
Looks like there are also two most instances where the super slow currentHost api is used, in sayEHLO and sayHELO. I tried also using SCDynamicStoreCopyLocalHostName(NULL), but for me at least this API is returning NULL.
My suggestion is to use the following code instead:
-(NSString *)getHostName; {
char hname[_POSIX_HOST_NAME_MAX+1];
if (gethostname(hname, _POSIX_HOST_NAME_MAX)
Err.. why is this issue now closed?
No idea. Re-opened it. Weird.