added a socketpair in libsocket.so with corresponding code in the network stack driver and the network stack

socketpair() in the network stack is empty and still to be implemented for real


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14267 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2005-09-28 12:21:42 +00:00
parent b093c5d130
commit 83e02263b7
7 changed files with 65 additions and 1 deletions
+1
View File
@@ -157,6 +157,7 @@ struct core_module_info {
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_socketpair) (struct socket *so, struct socket **nso);
int (*socket_set_event_callback)(struct socket *so, socket_event_callback, void *, int);
int (*socket_shutdown) (struct socket *so, int how);
};
+2
View File
@@ -30,6 +30,8 @@ int socket_ioctl (struct socket *so, int cmd, caddr_t data);
int socket_getpeername (struct socket *so, struct sockaddr *, int *);
int socket_getsockname (struct socket *so, struct sockaddr *, int *);
int socket_pair (struct socket *so, struct socket **nso);
int socket_set_event_callback(struct socket *so, socket_event_callback, void *, int);
+6
View File
@@ -37,6 +37,7 @@ enum {
NET_STACK_SETSOCKOPT, // sockopt_args *
NET_STACK_GETSOCKNAME, // sockaddr_args *
NET_STACK_GETPEERNAME, // sockaddr_args *
NET_STACK_SOCKETPAIR, //
NET_STACK_SYSCTL, // sysctl_args *
NET_STACK_SELECT, // select_args *
@@ -79,6 +80,10 @@ struct socket_args { // used by NET_STACK_SOCKET
int proto;
};
struct socketpair_args { // used by NET_STACK_SOCKETPAIR
void *cookie;
};
struct accept_args { // used by NET_STACK_ACCEPT
void *cookie;
struct sockaddr *addr;
@@ -156,6 +161,7 @@ struct stack_driver_args {
struct sysctl_args sysctl;
struct select_args select;
struct control_net_module_args control;
struct socketpair_args socketpair;
} u;
};
@@ -433,7 +433,11 @@ static status_t net_stack_control(void *cookie, uint32 op, void *data, size_t le
case NET_STACK_GETPEERNAME:
return g_core->socket_getpeername(nsc->socket, args->u.sockaddr.addr, &args->u.sockaddr.addrlen);
case NET_STACK_SOCKETPAIR: {
net_stack_cookie *ansc = args->u.socketpair.cookie;
return g_core->socket_socketpair(nsc->socket, &ansc->socket);
}
case B_SET_BLOCKING_IO: {
int off = false;
nsc->open_flags &= ~O_NONBLOCK;
+1
View File
@@ -207,6 +207,7 @@ struct core_module_info core_info = {
socket_getsockopt,
socket_getpeername,
socket_getsockname,
socket_socketpair,
socket_set_event_callback,
socket_shutdown
};
+9
View File
@@ -1565,3 +1565,12 @@ int socket_accept(struct socket *so, struct socket **nso, void *data, int *alen)
*nso = so;
return error;
}
void
socket_socketpair(struct socket *so, struct socket **nso)
{
// TODO : implement, eventually fill nso with a new cookie
return ENOIMPL;
}
+41
View File
@@ -282,6 +282,47 @@ _EXPORT int getsockname(int sock, struct sockaddr *addr, int *addrlen)
return rv;
}
_EXPORT int socketpair(int family, int type, int protocol, int socket_vector[2])
{
struct stack_driver_args args;
int rv;
void *cookie;
socket_vector[0] = socket(family, type, protocol);
if (socket_vector[0] < 0) {
return socket_vector[0];
}
socket_vector[1] = socket(family, type, protocol);
if (socket_vector[1] < 0) {
close(socket_vector[0]);
return socket_vector[1];
}
// The network stack driver will need to know to which net_stack_cookie to
// *bind* with the new accepted socket. He can't know himself find out
// the net_stack_cookie of our new_sock file descriptor, the just open() one...
// So, here, we ask him the net_stack_cookie value for our fd... :-)
rv = ioctl(socket_vector[1], NET_STACK_GET_COOKIE, &cookie);
if (rv < 0) {
close(socket_vector[0]);
close(socket_vector[1]);
return rv;
}
args.u.socketpair.cookie = cookie; // this way driver can use the right fd/cookie!
rv = ioctl(socket_vector[0], NET_STACK_SOCKETPAIR, &args, sizeof(args));
if (rv < 0) {
close(socket_vector[0]);
close(socket_vector[1]);
return rv;
}
return rv;
}
// #pragma mark -