Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
12409 Discussions

how to handle correctly timeouts using ethernet

Altera_Forum
Honored Contributor II
784 Views

Dear All,  

 

I have a design using CycIII full board from altera. This is running ethernet task which is direct copy of the simple server example. 

 

On the other side I run python stuff to communicate with the device using packets: i send sort of packet, receve back and so on. 

 

the problem I have is, that sometimes my python stuff gets stucked and freezes the connection. typically if it raises some error, and I do not call close(fd) to close the socket, and next time it creates again a new socket and tries to bind it. 

 

As the simple socket server has only one incoming connection enabled, such behaviour of python script basically denies other connections as inside the nios the descriptor is still allocated and it does not allow to create another connection/ 

 

What is a typical solution to this problem? 

 

thanks  

 

.d.
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
119 Views

What you need in this case is to call accept() in your Nios application again, even when the socket isn't closed. 

Typically this could be done with multithreading. Each time accept() returns, you create a new thread to answer on the created socket, and then immediately call back accept() in the main thread. 

The main problem is that resource usage will increase each time a new connection is made, so you should find a way to close unused sockets and kill their respective threads. 

 

It is also possible to do it in a single thread by using select() to listen on several sockets and accepting new connections simultaneously. But in my experience select() doesn't work very well with ucOS II and the Interniche TCP/IP stack.
Altera_Forum
Honored Contributor II
119 Views

well, today I've found altera web server application for NIOS, which is using the second method you mentioned. it seems to be fairly easy to use the bits of code in my application. I'll try this approach first and will see. If it does not work on satisfactory level, I try the 'accept' approach in multithread.....

Altera_Forum
Honored Contributor II
119 Views

to finish this story: at the end I use select with timeout and watch over the communication on specific file descriptors. when > timeout, I close it. This seems to be working very reasonably.  

 

thanks for help
Reply