1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

posix_sockets: use vfs_file_get() to resolve file descriptor

This commit is contained in:
Martine S. Lenders 2019-12-13 12:54:51 +01:00
parent ef844d8863
commit c7dc0bb8de
No known key found for this signature in database
GPG Key ID: CCD317364F63286F

View File

@ -122,12 +122,19 @@ static socket_sock_t *_get_free_sock(void)
static socket_t *_get_socket(int fd)
{
for (int i = 0; i < _ACTUAL_SOCKET_POOL_SIZE; i++) {
if (_socket_pool[i].fd == fd) {
return &_socket_pool[i];
}
const vfs_file_t *file = vfs_file_get(fd);
/* we know what to do with `socket`, so it's okay to discard the const */
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)