sockets and file open number

Asked by Criteria

Hello
i'm in the process of creating a chat software i've created a class to semplify the socket managment, in noneblocking mode
i stuck to the max file open 1024 i changed the FD_SETSIZE to 2048 with no luck
tried ulimit -n 2048
with no luck.
i use g++ 4.x.x
after 1024 the system accept gives a message " too many open files"
when i changed FD_SETSIZE to 2048
the system hang and refuse to accept more than 1028 connection
there is one listener thread

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
Criteria
Solved:
Last query:
Last reply:
Revision history for this message
Simone Cianfriglia (crimer) said :
#1

I think you know that you need root privileges to increase limits over hard limit.....
Then paste here the output of 'cat /proc/sys/fs/file-nr' if you need help, but you could know it, maybe ;)

Revision history for this message
Criteria (mohamed-adly) said :
#2

i have root privileges
the output is
'cat /proc/sys/fs/file-nr'
6176 0 204386

Regards

Revision history for this message
Simone Cianfriglia (crimer) said :
#3

Your system can handle a maximum of 204386 opened file descriptors, but every process can only open a smaller number of FD... with ulimit you're telling to increase the soft limit, but the hard limit blocks you.

Edit /etc/security/limits.conf adding at the end the following line:
<username> hard nofile <value>, change <username> and <value> with your own values then reboot :)

Revision history for this message
Criteria (mohamed-adly) said :
#4

well thats hard coded 2048 in the ulimits entry
the connection passed the number 1028
the system crashed totally at 1094 connection
with message "Bad file descriptor"

Regards

Revision history for this message
Simone Cianfriglia (crimer) said :
#5

The message provided, "Bad file descriptor", is quite general... it could be related to a series of problems. What's the last instruction executed by your application? Is it the accept one, or select/poll or anything else?

Revision history for this message
Criteria (mohamed-adly) said :
#6

it came from the Select() function

if(select(this->fdmax+1,&read_fds,null.null.null)==-1)
 {
    perror("select error:");
   exit(1); ------> this is what caused the system to exit. i think it did not crash
 }

Revision history for this message
Simone Cianfriglia (crimer) said :
#7

You have the same problem if you use 'poll'?

Revision history for this message
Criteria (mohamed-adly) said :
#8

hello
i tries the poll method and it wasnt all good
i got it now runing using the epoll method

thanks
Regards