Forum Discussion
Altera_Forum
Honored Contributor
21 years agoSetting a LWIP Non Blocking Socket
Hi,
Has anyone come a cross an issue with setting a non-blocking socket in LWIP. I did the following: if ((pNetworkManager->fd_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) { die_with_error("CreateSocketTask: Socket creation failed"); } u32_t on = 1; if (lwip_ioctl(pNetworkManager->fd_socket, FIONBIO, &on)) { close(pNetworkManager->fd_socket); } ... which appears to be supported by LWIP but my socking is still blocking. Any ideas or thoughts would be greatly appreciated.1 Reply
- Altera_Forum
Honored Contributor
I am not sure if you can create a socket that is non-blocking per se (I am not a sockets expert), but I do know you can to send() and recv() non-blocking; the data is just posted to the stack and gets sent later, or in the case of recv(), you get back an error if nothing (or less than your desired number of bytes) was received.
Check out the web_server example design, http.c, and look at how sends and receives are done. This example shows non-blocking I/O so that multiple web clients can be served at the same time.