Boost logo

Boost Users :

Subject: Re: [Boost-users] *NIX: Boost ASIO and file descriptor limits
From: Etienne Philip Pretorius (icewolfhunter_at_[hidden])
Date: 2008-10-04 11:43:11


Thank you Boris,

I have been using strace to track what is being called by the boost asio
libraries, and in my 2.6 kernel it is epoll.

getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM_INFINITY}) = 0
uname({sys="Linux", node="etienne-laptop", ...}) = 0
futex(0xb7f46674, 0x81 /* FUTEX_??? */, 2147483647) = 0
futex(0xb7f4b700, 0x81 /* FUTEX_??? */, 2147483647) = 0
brk(0) = 0x805c000
brk(0x807d000) = 0x807d000
epoll_create(20000) = 3
pipe([4, 5]) = 0
fcntl64(4, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
fcntl64(5, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
epoll_ctl(3, EPOLL_CTL_ADD, 4, {EPOLLIN|EPOLLERR, {u32=4, u64=4}}) = 0
socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP) = 6
epoll_ctl(3, EPOLL_CTL_ADD, 6, {0, {u32=6, u64=6}}) = 0
setsockopt(6, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
bind(6, {sa_family=AF_INET6, sin6_port=htons(1234), inet_pton(AF_INET6,
"::", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28) = 0
listen(6, 128) = 0
ioctl(6, FIONBIO, [1]) = 0
accept(6, 0, NULL) = -1 EAGAIN (Resource
temporarily unavailable)
epoll_ctl(3, EPOLL_CTL_MOD, 6, {EPOLLIN|EPOLLERR|EPOLLHUP, {u32=6,
u64=6}}) = 0
mmap2(NULL, 8392704, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0xb74ce000
mprotect(0xb74ce000, 4096, PROT_NONE) = 0
clone(child_stack=0xb7cce4b4,
flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID,
parent_tidptr=0xb7ccebd8, {entry_number:6, base_addr:0xb7cceb90,
limit:1048575, seg_32bit:1, contents:0, read_exec_only:0,
limit_in_pages:1, seg_not_present:0, useable:1},
child_tidptr=0xb7ccebd8) = 15388
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0

The limit unfortunately still applies.

I am using a shell script to test this on the Ubuntu distro:

for ((i=0;i<1024;i++)) do echo $i; `nc -n -w 1 127.0.0.1 1234 & `; done

In the code I output an error when the accept failes:

void server::accept(
     client* connection,
     const asio::error_code& ec
) {

     if(!ec) {
         client_.push_back(connection);
     }else{
         //TODO: say why the connection failed
         delete connection;
         std::cout << ec.message() << std::endl;
         ::exit(0);
     }
     accept();

};//accept

The returned error message is:
Too many open files


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net