posix_sockets: use vfs_file_get() to resolve file descriptor
This commit is contained in:
parent
ef844d8863
commit
c7dc0bb8de
@ -122,13 +122,20 @@ static socket_sock_t *_get_free_sock(void)
|
|||||||
|
|
||||||
static socket_t *_get_socket(int fd)
|
static socket_t *_get_socket(int fd)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _ACTUAL_SOCKET_POOL_SIZE; i++) {
|
const vfs_file_t *file = vfs_file_get(fd);
|
||||||
if (_socket_pool[i].fd == fd) {
|
/* we know what to do with `socket`, so it's okay to discard the const */
|
||||||
return &_socket_pool[i];
|
socket_t *socket = (file == NULL)
|
||||||
}
|
? NULL
|
||||||
|
: file->private_data.ptr;
|
||||||
|
if ((socket >= &_socket_pool[0]) &&
|
||||||
|
(socket <= &_socket_pool[_ACTUAL_SOCKET_POOL_SIZE - 1])) {
|
||||||
|
assert(socket->fd == fd);
|
||||||
|
return socket;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int _get_sock_idx(socket_sock_t *sock)
|
static int _get_sock_idx(socket_sock_t *sock)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user