Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

Multiple socket server

Altera_Forum
Honored Contributor II
944 Views

Hi everyone! 

I a Nios newbie, so I'm sorry if I'm asking any FAQ, but I can't find any information on the subject. 

 

I want to build a multiport socket server 

For example, imagine server which allows 3 connections: 

- port 23 which is a simple telnet terminal 

- port 6 which echoes back everything 

- port 1024 which bridges data to and from a serial port 

I started with the simple_server_socket template. 

Everything works fine as long as I listen only one of the above ports. If more than a port is listening, only the one whose task has higher priority will work; the others seems to connect but no data is transferred; then after a while a get a stream of "No free buffers for rx " error messages from the jtag debug port. 

 

Another issue I have is on connection closing. 

If the server closes it, there no problem and my client can reconnect. 

If the client closes the connection, the server doesn't recognize it and remain in a connected state. If I try to reconnect I get the same behaviour and errors as described above with a multiple connection. 

 

Thank you for any help 

Regards
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
258 Views

Further information: 

The problems arises when I call select() for both sockets, waiting for a connection. 

The higher priority one works 

The lower priority one connects (the client is connected) but select() doesn't return and the data actually is not accepted. 

I tried to set the select() call non blocking (zero timeout) and inserting a TK_SLEEP() after it, as suggested in a previous post, but select() still blocks. 

 

Any ideas? 

 

On the other hand I solved the problem with connection closing: recv() was not tested for zero return values, indicating that the client closed the connection.
0 Kudos
Altera_Forum
Honored Contributor II
258 Views

I'd check your code against what is done in an enhanced version of the example that you used: 

 

http://nioswiki.com/exampledesigns/simplesocketserverplus 

 

Also, the following looks _exactly_ like the issue that you're seeing: 

 

http://www.altera.com/support/kdb/solutions/rd11062009_597.html 

 

Cheers, 

 

- slacker
0 Kudos
Altera_Forum
Honored Contributor II
258 Views

Actually I had understood there was some sort of problem with the select() function, so I solved the problem with a non-blocking call and forcing a sleep if there's no data available from the socket. 

i.e. : 

if (select(max_socket, &readfds, NULL, NULL, &tout) <= 0) { 

TK_SLEEP(5); 

continue; 

 

with a zero tout. 

Now I will look at the patch you suggested which is probably better. 

Thank you for your help Slacker.
0 Kudos
Reply