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: Jay Bone <email@hidden>
- Date: Fri, 25 Sep 2009 13:01:39 -0700
Thank you for the reply.
On Fri, Sep 25, 2009 at 3:11 AM, Quinn
<email@hidden> wrote:
I'm trying to write a simple "Hello
World" type web server using BSD sockets. When I compile and run
this code on a linux box it behaves as I expect, close()'ed file
descriptors originally returned from accept() calls are re-used
on subsequent connections.
When I run this same code on an iPhone, close()'ed fd's are not reused
and accept() calls continue to return higher and higher fd's until it
reaches around 256 and at that point the application locks up.
Is the following code not correct? What am I missing? (Some
error handling omitted)
That's weird. I can't see anything in your code that would
cause this problem. What does it do on the simulator? [If
you get the same problem on the simulator you can apply better tools
to debug it, namely <x-man-page://8/lsof> and
<x-man-page://1/dtrace>.]
I don't have handy access to the simulator at the moment. But when I do I will try.
How will lsof help?
On the device I get the following. Does lsof not work on the device?
iPod:~ root# lsof -p 493
lsof: PID 500 information error: Cannot allocate memory
lsof: PID 493 information error: Cannot allocate memory
lsof: PID 486 information error: Cannot allocate memory
lsof: PID 483 information error: Cannot allocate memory
lsof: PID 482 information error: Cannot allocate memory
lsof: PID 478 information error: Cannot allocate memory
lsof: PID 477 information error: Cannot allocate memory
lsof: PID 447 information error: Cannot allocate memory
lsof: PID 400 information error: Cannot allocate memory
lsof: PID 46 information error: Cannot allocate memory
lsof: PID 31 information error: Cannot allocate memory
lsof: PID 29 information error: Cannot allocate memory
lsof: PID 24 information error: Cannot allocate memory
lsof: PID 23 information error: Cannot allocate memory
lsof: PID 22 information error: Cannot allocate memory
lsof: PID 21 information error: Cannot allocate memory
lsof: PID 18 information error: Cannot allocate memory
lsof: PID 17 information error: Cannot allocate memory
lsof: PID 16 information error: Cannot allocate memory
lsof: PID 15 information error: Cannot allocate memory
lsof: PID 13 information error: Cannot allocate memory
lsof: PID 1 information error: Cannot allocate memory
How would I use dtrace to debug this socket issue?
btw I'm confused by the following:
if( shutdown(connected, SHUT_RDWR) == -1 )
{
// Error
}
// Read rest of packets...
while(1)
{
int bytes = recv(
connected, recv_data, BUFF_SIZE, 0 );
[...]
}
Given that you've shut down the socket for both read and write,
the recv is guaranteed to fail, right?
Hm. Right I guess. I only added this shutdown() and this while(1) { read-rest-of-packets } code after googling for code on closing sockets and trying to debug this fd issue.
Originally I was just calling close() and thinking that would be enough.
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 :(
-J
_______________________________________________
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
_______________________________________________
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