diff options
author | IOhannes m zmölnig <zmoelnig@users.sourceforge.net> | 2010-09-13 13:48:13 +0000 |
---|---|---|
committer | IOhannes m zmölnig <zmoelnig@users.sourceforge.net> | 2010-09-13 13:48:13 +0000 |
commit | 2be21576e46acf6b22c2c4d4191b2ccc9e6671f6 (patch) | |
tree | f053c3eb190a3364c648f0099fb2c2d315a73674 | |
parent | b5379aacb64fa7ec66a0f7a98f35b550d4f4e95b (diff) |
more DEBUG; alternative algorithm to add clients
with a connection-less protocol it's a bit hard to know which clients are
connected to a server...
svn path=/trunk/externals/iem/iemnet/; revision=14114
-rw-r--r-- | udpserver.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/udpserver.c b/udpserver.c index 4bf6dee..e147b00 100644 --- a/udpserver.c +++ b/udpserver.c @@ -173,7 +173,6 @@ static int udpserver__find_sender(t_udpserver*x, unsigned long host, unsigned s static t_udpserver_sender* udpserver_sender_add(t_udpserver*x, unsigned long host, unsigned short port ) { - int id=-1; if(!x->x_accept)return NULL; @@ -181,6 +180,18 @@ static t_udpserver_sender* udpserver_sender_add(t_udpserver*x, id=udpserver__find_sender(x, host, port); DEBUG("%X:%d -> %d", host, port, id); if(id<0) { +#if 1 + /* since udp is a connection-less protocol we have no way of knowing the currently connected clients + * the following 3 lines assume, that there is only one client connected (the last we got data from + */ + id=0; + udpserver_sender_free(x->x_sr[id]); + x->x_sr[id]=udpserver_sender_new(x, host, port); +#else + /* this is a more optimistic approach as above: + * every client that we received data from is added to the list of receivers + * the idea is to remove the sender, if it's known to not receive any data + */ id=x->x_nconnections; /* an unknown address! add it */ if(id<MAX_CONNECT) { @@ -191,8 +202,9 @@ static t_udpserver_sender* udpserver_sender_add(t_udpserver*x, // oops, no more senders! id=-1; } +#endif } - + DEBUG("sender_add: %d", id); if(id>=0) { return x->x_sr[id]; } @@ -545,7 +557,9 @@ static void udpserver_receive_callback(void *y, t_iemnet_chunk*c) { if(c) { int conns = x->x_nconnections; + DEBUG("add new sender from %d", c->port); t_udpserver_sender*sdr=udpserver_sender_add(x, c->addr, c->port); + DEBUG("added new sender from %d", c->port); if(sdr) { udpserver_info_connection(x, sdr); x->x_floatlist=iemnet__chunk2list(c, x->x_floatlist); // gets destroyed in the dtor |