Re: BSD socket accept() fd leak on iphone OS
Re: BSD socket accept() fd leak on iphone OS
- Subject: Re: BSD socket accept() fd leak on iphone OS
- From: Quinn <email@hidden>
- Date: Mon, 28 Sep 2009 10:03:43 +0100
At 15:08 -0700 25/9/09, Jay Bone wrote:
I was using NSFileHandle to open and write to a file but I wasn't
calling NSFileHandle 's -closeFile. (Calling this fixes my problem.)
Ah, NSFileHandle, one of my least favourite APIs (-:
With regards this problem, NSFileHandle will close the underlying
descriptor in two circumstances:
A. when you call -closeFile
B. when the NSFileHandle object is dealloc'd (or finalized in the GC case)
If you weren't calling -closeFile explicitly, you were probably
relying on B. That's not a great idea. In the GC case (admittedly
not relevant to you right now, but it's always a good idea to not
paint yourself into a corner), there can be a long delay before an
object is finalized. In the non-GC case, this approach turns a
memory leak into a descriptor leaks )-:
At 14:22 -0700 25/9/09, Jack Brindle wrote:
I would question this.
Matt Slot already covered this, but I thought I'd post the
theoretical background to his conclusion. Specifically, here's what
the Single UNIX Spec has to say about the shutdown flags:
SHUT_RD
Disables further receive operations.
SHUT_WR
Disables further send operations.
SHUT_RDWR
Disables further send and receive operations.
<http://www.opengroup.org/onlinepubs/009695399/functions/shutdown.html>
And while the SUS verbiage is kinda fuzzy on the specific behaviour
if you read from SHUT_RD socket, it's very clear about writing to a
SHUT_WR socket:
[EPIPE]
The socket is shut down for writing, or the socket is
connection-mode and is no longer connected. [...]
<http://www.opengroup.org/onlinepubs/009695399/functions/send.html>
At 13:01 -0700 25/9/09, Jay Bone wrote:
How will lsof help?
lsof would have found this very quickly. You would've seen a whole
bunch of descriptors lying around inside your process, all of which
were attached to your log file.
At 13:01 -0700 25/9/09, Jay Bone wrote:
How would I use dtrace to debug this socket issue?
DTrace comes into play when the problems get really hard. In this
case you found the problem quickly,
At 13:01 -0700 25/9/09, Jay Bone wrote:
Do you know of any Apple iPhone Example code which creates a simple
Hello World type web server? I'd prefer a BSD API based example /
solution, but if I must I'll go to the higher layer CFStream stuff
if I have to. At this point, anything that works would be helpful :(
Apple sample code typically focuses on Apple specific technologies,
so we don't ship any vanilla sockets samples.
With regards the higher-level frameworks, which is what we generally
recommend you use, the typically place that folks start is:
<http://developer.apple.com/mac/library/samplecode/CocoaHTTPServer/>
S+E
--
Quinn "The Eskimo!" <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden