Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > "Too many open files - socket(2)" when invoking Socket.new

Reply
Thread Tools

"Too many open files - socket(2)" when invoking Socket.new

 
 
Clemens Wyss
Guest
Posts: n/a
 
      05-13-2009
Given the follwing code snippet:

require 'socket'
include Socket::Constants
socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
sockaddr = Socket.pack_sockaddr_in( 1313, 'localhost' )
socket.bind( sockaddr )
socket.listen( 5 )
client, client_sockaddr = socket.accept
client.puts "Hello from script one!"
puts "The client said, '#{client.readline.chomp}'"
client.puts "Hello from script one!"
socket.close

On my WinXP development machine this script runs as expected. Running it
on a WinXpEmbedded machine throws a
Too many open files - socket(2) (Errno::EMFILE)
exception on the line
socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
What could cause this exception?

Any advice help appreciated
Clemens
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Sandor Szücs
Guest
Posts: n/a
 
      05-16-2009

On 13.05.2009, at 16:41, Clemens Wyss wrote:

> Given the follwing code snippet:
>
>
> require 'socket'
> include Socket::Constants

begin
>
> socket =3D Socket.new( AF_INET, SOCK_STREAM, 0 )
> sockaddr =3D Socket.pack_sockaddr_in( 1313, 'localhost' )
> socket.bind( sockaddr )
> socket.listen( 5 )
> client, client_sockaddr =3D socket.accept
> client.puts "Hello from script one!"
> puts "The client said, '#{client.readline.chomp}'"
> client.puts "Hello from script one!"

ensure
>
> socket.close

end


Try to add these statements in your code and reboot your box,
then it should not happen.

> On my WinXP development machine this script runs as expected. =20
> Running it
> on a WinXpEmbedded machine throws a
> Too many open files - socket(2) (Errno::EMFILE)
> exception on the line
> socket =3D Socket.new( AF_INET, SOCK_STREAM, 0 )
> What could cause this exception?



Too many open files for your OS results in such an exception.

regards, Sandor Sz=FCcs
--=

 
Reply With Quote
 
 
 
 
Clemens Wyss
Guest
Posts: n/a
 
      05-18-2009
Dear Sandor,
I don't see why your exception handling code should be of any help. The
exception per se is the problem.

Why (on XP embedded only) do I get
Too many open files - socket(2) (Errno::EMFILE)
on the line
socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
?
Also: opening the very same port with a simple VB App works, even on XP
embedded...

Still any help/advice appreciated
Clemens

Sandor Szücs wrote:
> On 13.05.2009, at 16:41, Clemens Wyss wrote:
>
>> Given the follwing code snippet:
>>
>>
>> require 'socket'
>> include Socket::Constants

> begin
>>
>> socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
>> sockaddr = Socket.pack_sockaddr_in( 1313, 'localhost' )
>> socket.bind( sockaddr )
>> socket.listen( 5 )
>> client, client_sockaddr = socket.accept
>> client.puts "Hello from script one!"
>> puts "The client said, '#{client.readline.chomp}'"
>> client.puts "Hello from script one!"

> ensure
>>
>> socket.close

> end
>
>
> Try to add these statements in your code and reboot your box,
> then it should not happen.
>
>> On my WinXP development machine this script runs as expected.
>> Running it
>> on a WinXpEmbedded machine throws a
>> Too many open files - socket(2) (Errno::EMFILE)
>> exception on the line
>> socket = Socket.new( AF_INET, SOCK_STREAM, 0 )
>> What could cause this exception?

>
>
> Too many open files for your OS results in such an exception.
>
> regards, Sandor
> Sz�cs


--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Sandor Szücs
Guest
Posts: n/a
 
      05-18-2009

On 18.05.2009, at 07:39, Clemens Wyss wrote:

> I don't see why your exception handling code should be of any help. =20=


> The
> exception per se is the problem.


True, but I thought if you try to run your code and it doesn't close =20
the sockets,
then you get open files.... It's better to ensure the close operation.

regards, Sandor Sz=FCcs
--




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Winzip: which of the many many files do I click to install? dt4emails-websites2@yahoo.com Computer Support 3 11-11-2005 04:45 AM
many aspnet applications in one site? many Gloabal.asax files ok? dee ASP .Net 2 08-15-2005 03:07 AM
"java.io.IOException: Too many open files" rlim_fd_cur set to max Cathy Hui Java 6 03-04-2005 10:17 PM
Too many files open...? Kenneth Computer Support 5 10-30-2003 01:40 AM
(Too many open files) Collin VanDyck Java 5 10-14-2003 01:52 PM



Advertisments
 



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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57