mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-05-13 21:19:46 +08:00
Use socket ioctl() from FreeBSD
This commit is contained in:
parent
468b08e553
commit
e5393a3267
@ -120,7 +120,11 @@ soo_truncate(struct file *fp, off_t length, struct ucred *active_cred,
|
|||||||
|
|
||||||
return (EINVAL);
|
return (EINVAL);
|
||||||
}
|
}
|
||||||
|
#endif /* __rtems__ */
|
||||||
|
|
||||||
|
#ifdef __rtems__
|
||||||
|
static
|
||||||
|
#endif /* __rtems__ */
|
||||||
int
|
int
|
||||||
soo_ioctl(struct file *fp, u_long cmd, void *data, struct ucred *active_cred,
|
soo_ioctl(struct file *fp, u_long cmd, void *data, struct ucred *active_cred,
|
||||||
struct thread *td)
|
struct thread *td)
|
||||||
@ -128,6 +132,10 @@ soo_ioctl(struct file *fp, u_long cmd, void *data, struct ucred *active_cred,
|
|||||||
struct socket *so = fp->f_data;
|
struct socket *so = fp->f_data;
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
|
#ifdef __rtems__
|
||||||
|
if (td == NULL)
|
||||||
|
return (ENOMEM);
|
||||||
|
#endif /* __rtems__ */
|
||||||
CURVNET_SET(so->so_vnet);
|
CURVNET_SET(so->so_vnet);
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case FIONBIO:
|
case FIONBIO:
|
||||||
@ -225,7 +233,19 @@ soo_ioctl(struct file *fp, u_long cmd, void *data, struct ucred *active_cred,
|
|||||||
CURVNET_RESTORE();
|
CURVNET_RESTORE();
|
||||||
return (error);
|
return (error);
|
||||||
}
|
}
|
||||||
|
#ifdef __rtems__
|
||||||
|
static int
|
||||||
|
rtems_bsd_soo_ioctl(rtems_libio_t *iop, ioctl_command_t request, void *buffer)
|
||||||
|
{
|
||||||
|
struct thread *td = rtems_bsd_get_curthread_or_null();
|
||||||
|
struct file *fp = rtems_bsd_iop_to_fp(iop);
|
||||||
|
int error = soo_ioctl(fp, request, buffer, NULL, td);
|
||||||
|
|
||||||
|
return rtems_bsd_error_to_status_and_errno(error);
|
||||||
|
}
|
||||||
|
#endif /* __rtems__ */
|
||||||
|
|
||||||
|
#ifndef __rtems__
|
||||||
int
|
int
|
||||||
soo_poll(struct file *fp, int events, struct ucred *active_cred,
|
soo_poll(struct file *fp, int events, struct ucred *active_cred,
|
||||||
struct thread *td)
|
struct thread *td)
|
||||||
@ -345,7 +365,7 @@ const rtems_filesystem_file_handlers_r socketops = {
|
|||||||
.close_h = rtems_bsd_soo_close,
|
.close_h = rtems_bsd_soo_close,
|
||||||
.read_h = rtems_filesystem_default_read,
|
.read_h = rtems_filesystem_default_read,
|
||||||
.write_h = rtems_filesystem_default_write,
|
.write_h = rtems_filesystem_default_write,
|
||||||
.ioctl_h = rtems_filesystem_default_ioctl,
|
.ioctl_h = rtems_bsd_soo_ioctl,
|
||||||
.lseek_h = rtems_filesystem_default_lseek,
|
.lseek_h = rtems_filesystem_default_lseek,
|
||||||
.fstat_h = rtems_bsd_soo_stat,
|
.fstat_h = rtems_bsd_soo_stat,
|
||||||
.ftruncate_h = rtems_filesystem_default_ftruncate,
|
.ftruncate_h = rtems_filesystem_default_ftruncate,
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <sys/filio.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
@ -457,6 +458,56 @@ test_socket_fstat_and_shutdown(void)
|
|||||||
assert(rtems_resource_snapshot_check(&snapshot));
|
assert(rtems_resource_snapshot_check(&snapshot));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
no_mem_socket_ioctl(int fd)
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
int data;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
rv = ioctl(fd, FIONREAD, &data);
|
||||||
|
assert(rv == -1);
|
||||||
|
assert(errno == ENOMEM);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_socket_ioctl(void)
|
||||||
|
{
|
||||||
|
rtems_resource_snapshot snapshot;
|
||||||
|
int sd;
|
||||||
|
int rv;
|
||||||
|
int data;
|
||||||
|
|
||||||
|
puts("test socket ioctl");
|
||||||
|
|
||||||
|
rtems_resource_snapshot_take(&snapshot);
|
||||||
|
|
||||||
|
sd = socket(PF_INET, SOCK_DGRAM, 0);
|
||||||
|
assert(sd >= 0);
|
||||||
|
|
||||||
|
do_no_mem_test(no_mem_socket_ioctl, sd);
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
rv = ioctl(sd, 0xffffffff);
|
||||||
|
assert(rv == -1);
|
||||||
|
assert(errno == EOPNOTSUPP);
|
||||||
|
|
||||||
|
data = -1;
|
||||||
|
rv = ioctl(sd, FIONREAD, &data);
|
||||||
|
assert(rv == 0);
|
||||||
|
assert(data == 0);
|
||||||
|
|
||||||
|
rv = close(sd);
|
||||||
|
assert(rv == 0);
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
rv = ioctl(sd, 0);
|
||||||
|
assert(rv == -1);
|
||||||
|
assert(errno == EBADF);
|
||||||
|
|
||||||
|
assert(rtems_resource_snapshot_check(&snapshot));
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
no_mem_socket_bind(int fd)
|
no_mem_socket_bind(int fd)
|
||||||
{
|
{
|
||||||
@ -522,6 +573,7 @@ test_main(void)
|
|||||||
|
|
||||||
test_socket_unsupported_ops();
|
test_socket_unsupported_ops();
|
||||||
test_socket_fstat_and_shutdown();
|
test_socket_fstat_and_shutdown();
|
||||||
|
test_socket_ioctl();
|
||||||
test_socket_bind();
|
test_socket_bind();
|
||||||
|
|
||||||
puts("*** END OF " TEST_NAME " TEST ***");
|
puts("*** END OF " TEST_NAME " TEST ***");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user