Added a minimal version of posix fctl() to have a standardised way to set O_NONBLOCK for nonblocking sockets.

This commit is contained in:
goldsimon 2010-02-12 17:59:20 +00:00
parent f89c08872c
commit 8fbaf0304a
3 changed files with 50 additions and 0 deletions

View File

@ -19,6 +19,10 @@ HISTORY
++ New features:
2010-02-12: Simon Goldschmidt
* sockets.c/.h: Added a minimal version of posix fctl() to have a
standardised way to set O_NONBLOCK for nonblocking sockets.
2010-02-12: Simon Goldschmidt
* dhcp.c/.h, autoip.c/.h: task #10139 (Prefer statically allocated
memory): added autoip_set_struct() and dhcp_set_struct() to let autoip

View File

@ -2045,4 +2045,33 @@ lwip_ioctl(int s, long cmd, void *argp)
} /* switch (cmd) */
}
/** A minimal implementation of fcntl.
* Currently only the commands F_GETFL and F_SETFL are implemented.
* Only the flag O_NONBLOCK is implemented.
*/
int
lwip_fcntl(int s, int cmd, int val)
{
struct lwip_socket *sock = get_socket(s);
int ret = -1;
if (!sock || !sock->conn) {
return -1;
}
switch (cmd) {
case F_GETFL:
ret = netconn_is_nonblocking(sock->conn) ? O_NONBLOCK : 0;
break;
case F_SETFL:
if ((val & ~O_NONBLOCK) == 0) {
/* only O_NONBLOCK, all other bits are zero */
netconn_set_nonblocking(sock->conn, val & O_NONBLOCK);
ret = 0;
}
break;
}
return ret;
}
#endif /* LWIP_SOCKET */

View File

@ -262,6 +262,22 @@ typedef struct ip_mreq {
#define SIOCATMARK _IOR('s', 7, unsigned long) /* at oob mark? */
#endif
/* commands for fnctl */
#ifndef F_GETFL
#define F_GETFL 3
#endif
#ifndef F_SETFL
#define F_SETFL 4
#endif
/* File status flags and file access modes for fnctl,
these are bits in an int. */
#ifndef O_NONBLOCK
#define O_NONBLOCK 1 /* nonblocking I/O */
#endif
#ifndef O_NDELAY
#define O_NDELAY 1 /* same as O_NONBLOCK, for compatibility */
#endif
/* FD_SET used for lwip_select */
#ifndef FD_SET
@ -316,6 +332,7 @@ int lwip_write(int s, const void *dataptr, size_t size);
int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
struct timeval *timeout);
int lwip_ioctl(int s, long cmd, void *argp);
int lwip_fcntl(int s, int cmd, int val);
#if LWIP_COMPAT_SOCKETS
#define accept(a,b,c) lwip_accept(a,b,c)