mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-10-17 21:47:56 +08:00
Use socket read() and write() from FreeBSD
This commit is contained in:
@@ -618,127 +618,3 @@ done2:
|
||||
errno = error;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
************************************************************************
|
||||
* RTEMS I/O HANDLER ROUTINES *
|
||||
************************************************************************
|
||||
*/
|
||||
static int
|
||||
rtems_bsdnet_close (rtems_libio_t *iop)
|
||||
{
|
||||
struct socket *so;
|
||||
int error;
|
||||
|
||||
if ((so = iop->data1) == NULL) {
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
error = soclose (so);
|
||||
if (error) {
|
||||
errno = error;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
rtems_bsdnet_read (rtems_libio_t *iop, void *buffer, size_t count)
|
||||
{
|
||||
return recv (iop->data0, buffer, count, 0);
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
rtems_bsdnet_write (rtems_libio_t *iop, const void *buffer, size_t count)
|
||||
{
|
||||
return send (iop->data0, buffer, count, 0);
|
||||
}
|
||||
|
||||
static int
|
||||
so_ioctl (rtems_libio_t *iop, struct socket *so, uint32_t command, void *buffer)
|
||||
{
|
||||
switch (command) {
|
||||
case FIONBIO:
|
||||
SOCK_LOCK(so);
|
||||
if (*(int *)buffer) {
|
||||
iop->flags |= O_NONBLOCK;
|
||||
so->so_state |= SS_NBIO;
|
||||
}
|
||||
else {
|
||||
iop->flags &= ~O_NONBLOCK;
|
||||
so->so_state &= ~SS_NBIO;
|
||||
}
|
||||
SOCK_UNLOCK(so);
|
||||
return 0;
|
||||
|
||||
case FIONREAD:
|
||||
*(int *)buffer = so->so_rcv.sb_cc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (IOCGROUP(command) == 'i')
|
||||
return ifioctl (so, command, buffer, NULL);
|
||||
if (IOCGROUP(command) == 'r')
|
||||
return rtioctl (command, buffer, NULL);
|
||||
return (*so->so_proto->pr_usrreqs->pru_control)(so, command, buffer, 0, curthread);
|
||||
}
|
||||
|
||||
static int
|
||||
rtems_bsdnet_ioctl (rtems_libio_t *iop, uint32_t command, void *buffer)
|
||||
{
|
||||
struct socket *so;
|
||||
int error;
|
||||
|
||||
if ((so = iop->data1) == NULL) {
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
error = so_ioctl (iop, so, command, buffer);
|
||||
if (error) {
|
||||
errno = error;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
rtems_bsdnet_fcntl (int cmd, rtems_libio_t *iop)
|
||||
{
|
||||
struct socket *so;
|
||||
|
||||
if (cmd == F_SETFL) {
|
||||
if ((so = iop->data1) == NULL) {
|
||||
return EBADF;
|
||||
}
|
||||
SOCK_LOCK(so);
|
||||
if (iop->flags & LIBIO_FLAGS_NO_DELAY)
|
||||
so->so_state |= SS_NBIO;
|
||||
else
|
||||
so->so_state &= ~SS_NBIO;
|
||||
SOCK_UNLOCK(so);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
rtems_bsdnet_fstat (rtems_filesystem_location_info_t *loc, struct stat *sp)
|
||||
{
|
||||
sp->st_mode = S_IFSOCK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const rtems_filesystem_file_handlers_r socket_handlers = {
|
||||
rtems_filesystem_default_open, /* open */
|
||||
rtems_bsdnet_close, /* close */
|
||||
rtems_bsdnet_read, /* read */
|
||||
rtems_bsdnet_write, /* write */
|
||||
rtems_bsdnet_ioctl, /* ioctl */
|
||||
rtems_filesystem_default_lseek, /* lseek */
|
||||
rtems_bsdnet_fstat, /* fstat */
|
||||
rtems_filesystem_default_fchmod, /* fchmod */
|
||||
rtems_filesystem_default_ftruncate, /* ftruncate */
|
||||
rtems_filesystem_default_fsync_or_fdatasync, /* fsync */
|
||||
rtems_filesystem_default_fsync_or_fdatasync, /* fdatasync */
|
||||
rtems_bsdnet_fcntl, /* fcntl */
|
||||
rtems_filesystem_default_rmnod /* rmnod */
|
||||
};
|
||||
|
Reference in New Issue
Block a user