Skip to main content
PChri.2
Associate
August 1, 2021
Question

O_NONBLOCK is defined twice and does not work with lwIP

  • August 1, 2021
  • 7 replies
  • 2227 views

The define O_NONBLOCK exists twice.

Once in:

...\ST\STM32CubeIDE_1.6.0\STM32CubeIDE\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.9-2020-q2-update.win32_2.0.0.202105311346\tools\arm-none-eabi\include\sys\_default_fcntl.h:

#define	_FNONBLOCK	0x4000	/* non blocking I/O (POSIX style) */
....
#define	O_NONBLOCK	_FNONBLOCK

and at in:

<ProjectFolder>\Middlewares\Third_Party\LwIP\src\include\lwip\sockets.h:

#ifndef O_NONBLOCK
#define O_NONBLOCK 1 /* nonblocking I/O */
#endif

Now a call like this fails:

fcntl(socket_handle, F_SETFL, fcntl(socket_handle, F_GETFL, 0) | O_NONBLOCK);

as the define in _default_fcntl.h is not compatible with lwIP.

Please remove this define in _default_fcntl.h

This topic has been closed for replies.

7 replies

Pavel A.
August 1, 2021

The question is, how the _default_fcntl.h gets incuded into your program?

And why it doesn't get included into LwIP? (as LwIP usually is compiled from sources, along with your files).

Note the #ifndef O_NONBLOCK.

-- pa

PChri.2
PChri.2Author
Associate
August 3, 2021

Hi Pavel

The includes in my source file are:

#include "lwip/opt.h"
#include "lwip/arch.h"
#include "lwip/api.h"
#include "lwip/apps/fs.h"
#include "lwip/sockets.h"
#include "FreeRTOS.h"
#include "task.h"

and the in STM32CubeIDE project there are these includes:

0693W00000D1Rk5QAF.pngPeter

PChri.2
PChri.2Author
Associate
August 7, 2021

Hi Pavel

I have some additional informations for you.

The basis for my project is the example application "LwIP_HTTP_Server_Netconn_RTOS" from STM Cube V1.6.0.

There for I had a deeper look there and have seen how the _default_fcntl.h gets incuded into my program. It comes via the includes in the project:

0693W00000D1oKeQAJ.png0693W00000D1oJIQAZ.png 

Please check this.

Kind regards Peter

Pavel A.
August 8, 2021

Then ok, the _default_fcntl.h comes from the toolchain includes. Normally this is included via fcntl.h.

Just make sure that LwIP source files are cofigured so that fcntl.h from the toolchain gets included, and #ifndef O_NONBLOCK is false.

PChri.2
PChri.2Author
Associate
August 9, 2021

Hi Pavel

In my current project I have solved it by adding an #undef for O_NONBLOCK  before socket.h is included:

#undef O_NONBLOCK			/* in _default_fcntl.h defined as 0x4000, but lwip defines 1 in sockets.h */
....
#include "lwip/sockets.h"
...

As this problem comes from example application "LwIP_HTTP_Server_Netconn_RTOS" from STM Cube V1.6.0 which I used a basis for my project I like to provide a feedback the team who manages the STM Cube code. This should be fixed.

Pavel A.
August 9, 2021

The team who manages the STM Cube code probably doesn't want to touch the newlib stuff in the toolchain because of some 3rd party library ... but who knows.

PChri.2
PChri.2Author
Associate
August 10, 2021

Lets try, in my eyes this is an error and I lost several hours to fix it. Unfortunately I commented out firstly this line in _default_fcntl.h. After an update this was lost and the problem was back...

Do you know where I can provide this feedback to the STM Cube team?