mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-10-05 22:29:49 +00:00
Simplify lwip_accept() and lwip_ioctl() by relying on nonblocking netconn functions instead of sock->rcvevent
This commit is contained in:
parent
5c3bb19923
commit
3feb748fee
@ -545,13 +545,6 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (netconn_is_nonblocking(sock->conn) && (sock->rcvevent <= 0)) {
|
|
||||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d): returning EWOULDBLOCK\n", s));
|
|
||||||
set_errno(EWOULDBLOCK);
|
|
||||||
done_socket(sock);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* wait for a new connection */
|
/* wait for a new connection */
|
||||||
err = netconn_accept(sock->conn, &newconn);
|
err = netconn_accept(sock->conn, &newconn);
|
||||||
if (err != ERR_OK) {
|
if (err != ERR_OK) {
|
||||||
@ -592,7 +585,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
|
|||||||
/* Note that POSIX only requires us to check addr is non-NULL. addrlen must
|
/* Note that POSIX only requires us to check addr is non-NULL. addrlen must
|
||||||
* not be NULL if addr is valid.
|
* not be NULL if addr is valid.
|
||||||
*/
|
*/
|
||||||
if (addr != NULL) {
|
if ((addr != NULL) && (addrlen != NULL)) {
|
||||||
union sockaddr_aligned tempaddr;
|
union sockaddr_aligned tempaddr;
|
||||||
/* get the IP address and port of the remote host */
|
/* get the IP address and port of the remote host */
|
||||||
err = netconn_peer(newconn, &naddr, &port);
|
err = netconn_peer(newconn, &naddr, &port);
|
||||||
@ -604,7 +597,6 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
|
|||||||
done_socket(sock);
|
done_socket(sock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
LWIP_ASSERT("addr valid but addrlen NULL", addrlen != NULL);
|
|
||||||
|
|
||||||
IPADDR_PORT_TO_SOCKADDR(&tempaddr, &naddr, port);
|
IPADDR_PORT_TO_SOCKADDR(&tempaddr, &naddr, port);
|
||||||
if (*addrlen > tempaddr.sa.sa_len) {
|
if (*addrlen > tempaddr.sa.sa_len) {
|
||||||
@ -2857,18 +2849,13 @@ lwip_ioctl(int s, long cmd, void *argp)
|
|||||||
*((int*)argp) = p->tot_len - sock->lastoffset;
|
*((int*)argp) = p->tot_len - sock->lastoffset;
|
||||||
} else {
|
} else {
|
||||||
struct netbuf *rxbuf;
|
struct netbuf *rxbuf;
|
||||||
err_t err;
|
err_t err = netconn_recv_udp_raw_netbuf_flags(sock->conn, &rxbuf, NETCONN_DONTBLOCK);
|
||||||
if (sock->rcvevent <= 0) {
|
if (err != ERR_OK) {
|
||||||
*((int*)argp) = 0;
|
*((int*)argp) = 0;
|
||||||
} else {
|
} else {
|
||||||
err = netconn_recv_udp_raw_netbuf(sock->conn, &rxbuf);
|
sock->lastdata = rxbuf;
|
||||||
if (err != ERR_OK) {
|
sock->lastoffset = 0;
|
||||||
*((int*)argp) = 0;
|
*((int*)argp) = rxbuf->p->tot_len;
|
||||||
} else {
|
|
||||||
sock->lastdata = rxbuf;
|
|
||||||
sock->lastoffset = 0;
|
|
||||||
*((int*)argp) = rxbuf->p->tot_len;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
done_socket(sock);
|
done_socket(sock);
|
||||||
|
Loading…
Reference in New Issue
Block a user