mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-10-14 06:35:01 +08:00
Use send/recv functions from FreeBSD
Use recvfrom(), recvmsg(), sendto() and sendmsg() from FreeBSD.
This commit is contained in:
@@ -98,10 +98,10 @@ __FBSDID("$FreeBSD$");
|
||||
#include <machine/rtems-bsd-syscall-api.h>
|
||||
#endif /* __rtems__ */
|
||||
|
||||
#ifndef __rtems__
|
||||
static int sendit(struct thread *td, int s, struct msghdr *mp, int flags);
|
||||
static int recvit(struct thread *td, int s, struct msghdr *mp, void *namelenp);
|
||||
|
||||
#ifndef __rtems__
|
||||
static int accept1(struct thread *td, struct accept_args *uap, int compat);
|
||||
static int do_sendfile(struct thread *td, struct sendfile_args *uap, int compat);
|
||||
static int getsockname1(struct thread *td, struct getsockname_args *uap,
|
||||
@@ -863,7 +863,13 @@ socketpair(struct thread *td, struct socketpair_args *uap)
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
#endif /* __rtems__ */
|
||||
|
||||
#ifdef __rtems__
|
||||
static int
|
||||
kern_sendit( struct thread *td, int s, struct msghdr *mp, int flags,
|
||||
struct mbuf *control, enum uio_seg segflg);
|
||||
#endif /* __rtems__ */
|
||||
static int
|
||||
sendit(td, s, mp, flags)
|
||||
struct thread *td;
|
||||
@@ -986,9 +992,13 @@ kern_sendit(td, s, mp, flags, control, segflg)
|
||||
/* Generation of SIGPIPE can be controlled per socket */
|
||||
if (error == EPIPE && !(so->so_options & SO_NOSIGPIPE) &&
|
||||
!(flags & MSG_NOSIGNAL)) {
|
||||
#ifndef __rtems__
|
||||
PROC_LOCK(td->td_proc);
|
||||
tdksignal(td, SIGPIPE, NULL);
|
||||
PROC_UNLOCK(td->td_proc);
|
||||
#else /* __rtems__ */
|
||||
/* FIXME: Determine if we really want to use signals */
|
||||
#endif /* __rtems__ */
|
||||
}
|
||||
}
|
||||
if (error == 0)
|
||||
@@ -1004,8 +1014,13 @@ bad:
|
||||
return (error);
|
||||
}
|
||||
|
||||
#ifndef __rtems__
|
||||
int
|
||||
sendto(td, uap)
|
||||
#else /* __rtems__ */
|
||||
static int
|
||||
rtems_bsd_sendto(td, uap)
|
||||
#endif /* __rtems__ */
|
||||
struct thread *td;
|
||||
struct sendto_args /* {
|
||||
int s;
|
||||
@@ -1033,7 +1048,37 @@ sendto(td, uap)
|
||||
error = sendit(td, uap->s, &msg, uap->flags);
|
||||
return (error);
|
||||
}
|
||||
#ifdef __rtems__
|
||||
ssize_t
|
||||
sendto(int socket, const void *message, size_t length, int flags,
|
||||
const struct sockaddr *dest_addr, socklen_t dest_len)
|
||||
{
|
||||
struct thread *td = rtems_bsd_get_curthread_or_null();
|
||||
struct sendto_args ua = {
|
||||
.s = socket,
|
||||
.buf = (caddr_t) message,
|
||||
.len = length,
|
||||
.flags = flags,
|
||||
.to = (caddr_t) dest_addr,
|
||||
.tolen = dest_len
|
||||
};
|
||||
int error;
|
||||
|
||||
if (td != NULL) {
|
||||
error = rtems_bsd_sendto(td, &ua);
|
||||
} else {
|
||||
error = ENOMEM;
|
||||
}
|
||||
|
||||
if (error == 0) {
|
||||
return td->td_retval[0];
|
||||
} else {
|
||||
rtems_set_errno_and_return_minus_one(error);
|
||||
}
|
||||
}
|
||||
#endif /* __rtems__ */
|
||||
|
||||
#ifndef __rtems__
|
||||
#ifdef COMPAT_OLDSOCK
|
||||
int
|
||||
osend(td, uap)
|
||||
@@ -1087,9 +1132,15 @@ osendmsg(td, uap)
|
||||
return (error);
|
||||
}
|
||||
#endif
|
||||
#endif /* __rtems__ */
|
||||
|
||||
#ifndef __rtems__
|
||||
int
|
||||
sendmsg(td, uap)
|
||||
#else /* __rtems__ */
|
||||
static int
|
||||
rtems_bsd_sendmsg(td, uap)
|
||||
#endif /* __rtems__ */
|
||||
struct thread *td;
|
||||
struct sendmsg_args /* {
|
||||
int s;
|
||||
@@ -1115,7 +1166,35 @@ sendmsg(td, uap)
|
||||
free(iov, M_IOV);
|
||||
return (error);
|
||||
}
|
||||
#ifdef __rtems__
|
||||
ssize_t
|
||||
sendmsg(int socket, const struct msghdr *message, int flags)
|
||||
{
|
||||
struct thread *td = rtems_bsd_get_curthread_or_null();
|
||||
struct sendmsg_args ua = {
|
||||
.s = socket,
|
||||
.msg = message,
|
||||
.flags = flags
|
||||
};
|
||||
int error;
|
||||
|
||||
if (td != NULL) {
|
||||
error = rtems_bsd_sendmsg(td, &ua);
|
||||
} else {
|
||||
error = ENOMEM;
|
||||
}
|
||||
|
||||
if (error == 0) {
|
||||
return td->td_retval[0];
|
||||
} else {
|
||||
rtems_set_errno_and_return_minus_one(error);
|
||||
}
|
||||
}
|
||||
#endif /* __rtems__ */
|
||||
|
||||
#ifdef __rtems__
|
||||
static
|
||||
#endif /* __rtems__ */
|
||||
int
|
||||
kern_recvit(td, s, mp, fromseg, controlp)
|
||||
struct thread *td;
|
||||
@@ -1300,8 +1379,13 @@ recvit(td, s, mp, namelenp)
|
||||
return (error);
|
||||
}
|
||||
|
||||
#ifndef __rtems__
|
||||
int
|
||||
recvfrom(td, uap)
|
||||
#else /* __rtems__ */
|
||||
static int
|
||||
rtems_bsd_recvfrom(td, uap)
|
||||
#endif /* __rtems__ */
|
||||
struct thread *td;
|
||||
struct recvfrom_args /* {
|
||||
int s;
|
||||
@@ -1335,7 +1419,37 @@ recvfrom(td, uap)
|
||||
done2:
|
||||
return(error);
|
||||
}
|
||||
#ifdef __rtems__
|
||||
ssize_t
|
||||
recvfrom(int socket, void *__restrict buffer, size_t length, int flags,
|
||||
struct sockaddr *__restrict address, socklen_t *__restrict address_len)
|
||||
{
|
||||
struct thread *td = rtems_bsd_get_curthread_or_null();
|
||||
struct recvfrom_args ua = {
|
||||
.s = socket,
|
||||
.buf = buffer,
|
||||
.len = length,
|
||||
.flags = flags,
|
||||
.from = address,
|
||||
.fromlenaddr = address_len
|
||||
};
|
||||
int error;
|
||||
|
||||
if (td != NULL) {
|
||||
error = rtems_bsd_recvfrom(td, &ua);
|
||||
} else {
|
||||
error = ENOMEM;
|
||||
}
|
||||
|
||||
if (error == 0) {
|
||||
return td->td_retval[0];
|
||||
} else {
|
||||
rtems_set_errno_and_return_minus_one(error);
|
||||
}
|
||||
}
|
||||
#endif /* __rtems__ */
|
||||
|
||||
#ifndef __rtems__
|
||||
#ifdef COMPAT_OLDSOCK
|
||||
int
|
||||
orecvfrom(td, uap)
|
||||
@@ -1409,9 +1523,15 @@ orecvmsg(td, uap)
|
||||
return (error);
|
||||
}
|
||||
#endif
|
||||
#endif /* __rtems__ */
|
||||
|
||||
#ifndef __rtems__
|
||||
int
|
||||
recvmsg(td, uap)
|
||||
#else /* __rtems__ */
|
||||
static int
|
||||
rtems_bsd_recvmsg(td, uap)
|
||||
#endif /* __rtems__ */
|
||||
struct thread *td;
|
||||
struct recvmsg_args /* {
|
||||
int s;
|
||||
@@ -1443,6 +1563,30 @@ recvmsg(td, uap)
|
||||
free(iov, M_IOV);
|
||||
return (error);
|
||||
}
|
||||
#ifdef __rtems__
|
||||
ssize_t
|
||||
recvmsg(int socket, struct msghdr *message, int flags)
|
||||
{
|
||||
struct thread *td = rtems_bsd_get_curthread_or_null();
|
||||
struct recvmsg_args ua = {
|
||||
.s = socket,
|
||||
.msg = message,
|
||||
.flags = flags
|
||||
};
|
||||
int error;
|
||||
|
||||
if (td != NULL) {
|
||||
error = rtems_bsd_recvmsg(td, &ua);
|
||||
} else {
|
||||
error = ENOMEM;
|
||||
}
|
||||
|
||||
if (error == 0) {
|
||||
return td->td_retval[0];
|
||||
} else {
|
||||
rtems_set_errno_and_return_minus_one(error);
|
||||
}
|
||||
}
|
||||
#endif /* __rtems__ */
|
||||
|
||||
/* ARGSUSED */
|
||||
@@ -1961,6 +2105,7 @@ ogetpeername(td, uap)
|
||||
return (getpeername1(td, (struct getpeername_args *)uap, 1));
|
||||
}
|
||||
#endif /* COMPAT_OLDSOCK */
|
||||
#endif /* __rtems__ */
|
||||
|
||||
int
|
||||
sockargs(mp, buf, buflen, type)
|
||||
@@ -2002,7 +2147,6 @@ sockargs(mp, buf, buflen, type)
|
||||
}
|
||||
return (error);
|
||||
}
|
||||
#endif /* __rtems__ */
|
||||
|
||||
int
|
||||
getsockaddr(namp, uaddr, len)
|
||||
|
@@ -127,6 +127,7 @@ struct ptrace_args {
|
||||
char addr_l_[PADL_(caddr_t)]; caddr_t addr; char addr_r_[PADR_(caddr_t)];
|
||||
char data_l_[PADL_(int)]; int data; char data_r_[PADR_(int)];
|
||||
};
|
||||
#endif /* __rtems__ */
|
||||
struct recvmsg_args {
|
||||
char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
|
||||
char msg_l_[PADL_(struct msghdr *)]; struct msghdr * msg; char msg_r_[PADR_(struct msghdr *)];
|
||||
@@ -134,7 +135,11 @@ struct recvmsg_args {
|
||||
};
|
||||
struct sendmsg_args {
|
||||
char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
|
||||
#ifndef __rtems__
|
||||
char msg_l_[PADL_(struct msghdr *)]; struct msghdr * msg; char msg_r_[PADR_(struct msghdr *)];
|
||||
#else /* __rtems__ */
|
||||
char msg_l_[PADL_(struct msghdr *)]; const struct msghdr * msg; char msg_r_[PADR_(struct msghdr *)];
|
||||
#endif /* __rtems__ */
|
||||
char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
|
||||
};
|
||||
struct recvfrom_args {
|
||||
@@ -145,7 +150,6 @@ struct recvfrom_args {
|
||||
char from_l_[PADL_(struct sockaddr *__restrict)]; struct sockaddr *__restrict from; char from_r_[PADR_(struct sockaddr *__restrict)];
|
||||
char fromlenaddr_l_[PADL_(__socklen_t *__restrict)]; __socklen_t *__restrict fromlenaddr; char fromlenaddr_r_[PADR_(__socklen_t *__restrict)];
|
||||
};
|
||||
#endif /* __rtems__ */
|
||||
struct accept_args {
|
||||
char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
|
||||
char name_l_[PADL_(struct sockaddr *__restrict)]; struct sockaddr *__restrict name; char name_r_[PADR_(struct sockaddr *__restrict)];
|
||||
@@ -462,15 +466,19 @@ struct mkfifo_args {
|
||||
char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)];
|
||||
char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)];
|
||||
};
|
||||
#endif /* __rtems__ */
|
||||
struct sendto_args {
|
||||
char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
|
||||
char buf_l_[PADL_(caddr_t)]; caddr_t buf; char buf_r_[PADR_(caddr_t)];
|
||||
char len_l_[PADL_(size_t)]; size_t len; char len_r_[PADR_(size_t)];
|
||||
char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)];
|
||||
char to_l_[PADL_(caddr_t)]; caddr_t to; char to_r_[PADR_(caddr_t)];
|
||||
#ifndef __rtems__
|
||||
char tolen_l_[PADL_(int)]; int tolen; char tolen_r_[PADR_(int)];
|
||||
};
|
||||
#else /* __rtems__ */
|
||||
char tolen_l_[PADL_(__socklen_t)]; __socklen_t tolen; char tolen_r_[PADR_(__socklen_t)];
|
||||
#endif /* __rtems__ */
|
||||
};
|
||||
struct shutdown_args {
|
||||
char s_l_[PADL_(int)]; int s; char s_r_[PADR_(int)];
|
||||
char how_l_[PADL_(int)]; int how; char how_r_[PADR_(int)];
|
||||
|
Reference in New Issue
Block a user