TcpServerSocket blocking ::Accept

28 views
Skip to first unread message

Vojtěch Frič

unread,
Jul 21, 2013, 5:55:19 PM7/21/13
to lib...@googlegroups.com
Hi,
is there any way to make Accept in TcpServerSocket blocking? I don't really see an advantage when it's non-blocking.

I can easily fix this, by tinkering with your code, but I would like to know, if there is something I missed.

Thanks,
vf

Ivan Gagis

unread,
Jul 22, 2013, 7:17:35 AM7/22/13
to lib...@googlegroups.com
Hi,

there is an advantage of non-blocking behaviour. Normally, you should use it along with WaitSet, so you could wait for incoming connections and some other events at the same time.

But if you really need blocking behaviour, you can achieve it using WaitSet like this:

TCPServerSocket s;
s.Open(...);
...
ting::WaitSet ws(1);
ws.Add(s, ting::Waitable::READ);
...
ws.Wait();
if(s.CanRead()){
    TCPSocket sock = s.Accept();
    ...
}else{
    //error happened
    ...
}
...
ws.Remove(s);


--
Ivan


понедельник, 22 июля 2013 г., 0:55:19 UTC+3 пользователь Vojtěch Frič написал:

Vojtěch Frič

unread,
Jul 22, 2013, 8:07:07 AM7/22/13
to lib...@googlegroups.com
Great that's exactly what I need. I want main thread to block, until there is new connection, and after accepting the new connection, I will take care of the new connection in other thread.

Dne pondělí, 22. července 2013 13:17:35 UTC+2 Ivan Gagis napsal(a):
Reply all
Reply to author
Forward
0 new messages