-
Notifications
You must be signed in to change notification settings - Fork 27
Library exits on "socket 0" error #9
Description
The FreeRTOS and c-version of the library abort with exit() when
srv->sock = socket(AF_INET, SOCK_STREAM, 0);
if(srv->sock <= 0) exit(1);
returns with srv->sock == 0.
Socket 0 is a perfectly valid socket descriptor. Only negative numbers indicate an error.
In an full-scale OS environment descriptor 0 is usually reserved for stdin. However, in a bare-metal embedded environment, e.g. when using lwip, "0" is just the first socket to be created.
The libraries are also using "exit()" for any errors. That is not ideal for a library - as it kills the entire application. It would be better to just "return".
I'm attaching a pull request with two commits. The first commit just fixes the "socket 0" issue. The second is a suggestion to also avoid the use of "exit()" in a library.
(Btw, just if you are interested: :) the "exit() on socket 0" issue was detected in the firmware of the new Commodore 64 Ultimates, which uses your MicroHttpServer. Depending on configuration, users can "brick" devices, as the firmware exits/no longer boots when lwip returns "socket 0" to MicroHttpServer, see GideonZ/1541ultimate#620)