|
From: Stephen S. <rad...@gm...> - 2008-12-24 02:27:18
|
On Tue, Dec 23, 2008 at 4:46 PM, Steve Harris <S.W...@ec...> wrote: > On 23 Dec 2008, at 19:03, Stephen Sinclair wrote: > >> On Sun, Dec 21, 2008 at 3:17 AM, Kentaro Fukuchi >> <fu...@me...> wrote: >>> Hi Steve, >>> >>> It's really nice to have a keep-alive TCP connection of OSC server. >>> >>> On Wed, 17 Dec 2008 15:59:58 -0500 >>> "Stephen Sinclair" <rad...@gm...> wrote: >>> >>>> So that tells me it might be better to leave them open, so I tried >>>> this. It worked for a single connection, by adding a >>>> "connected_socket" member to the lo_server structure, and polling >>>> that >>>> instead of the "socket" member. However, I quickly realized that >>>> this >>>> would mean that lo_server would need a data structure to track _all_ >>>> open sockets. >>> >>> Common server programs using TCP have the same data structure to >>> track them. >>> For blocking server, you can use select() system call. >> >> Exactly, it's already using select() for Windows and poll() for *nix, >> so it should be fairly easy to support this. I already started >> working on a patch but it's not ready yet. So far I'm using a linked >> list to keep the socket information, but I'm trying to decide if this >> approach is more complex than necessary. >> >> Maybe Steve H. can tell me, but I'm not actually sure what advantage >> poll() has over select(), actually. > > Not really my field, but I used to work without shouting distance of a > load of network research people, I asked them and they said "use > poll(), it's better" or words to that effect :) > > I vaguely remember that select is only efficient with a small number > of sockets/FDs. Hmm.. :) Interesting, I personally haven't used poll before at all. I looked into it, as I got curious. It looks like select() is basically limited in number of sockets because it uses a bitmask. Looks like it wasn't necessary before, but if I'm to maintain a list of sockets it works well. I can probably save some coding by using an array instead of a linked list and pass it in directly. (I was trying to avoid shuffling array items around, but now that I think about it, it's probably a lot more efficient to shuffle an array when connections are removed, than to build it from a list every time lo_server_recv() is called.) I think for portability I might change it to use autoconf to detect poll() and use it, instead of just assuming it is there on non-Windows systems. Steve |