mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-08-24 15:16:02 +00:00
make get_socket use tryget_socket, added tryget_socket_unconn in preparation of properly fixing bug #44032
This commit is contained in:
parent
f1f6050ad7
commit
9afe10e23d
|
@ -336,34 +336,16 @@ lwip_socket_thread_cleanup(void)
|
||||||
netconn_thread_cleanup();
|
netconn_thread_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* Translate a socket 'int' into a pointer (only fails if the index is invalid) */
|
||||||
* Map a externally used socket index to the internal socket representation.
|
|
||||||
*
|
|
||||||
* @param s externally used socket index
|
|
||||||
* @return struct lwip_sock for the socket or NULL if not found
|
|
||||||
*/
|
|
||||||
static struct lwip_sock *
|
static struct lwip_sock *
|
||||||
get_socket(int s)
|
tryget_socket_unconn(int fd)
|
||||||
{
|
{
|
||||||
struct lwip_sock *sock;
|
int s = fd - LWIP_SOCKET_OFFSET;
|
||||||
|
|
||||||
s -= LWIP_SOCKET_OFFSET;
|
|
||||||
|
|
||||||
if ((s < 0) || (s >= NUM_SOCKETS)) {
|
if ((s < 0) || (s >= NUM_SOCKETS)) {
|
||||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("get_socket(%d): invalid\n", s + LWIP_SOCKET_OFFSET));
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("tryget_socket_unconn(%d): invalid\n", fd));
|
||||||
set_errno(EBADF);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
return &sockets[s];
|
||||||
sock = &sockets[s];
|
|
||||||
|
|
||||||
if (!sock->conn) {
|
|
||||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("get_socket(%d): not active\n", s + LWIP_SOCKET_OFFSET));
|
|
||||||
set_errno(EBADF);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sock;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -373,16 +355,36 @@ get_socket(int s)
|
||||||
* @return struct lwip_sock for the socket or NULL if not found
|
* @return struct lwip_sock for the socket or NULL if not found
|
||||||
*/
|
*/
|
||||||
static struct lwip_sock *
|
static struct lwip_sock *
|
||||||
tryget_socket(int s)
|
tryget_socket(int fd)
|
||||||
{
|
{
|
||||||
s -= LWIP_SOCKET_OFFSET;
|
struct lwip_sock *sock = tryget_socket_unconn(fd);
|
||||||
if ((s < 0) || (s >= NUM_SOCKETS)) {
|
if (sock != NULL) {
|
||||||
|
if (sock->conn) {
|
||||||
|
return sock;
|
||||||
|
}
|
||||||
|
done_socket(sock);
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (!sockets[s].conn) {
|
|
||||||
|
/**
|
||||||
|
* Map a externally used socket index to the internal socket representation.
|
||||||
|
*
|
||||||
|
* @param s externally used socket index
|
||||||
|
* @return struct lwip_sock for the socket or NULL if not found
|
||||||
|
*/
|
||||||
|
static struct lwip_sock *
|
||||||
|
get_socket(int fd)
|
||||||
|
{
|
||||||
|
struct lwip_sock *sock = tryget_socket_unconn(fd);
|
||||||
|
if (!sock) {
|
||||||
|
if ((fd < LWIP_SOCKET_OFFSET) || (fd >= (LWIP_SOCKET_OFFSET + NUM_SOCKETS))) {
|
||||||
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("get_socket(%d): invalid\n", fd));
|
||||||
|
}
|
||||||
|
set_errno(EBADF);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return &sockets[s];
|
return sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user