libc_lwip: 'fcntl()' fix
The 'O_NONBLOCK' flag has different numerical values in lwip and in the libc, which prevented the correct setting of nonblocking socket mode. Fixes #1699
This commit is contained in:
parent
de87ecfc62
commit
5309bda8b6
|
@ -51,8 +51,9 @@ static inline void lwip_FD_SET(int lwip_fd, lwip_fd_set *set)
|
||||||
FD_SET(lwip_fd, set);
|
FD_SET(lwip_fd, set);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const long lwip_FIONBIO = FIONBIO;
|
static constexpr long lwip_FIONBIO = FIONBIO;
|
||||||
static const long lwip_FIONREAD = FIONREAD;
|
static constexpr long lwip_FIONREAD = FIONREAD;
|
||||||
|
static constexpr int lwip_O_NONBLOCK = O_NONBLOCK;
|
||||||
|
|
||||||
/* undefine lwip type names that are also defined in libc headers and have
|
/* undefine lwip type names that are also defined in libc headers and have
|
||||||
* been renamed to lwip_*() */
|
* been renamed to lwip_*() */
|
||||||
|
@ -65,6 +66,7 @@ static const long lwip_FIONREAD = FIONREAD;
|
||||||
|
|
||||||
/* undefine lwip macros that are also defined in libc headers and cannot be
|
/* undefine lwip macros that are also defined in libc headers and cannot be
|
||||||
* renamed */
|
* renamed */
|
||||||
|
#undef AF_INET6
|
||||||
#undef BIG_ENDIAN
|
#undef BIG_ENDIAN
|
||||||
#undef BYTE_ORDER
|
#undef BYTE_ORDER
|
||||||
#undef FD_CLR
|
#undef FD_CLR
|
||||||
|
@ -73,6 +75,8 @@ static const long lwip_FIONREAD = FIONREAD;
|
||||||
#undef FD_ZERO
|
#undef FD_ZERO
|
||||||
#undef FIONBIO
|
#undef FIONBIO
|
||||||
#undef FIONREAD
|
#undef FIONREAD
|
||||||
|
#undef O_NDELAY
|
||||||
|
#undef O_NONBLOCK
|
||||||
#undef HOST_NOT_FOUND
|
#undef HOST_NOT_FOUND
|
||||||
#undef IOCPARM_MASK
|
#undef IOCPARM_MASK
|
||||||
#undef IOC_VOID
|
#undef IOC_VOID
|
||||||
|
@ -110,6 +114,7 @@ static const long lwip_FIONREAD = FIONREAD;
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/fcntl.h>
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -320,15 +325,20 @@ int Plugin::fcntl(Libc::File_descriptor *sockfdo, int cmd, long val)
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case F_GETFL:
|
case F_GETFL:
|
||||||
|
/* lwip_fcntl() supports only the 'O_NONBLOCK' flag */
|
||||||
|
result = lwip_fcntl(s, cmd, val);
|
||||||
|
if (result == lwip_O_NONBLOCK)
|
||||||
|
result = O_NONBLOCK;
|
||||||
|
break;
|
||||||
case F_SETFL:
|
case F_SETFL:
|
||||||
/*
|
/*
|
||||||
* lwip_fcntl() supports only the 'O_NONBLOCK' flag and only if
|
* lwip_fcntl() supports only the 'O_NONBLOCK' flag and only if
|
||||||
* no other flag is set.
|
* no other flag is set.
|
||||||
*/
|
*/
|
||||||
result = lwip_fcntl(s, cmd, val & O_NONBLOCK);
|
result = lwip_fcntl(s, cmd, (val & O_NONBLOCK) ? lwip_O_NONBLOCK : 0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
PERR("unsupported fcntl() request: %d", cmd);
|
PERR("libc_lwip: unsupported fcntl() request: %d", cmd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,16 +391,16 @@ int Plugin::getsockopt(Libc::File_descriptor *sockfdo, int level,
|
||||||
int Plugin::ioctl(Libc::File_descriptor *sockfdo, int request, char *argp)
|
int Plugin::ioctl(Libc::File_descriptor *sockfdo, int request, char *argp)
|
||||||
{
|
{
|
||||||
switch (request) {
|
switch (request) {
|
||||||
case FIONBIO:
|
case FIONBIO:
|
||||||
return lwip_ioctl(get_lwip_fd(sockfdo), lwip_FIONBIO, argp);
|
return lwip_ioctl(get_lwip_fd(sockfdo), lwip_FIONBIO, argp);
|
||||||
break;
|
break;
|
||||||
case FIONREAD:
|
case FIONREAD:
|
||||||
return lwip_ioctl(get_lwip_fd(sockfdo), lwip_FIONREAD, argp);;
|
return lwip_ioctl(get_lwip_fd(sockfdo), lwip_FIONREAD, argp);;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
PERR("unsupported ioctl() request");
|
PERR("unsupported ioctl() request");
|
||||||
errno = ENOSYS;
|
errno = ENOSYS;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user