code cleanup. renamed exported socket functions as socket_ and removed void *

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1792 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
beveloper 2002-10-30 16:40:51 +00:00
parent 50051aab06
commit b282b44773
7 changed files with 106 additions and 139 deletions

View File

@ -98,19 +98,6 @@
# define get_interfaces core->get_interfaces
# define get_primary_addr core->get_primary_addr
# define initsocket core->initsocket
# define socreate core->socreate
# define soclose core->soclose
# define sobind core->sobind
# define soconnect core->soconnect
# define solisten core->solisten
# define soaccept core->soaccept
# define soo_ioctl core->soo_ioctl
# define net_sysctl core->net_sysctl
# define readit core->readit
# define writeit core->writeit
#endif /* OBOS_CORE_FUNCS_H */

View File

@ -129,25 +129,26 @@ struct core_module_info {
struct in_ifaddr *(*get_primary_addr)(void);
/* socket functions - used by socket driver */
int (*initsocket)(struct socket **);
int (*socreate)(int, struct socket *, int, int);
int (*soclose)(void *);
int (*sobind)(void *, caddr_t, int);
int (*solisten)(void *, int);
int (*soconnect)(void *, caddr_t, int);
int (*recvit)(void *, struct msghdr *, caddr_t, int *);
int (*sendit)(void *, struct msghdr *, int, int *);
int (*soo_ioctl)(void *, int, caddr_t);
int (*net_sysctl)(int *, uint, void *, size_t *, void *, size_t);
int (*writeit)(void *, struct iovec *, int);
int (*readit)(void*, struct iovec *, int *);
int (*sosetopt)(void *, int, int, const void *, size_t);
int (*sogetopt)(void *, int, int, void *, size_t *);
int (*set_socket_event_callback)(void *, socket_event_callback, void *, int);
int (*sogetpeername)(void *, struct sockaddr *, int *);
int (*sogetsockname)(void *, struct sockaddr *, int *);
int (*soaccept)(struct socket *s, struct socket **news, void *, int *);
/* socket functions - used by socket driver */
int (*socket_init) (struct socket **nso);
int (*socket_create) (struct socket *so, int dom, int type, int proto);
int (*socket_close) (struct socket *so);
int (*socket_bind) (struct socket *so, caddr_t, int);
int (*socket_listen) (struct socket *so, int backlog);
int (*socket_connect) (struct socket *so, caddr_t, int);
int (*socket_accept) (struct socket *so, struct socket **nso, void *, int *);
int (*socket_recv) (struct socket *so, struct msghdr *, caddr_t namelenp, int *retsize);
int (*socket_send) (struct socket *so, struct msghdr *, int flags, int *retsize);
int (*socket_ioctl) (struct socket *so, int, caddr_t);
int (*socket_writev) (struct socket *so, struct iovec *, int flags);
int (*socket_readv) (struct socket *so, struct iovec *, int *flags);
int (*socket_setsockopt) (struct socket *so, int, int, const void *, size_t);
int (*socket_getsockopt) (struct socket *so, int, int, void *, size_t *);
int (*socket_getpeername) (struct socket *so, struct sockaddr *, int *);
int (*socket_getsockname) (struct socket *so, struct sockaddr *, int *);
int (*socket_set_event_callback)(struct socket *so, socket_event_callback, void *, int);
};
#ifdef _KERNEL_MODE
@ -157,4 +158,3 @@ struct core_module_info {
#endif
#endif /* OBOS_CORE_MODULE_H */

View File

@ -4,35 +4,33 @@
#include <sys/socketvar.h>
#include <mbuf.h>
//uint32 sb_max;
/* Function prototypes */
/* These are the ones we export to libnet.so */
/* These functions are exported through the core module */
int initsocket(struct socket **);
int socreate (int, struct socket *, int, int);//XXX
int soshutdown(void *, int);
int soclose (void *);
int socket_init (struct socket **nso);
int socket_create (struct socket *so, int dom, int type, int proto);
int socket_shutdown (struct socket *so, int how); // XXX this one is not used at all
int socket_close (struct socket *so);
int sobind (void *, char *, int);
int solisten (void *, int);
int soconnect (void *, char *, int);
int soaccept (struct socket *, struct socket **, void *, int *);
int socket_bind (struct socket *so, char *, int);
int socket_listen (struct socket *so, int backlog);
int socket_connect (struct socket *so, char *, int);
int socket_accept (struct socket *so, struct socket **nso, void *, int *);
int writeit (void *, struct iovec *, int);
int readit (void *, struct iovec *, int *);
int sendit (void *, struct msghdr *, int, int *);
int recvit (void *, struct msghdr *, char *, int *);
int socket_writev (struct socket *so, struct iovec *, int flags);
int socket_readv (struct socket *so, struct iovec *, int *flags);
int socket_send (struct socket *so, struct msghdr *, int flags, int *retsize);
int socket_recv (struct socket *so, struct msghdr *, caddr_t namelenp, int *retsize);
//int so_ioctl (void *, int, void *, size_t);
int sosysctl (int *, uint, void *, size_t *, void *, size_t);
int sosetopt (void *, int, int, const void *, size_t);
int sogetopt (void *, int, int, void *, size_t *);
int soo_ioctl(void *sp, int cmd, caddr_t data);
int socket_setsockopt (struct socket *so, int, int, const void *, size_t);
int socket_getsockopt (struct socket *so, int, int, void *, size_t *);
int socket_ioctl (struct socket *so, int cmd, caddr_t data);
int sogetpeername(void *, struct sockaddr *, int *);
int sogetsockname(void *, struct sockaddr *, int *);
int socket_getpeername (struct socket *so, struct sockaddr *, int *);
int socket_getsockname (struct socket *so, struct sockaddr *, int *);
int socket_set_event_callback(struct socket *so, socket_event_callback, void *, int);
/* these are all private to the stack...although may be shared with
@ -43,7 +41,6 @@ int sosend(struct socket *so, struct mbuf *addr, struct uio *uio,
struct mbuf *top, struct mbuf *control, int flags);
struct socket *sonewconn(struct socket *head, int connstatus);
int set_socket_event_callback(void *, socket_event_callback, void *, int);
int soreserve (struct socket *so, uint32 sndcc, uint32 rcvcc);
void sbrelease (struct sockbuf *sb);

View File

@ -312,7 +312,7 @@ static status_t net_stack_close(void *cookie)
if (nsc->socket) {
// if a socket was opened on this fd, close it now.
rv = core->soclose(nsc->socket);
rv = core->socket_close(nsc->socket);
nsc->socket = NULL;
}
@ -364,26 +364,26 @@ static status_t net_stack_control(void *cookie, uint32 op, void * data, size_t l
int rv;
// okay, now try to open a real socket behind this fd/net_stack_cookie pair
rv = core->initsocket(&nsc->socket);
rv = core->socket_init(&nsc->socket);
if (rv == 0)
rv = core->socreate(args->family, nsc->socket, args->type, args->proto);
rv = core->socket_create(nsc->socket, args->family, args->type, args->proto);
// TODO: This is where the open flags need to be addressed
return rv;
}
case NET_STACK_CONNECT: {
struct sockaddr_args * args = (struct sockaddr_args *) data;
// args->addr == sockaddr to connect to
return core->soconnect(nsc->socket, (caddr_t) args->addr, args->addrlen);
return core->socket_connect(nsc->socket, (caddr_t) args->addr, args->addrlen);
}
case NET_STACK_BIND: {
struct sockaddr_args * args = (struct sockaddr_args *) data;
// args->addr == sockaddr to try and bind to
return core->sobind(nsc->socket, (caddr_t) args->addr, args->addrlen);
return core->socket_bind(nsc->socket, (caddr_t) args->addr, args->addrlen);
}
case NET_STACK_LISTEN: {
struct int_args * args = (struct int_args *) data;
// args->value == backlog to set
return core->solisten(nsc->socket, args->value);
return core->socket_listen(nsc->socket, args->value);
}
case NET_STACK_GET_COOKIE: {
/* this is needed by accept() call, to be able to pass back
@ -399,7 +399,7 @@ static status_t net_stack_control(void *cookie, uint32 op, void * data, size_t l
/* args->cookie == net_stack_cookie * of the already opened fd to use to the
* newly accepted socket
*/
return core->soaccept(nsc->socket, &ansc->socket, (void *)args->addr, &args->addrlen);
return core->socket_accept(nsc->socket, &ansc->socket, (void *)args->addr, &args->addrlen);
}
case NET_STACK_SEND: {
struct data_xfer_args * args = (struct data_xfer_args *) data;
@ -415,7 +415,7 @@ static status_t net_stack_control(void *cookie, uint32 op, void * data, size_t l
struct msghdr * mh = (struct msghdr *) data;
int retsize, error;
error = core->recvit(nsc->socket, mh, (caddr_t)&mh->msg_namelen,
error = core->socket_recv(nsc->socket, mh, (caddr_t)&mh->msg_namelen,
&retsize);
if (error == 0)
return retsize;
@ -425,7 +425,7 @@ static status_t net_stack_control(void *cookie, uint32 op, void * data, size_t l
struct msghdr * mh = (struct msghdr *) data;
int retsize, error;
error = core->sendit(nsc->socket, mh, mh->msg_flags,
error = core->socket_send(nsc->socket, mh, mh->msg_flags,
&retsize);
if (error == 0)
return retsize;
@ -439,24 +439,24 @@ static status_t net_stack_control(void *cookie, uint32 op, void * data, size_t l
}
case NET_STACK_GETSOCKOPT: {
struct sockopt_args * args = (struct sockopt_args *) data;
return core->sogetopt(nsc->socket, args->level, args->option,
return core->socket_getsockopt(nsc->socket, args->level, args->option,
args->optval, (size_t *) &args->optlen);
}
case NET_STACK_SETSOCKOPT: {
struct sockopt_args * args = (struct sockopt_args *)data;
return core->sosetopt(nsc->socket, args->level, args->option,
return core->socket_setsockopt(nsc->socket, args->level, args->option,
(const void *) args->optval, args->optlen);
}
case NET_STACK_GETSOCKNAME: {
struct sockaddr_args * args = (struct sockaddr_args *) data;
// args->addr == sockaddr to accept the sockname
return core->sogetsockname(nsc->socket, args->addr, &args->addrlen);
return core->socket_getsockname(nsc->socket, args->addr, &args->addrlen);
}
case NET_STACK_GETPEERNAME: {
struct sockaddr_args * args = (struct sockaddr_args *) data;
// args->addr == sockaddr to accept the peername
return core->sogetpeername(nsc->socket, args->addr, &args->addrlen);
return core->socket_getpeername(nsc->socket, args->addr, &args->addrlen);
}
case NET_STACK_STOP: {
core->stop();
@ -485,7 +485,7 @@ static status_t net_stack_control(void *cookie, uint32 op, void * data, size_t l
default:
if (nsc->socket)
// pass any unhandled opcode to the stack
return core->soo_ioctl(nsc->socket, op, data);
return core->socket_ioctl(nsc->socket, op, data);
return B_BAD_VALUE;
}
}
@ -519,7 +519,7 @@ static status_t net_stack_read(void *cookie,
iov.iov_base = buffer;
iov.iov_len = *readlen;
error = core->readit(nsc->socket, &iov, &flags);
error = core->socket_readv(nsc->socket, &iov, &flags);
*readlen = error;
return error;
}
@ -556,7 +556,7 @@ static status_t net_stack_write(void *cookie,
iov.iov_base = (void*)buffer;
iov.iov_len = *writelen;
error = core->writeit(nsc->socket, &iov, flags);
error = core->socket_writev(nsc->socket, &iov, flags);
*writelen = error;
return error;
}
@ -600,7 +600,7 @@ static status_t net_stack_select(void *cookie, uint8 event, uint32 ref, selectsy
release_sem(nsc->selecters_lock);
// start (or continue) to monitor for socket event
return core->set_socket_event_callback(nsc->socket, on_socket_event, nsc, event);
return core->socket_set_event_callback(nsc->socket, on_socket_event, nsc, event);
}
@ -650,7 +650,7 @@ static status_t net_stack_deselect(void *cookie, uint8 event, selectsync *sync)
if (nsc->selecters == NULL)
// selecters list is empty: no need to monitor socket events anymore
core->set_socket_event_callback(nsc->socket, NULL, NULL, event);
core->socket_set_event_callback(nsc->socket, NULL, NULL, event);
// unlock the selecters list
return release_sem(nsc->selecters_lock);

View File

@ -172,24 +172,25 @@ _EXPORT struct core_module_info core_info = {
get_primary_addr,
initsocket,
socreate,
soclose,
sobind,
solisten,
soconnect,
recvit,
sendit,
soo_ioctl,
net_sysctl,
writeit,
readit,
sosetopt,
sogetopt,
set_socket_event_callback,
sogetpeername,
sogetsockname,
soaccept
socket_init,
socket_create,
socket_close,
socket_bind,
socket_listen,
socket_connect,
socket_accept,
socket_recv,
socket_send,
socket_ioctl,
socket_writev,
socket_readv,
socket_setsockopt,
socket_getsockopt,
socket_getpeername,
socket_getsockname,
socket_set_event_callback
};
static int32 if_thread(void *data)

View File

@ -81,7 +81,7 @@ void in_pcbdetach(struct inpcb *inp)
* (SS_NOFDREF) and if there are it doesn't free. We don't have
* the same relationship to our sockets, as we use the socket for
* the kernel cookie, and freeing it here would lead to real problems,
* so we leave the socket until we call soclose()
* so we leave the socket until we call socket_close()
* This may need to be reviewed and an extra layer of abstraction
* added at some point if we find it's using too much system resource.
*/

View File

@ -106,32 +106,31 @@ int uiomove(caddr_t cp, int n, struct uio *uio)
return (error);
}
int initsocket(struct socket **sp)
int socket_init(struct socket **nso)
{
struct socket *so;
so = (struct socket*)pool_get(spool);
if (so == NULL) {
printf("initsocket: ENOMEM\n");
printf("socket_init: ENOMEM\n");
return ENOMEM;
}
memset(so, 0, sizeof(*so));
*sp = so;
*nso = so;
return 0;
}
int socreate(int dom, struct socket *sp, int type, int proto)
int socket_create(struct socket *so, int dom, int type, int proto)
{
struct protosw *prm = NULL; /* protocol module */
struct socket *so = sp;
int error;
if (so == NULL) {
printf("socreate: EINVAL\n");
printf("socket_create: EINVAL\n");
return EINVAL;
}
@ -141,12 +140,12 @@ int socreate(int dom, struct socket *sp, int type, int proto)
prm = pffindtype(dom, type);
if (!prm || !prm->pr_userreq) {
printf("socreate: EPROTONOSUPPORT\n");
printf("socket_create: EPROTONOSUPPORT\n");
return EPROTONOSUPPORT;
}
if (prm->pr_type != type) {
printf("socreate: EPROTOTYPE\n");
printf("socket_create: EPROTOTYPE\n");
return EPROTOTYPE;
}
@ -209,15 +208,14 @@ bad:
}
int sobind(void *sp, caddr_t data, int len)
int socket_bind(struct socket *so, caddr_t data, int len)
{
int error;
struct mbuf *nam;
struct socket *so = (struct socket*)sp;
nam = m_get(MT_SONAME);
if (!nam) {
printf("sobind: ENOMEM\n");
printf("socket_bind: ENOMEM\n");
return ENOMEM;
}
@ -232,9 +230,8 @@ int sobind(void *sp, caddr_t data, int len)
return error;
}
int solisten(void *sp, int backlog)
int socket_listen(struct socket *so, int backlog)
{
struct socket *so = (struct socket *)sp;
int error;
error = so->so_proto->pr_userreq(so, PRU_LISTEN, NULL, NULL, NULL);
@ -252,9 +249,8 @@ int solisten(void *sp, int backlog)
return 0;
}
int soconnect(void *sp, caddr_t data, int len)
int socket_connect(struct socket *so, caddr_t data, int len)
{
struct socket *so = (struct socket *)sp;
struct mbuf *nam = m_get(MT_SONAME);
int error;
@ -295,7 +291,7 @@ int soconnect(void *sp, caddr_t data, int len)
}
while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0)
if ((error = nsleep(so->so_timeo, "soconnect", 0)))
if ((error = nsleep(so->so_timeo, "socket_connect", 0)))
break;
if (error == 0) {
@ -317,7 +313,7 @@ struct socket *sonewconn(struct socket *head, int connstatus)
if (head->so_qlen + head->so_q0len > 3 * head->so_qlimit / 2)
return NULL;
if (initsocket(&so) < 0)
if (socket_init(&so) < 0)
return NULL;
so->so_type = head->so_type;
@ -343,9 +339,8 @@ struct socket *sonewconn(struct socket *head, int connstatus)
return so;
}
int soshutdown(void *sp, int how)
int socket_shutdown(struct socket *so, int how)
{
struct socket *so = (struct socket*)sp;
struct protosw *pr = so->so_proto;
how++;
@ -356,9 +351,8 @@ int soshutdown(void *sp, int how)
return 0;
}
int sendit(void *sp, struct msghdr *mp, int flags, int *retsize)
int socket_send(struct socket *so, struct msghdr *mp, int flags, int *retsize)
{
struct socket *so = (struct socket *)sp;
struct uio auio;
struct iovec *iov;
int i;
@ -418,9 +412,8 @@ bad:
return error;
}
int writeit(void *sp, struct iovec *iov, int flags)
int socket_writev(struct socket *so, struct iovec *iov, int flags)
{
struct socket *so = (struct socket *)sp;
struct uio auio;
int len = iov->iov_len;
int error;
@ -606,9 +599,8 @@ out:
return (error);
}
int readit(void *sp, struct iovec *iov, int *flags)
int socket_readv(struct socket *so, struct iovec *iov, int *flags)
{
struct socket *so = (struct socket *)sp;
struct uio auio;
int len = iov->iov_len;
int error;
@ -626,9 +618,8 @@ int readit(void *sp, struct iovec *iov, int *flags)
return (len - auio.uio_resid);
}
int recvit(void *sp, struct msghdr *mp, caddr_t namelenp, int *retsize)
int socket_recv(struct socket *so, struct msghdr *mp, caddr_t namelenp, int *retsize)
{
struct socket *so = (struct socket*)sp;
struct uio auio;
struct iovec *iov;
struct mbuf *control = NULL;
@ -944,10 +935,8 @@ release:
return error;
}
int soo_ioctl(void *sp, int cmd, caddr_t data)
int socket_ioctl(struct socket *so, int cmd, caddr_t data)
{
struct socket *so = (struct socket*)sp;
switch (cmd) {
case FIONBIO:
if (*(int*)data)
@ -975,9 +964,8 @@ int soo_ioctl(void *sp, int cmd, caddr_t data)
}
int soclose(void *sp)
int socket_close(struct socket *so)
{
struct socket *so = (struct socket*)sp;
int error = 0;
/* we don't want any more events... */
@ -1019,7 +1007,7 @@ drop:
discard:
if (so->so_state & SS_NOFDREF)
printf("PANIC: soclose: NOFDREF");
printf("PANIC: socket_close: NOFDREF");
so->so_state |= SS_NOFDREF;
sofree(so);
return error;
@ -1086,9 +1074,8 @@ void sofree(struct socket *so)
return;
}
int sosetopt(void *sp, int level, int optnum, const void *data, size_t datalen)
int socket_setsockopt(struct socket *so, int level, int optnum, const void *data, size_t datalen)
{
struct socket *so = (struct socket*)sp;
struct mbuf *m, *m0;
int error = 0;
@ -1193,9 +1180,8 @@ bad:
return error;
}
int sogetopt(void *sp, int level, int optnum, void *data, size_t *datalen)
int socket_getsockopt(struct socket *so, int level, int optnum, void *data, size_t *datalen)
{
struct socket *so = (struct socket*)sp;
struct mbuf *m;
m = m_get(MT_SOOPTS);
@ -1270,10 +1256,8 @@ int sogetopt(void *sp, int level, int optnum, void *data, size_t *datalen)
}
int set_socket_event_callback(void * sp, socket_event_callback cb, void * cookie, int event)
int socket_set_event_callback(struct socket *so, socket_event_callback cb, void * cookie, int event)
{
struct socket *so = (struct socket *) sp;
so->event_callback = cb;
so->event_callback_cookie = cookie;
if (cb) {
@ -1469,9 +1453,8 @@ void wakeup(sem_id chan)
}
/* This file is too big - split it up!! */
int sogetsockname(void *sp, struct sockaddr *sa, int *alen)
int socket_getsockname(struct socket *so, struct sockaddr *sa, int *alen)
{
struct socket *so = (struct socket*)sp;
struct mbuf *m = m_getclr(MT_SONAME);
int len;
int error;
@ -1490,9 +1473,8 @@ int sogetsockname(void *sp, struct sockaddr *sa, int *alen)
return error;
}
int sogetpeername(void *sp, struct sockaddr *sa, int * alen)
int socket_getpeername(struct socket *so, struct sockaddr *sa, int * alen)
{
struct socket *so = (struct socket*)sp;
struct mbuf *m = m_getclr(MT_SONAME);
int len;
int error;
@ -1513,7 +1495,7 @@ int sogetpeername(void *sp, struct sockaddr *sa, int * alen)
return error;
}
int soaccept(struct socket *so, struct socket **nsp, void *data, int *alen)
int socket_accept(struct socket *so, struct socket **nso, void *data, int *alen)
{
int len;
int error;
@ -1530,7 +1512,7 @@ int soaccept(struct socket *so, struct socket **nsp, void *data, int *alen)
so->so_error = ECONNABORTED;
break;
}
if ((error = nsleep(so->so_timeo, "soaccept", 0)))
if ((error = nsleep(so->so_timeo, "socket_accept", 0)))
return error;
}
if (so->so_error) {
@ -1542,7 +1524,7 @@ int soaccept(struct socket *so, struct socket **nsp, void *data, int *alen)
{
struct socket *aso = so->so_q;
if (soqremque(aso, 1) == 0) {
printf("PANIC: soaccept!\n");
printf("PANIC: socket_accept!\n");
return ENOMEM;
}
so = aso;
@ -1559,6 +1541,6 @@ int soaccept(struct socket *so, struct socket **nsp, void *data, int *alen)
m_freem(nam);
/* assign the socket to the cookie passed in! */
*nsp = so;
*nso = so;
return error;
}