Export socket_shutdown from stack core module.
Fix and build again net_server_driver. Rollback to NET_STACK_GET_COOKIE trick for accept() implementation. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3926 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
bf09be1c1e
commit
2a1f1e5a23
@ -16,11 +16,11 @@ R5KernelAddon net_server_driver : kernel drivers bin :
|
|||||||
# ;
|
# ;
|
||||||
|
|
||||||
# b) Kernelland stack version:
|
# b) Kernelland stack version:
|
||||||
#
|
|
||||||
R5KernelAddon net_stack_driver : kernel drivers bin :
|
R5KernelAddon net_stack_driver : kernel drivers bin :
|
||||||
net_stack_driver.c
|
net_stack_driver.c
|
||||||
;
|
;
|
||||||
#
|
|
||||||
# For OpenBeOS we should be building the kernel stack driver objects this way.
|
# For OpenBeOS we should be building the kernel stack driver objects this way.
|
||||||
#KernelObjects
|
#KernelObjects
|
||||||
# net_stack_driver.c
|
# net_stack_driver.c
|
||||||
|
@ -102,7 +102,7 @@ typedef struct {
|
|||||||
|
|
||||||
sem_id selecters_lock; // protect the selecters linked-list
|
sem_id selecters_lock; // protect the selecters linked-list
|
||||||
selecter * selecters; // the select()'ers lists (thread-aware)
|
selecter * selecters; // the select()'ers lists (thread-aware)
|
||||||
} net_stack_cookie;
|
} net_server_cookie;
|
||||||
|
|
||||||
|
|
||||||
//*****************************************************/
|
//*****************************************************/
|
||||||
@ -110,16 +110,16 @@ typedef struct {
|
|||||||
//*****************************************************/
|
//*****************************************************/
|
||||||
|
|
||||||
/* device hooks */
|
/* device hooks */
|
||||||
static status_t net_stack_open(const char * name, uint32 flags, void ** cookie);
|
static status_t net_server_open(const char * name, uint32 flags, void ** cookie);
|
||||||
static status_t net_stack_close(void * cookie);
|
static status_t net_server_close(void * cookie);
|
||||||
static status_t net_stack_free_cookie(void * cookie);
|
static status_t net_server_free_cookie(void * cookie);
|
||||||
static status_t net_stack_control(void * cookie, uint32 msg,void * data, size_t datalen);
|
static status_t net_server_control(void * cookie, uint32 msg,void * data, size_t datalen);
|
||||||
static status_t net_stack_read(void * cookie, off_t pos, void * data, size_t * datalen);
|
static status_t net_server_read(void * cookie, off_t pos, void * data, size_t * datalen);
|
||||||
static status_t net_stack_write(void * cookie, off_t pos, const void * data, size_t * datalen);
|
static status_t net_server_write(void * cookie, off_t pos, const void * data, size_t * datalen);
|
||||||
static status_t net_stack_select(void *cookie, uint8 event, uint32 ref, selectsync *sync);
|
static status_t net_server_select(void *cookie, uint8 event, uint32 ref, selectsync *sync);
|
||||||
static status_t net_stack_deselect(void *cookie, uint8 event, selectsync *sync);
|
static status_t net_server_deselect(void *cookie, uint8 event, selectsync *sync);
|
||||||
// static status_t net_stack_readv(void * cookie, off_t pos, const iovec * vec, size_t count, size_t * len);
|
// static status_t net_server_readv(void * cookie, off_t pos, const iovec * vec, size_t count, size_t * len);
|
||||||
// static status_t net_stack_writev(void * cookie, off_t pos, const iovec * vec, size_t count, size_t * len);
|
// static status_t net_server_writev(void * cookie, off_t pos, const iovec * vec, size_t count, size_t * len);
|
||||||
|
|
||||||
/* select() support */
|
/* select() support */
|
||||||
static int32 socket_event_listener(void * data);
|
static int32 socket_event_listener(void * data);
|
||||||
@ -128,30 +128,33 @@ static void r5_notify_select_event(selectsync *sync, uint32 ref);
|
|||||||
|
|
||||||
/* command queue */
|
/* command queue */
|
||||||
static status_t init_connection(void **cookie);
|
static status_t init_connection(void **cookie);
|
||||||
static void shutdown_connection(net_stack_cookie *nsc);
|
static void shutdown_connection(net_server_cookie *nsc);
|
||||||
static net_command *get_command(net_stack_cookie *nsc, int32 *index);
|
static net_command *get_command(net_server_cookie *nsc, int32 *index);
|
||||||
static status_t execute_command(net_stack_cookie *nsc, int32 op, void *data, uint32 length);
|
static status_t execute_command(net_server_cookie *nsc, int32 op, void *data, uint32 length);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Global variables
|
* Global variables
|
||||||
* ----------------
|
* ----------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define NET_SERVER_DRIVER_DEV "net/server"
|
||||||
|
#define NET_SERVER_DRIVER_PATH "/dev/" ## NET_SERVER_DRIVER_DEV
|
||||||
|
|
||||||
const char * g_device_names_list[] = {
|
const char * g_device_names_list[] = {
|
||||||
"net/server",
|
"net/server",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
device_hooks g_net_stack_driver_hooks =
|
device_hooks g_net_server_driver_hooks =
|
||||||
{
|
{
|
||||||
net_stack_open, /* -> open entry point */
|
net_server_open, /* -> open entry point */
|
||||||
net_stack_close, /* -> close entry point */
|
net_server_close, /* -> close entry point */
|
||||||
net_stack_free_cookie, /* -> free entry point */
|
net_server_free_cookie, /* -> free entry point */
|
||||||
net_stack_control, /* -> control entry point */
|
net_server_control, /* -> control entry point */
|
||||||
net_stack_read, /* -> read entry point */
|
net_server_read, /* -> read entry point */
|
||||||
net_stack_write, /* -> write entry point */
|
net_server_write, /* -> write entry point */
|
||||||
net_stack_select, /* -> select entry point */
|
net_server_select, /* -> select entry point */
|
||||||
net_stack_deselect, /* -> deselect entry point */
|
net_server_deselect, /* -> deselect entry point */
|
||||||
NULL, /* -> readv entry pint */
|
NULL, /* -> readv entry pint */
|
||||||
NULL /* -> writev entry point */
|
NULL /* -> writev entry point */
|
||||||
};
|
};
|
||||||
@ -230,7 +233,7 @@ _EXPORT device_hooks *
|
|||||||
find_device(const char *deviceName)
|
find_device(const char *deviceName)
|
||||||
{
|
{
|
||||||
FUNCTION();
|
FUNCTION();
|
||||||
return &g_net_stack_driver_hooks;
|
return &g_net_server_driver_hooks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -241,9 +244,9 @@ find_device(const char *deviceName)
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
net_stack_open(const char *name, uint32 flags, void ** cookie)
|
net_server_open(const char *name, uint32 flags, void **cookie)
|
||||||
{
|
{
|
||||||
net_stack_cookie * nsc;
|
net_server_cookie *nsc;
|
||||||
|
|
||||||
status_t status = init_connection(cookie);
|
status_t status = init_connection(cookie);
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
@ -253,16 +256,16 @@ net_stack_open(const char *name, uint32 flags, void ** cookie)
|
|||||||
|
|
||||||
status = execute_command(nsc, NET_STACK_OPEN, &flags, sizeof(uint32));
|
status = execute_command(nsc, NET_STACK_OPEN, &flags, sizeof(uint32));
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
net_stack_free_cookie(nsc);
|
net_server_free_cookie(nsc);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
net_stack_close(void *cookie)
|
net_server_close(void *cookie)
|
||||||
{
|
{
|
||||||
net_stack_cookie * nsc = (net_stack_cookie *) cookie;
|
net_server_cookie *nsc = cookie;
|
||||||
if (nsc == NULL)
|
if (nsc == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
@ -275,9 +278,9 @@ net_stack_close(void *cookie)
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
net_stack_free_cookie(void *cookie)
|
net_server_free_cookie(void *cookie)
|
||||||
{
|
{
|
||||||
net_stack_cookie * nsc = (net_stack_cookie *) cookie;
|
net_server_cookie *nsc = cookie;
|
||||||
if (nsc == NULL)
|
if (nsc == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
@ -287,9 +290,10 @@ net_stack_free_cookie(void *cookie)
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
net_stack_control(void *cookie, uint32 op, void *data, size_t length)
|
net_server_control(void *cookie, uint32 op, void *data, size_t length)
|
||||||
{
|
{
|
||||||
net_stack_cookie * nsc = (net_stack_cookie *) cookie;
|
net_server_cookie *nsc = cookie;
|
||||||
|
struct stack_driver_args *args = data;
|
||||||
|
|
||||||
//FUNCTION_START(("cookie = %p, op = %lx, data = %p, length = %ld\n", cookie, op, data, length));
|
//FUNCTION_START(("cookie = %p, op = %lx, data = %p, length = %ld\n", cookie, op, data, length));
|
||||||
|
|
||||||
@ -297,19 +301,16 @@ net_stack_control(void *cookie, uint32 op, void *data, size_t length)
|
|||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case NET_STACK_SELECT: {
|
case NET_STACK_SELECT:
|
||||||
struct select_args *args = (struct select_args *) data;
|
|
||||||
|
|
||||||
// if we get this call via ioctl() we are obviously called from an
|
// if we get this call via ioctl() we are obviously called from an
|
||||||
// R5 compatible libnet: we are using the r5 kernel select() call,
|
// R5 compatible libnet: we are using the r5 kernel select() call,
|
||||||
// So, we can't use the kernel notify_select_event(), but our own implementation!
|
// So, we can't use the kernel notify_select_event(), but our own implementation!
|
||||||
g_nse = r5_notify_select_event;
|
g_nse = r5_notify_select_event;
|
||||||
return net_stack_select(cookie, (args->ref & 0x0F), args->ref, args->sync);
|
return net_server_select(cookie, (args->u.select.ref & 0x0F), args->u.select.ref, args->u.select.sync);
|
||||||
}
|
|
||||||
case NET_STACK_DESELECT: {
|
case NET_STACK_DESELECT:
|
||||||
struct select_args * args = (struct select_args *) data;
|
return net_server_deselect(cookie, (args->u.select.ref & 0x0F), args->u.select.sync);
|
||||||
return net_stack_deselect(cookie, (args->ref & 0x0F), args->sync);
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return execute_command(nsc, op, data, -1);
|
return execute_command(nsc, op, data, -1);
|
||||||
};
|
};
|
||||||
@ -317,15 +318,15 @@ net_stack_control(void *cookie, uint32 op, void *data, size_t length)
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
net_stack_read(void *cookie, off_t pos, void *buffer, size_t *length)
|
net_server_read(void *cookie, off_t pos, void *buffer, size_t *length)
|
||||||
{
|
{
|
||||||
net_stack_cookie * nsc = (net_stack_cookie *) cookie;
|
net_server_cookie *nsc = cookie;
|
||||||
struct data_xfer_args args;
|
struct stack_driver_args args;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
memset(&args, 0, sizeof(args));
|
memset(&args, 0, sizeof(args));
|
||||||
args.data = buffer;
|
args.u.transfer.data = buffer;
|
||||||
args.datalen = *length;
|
args.u.transfer.datalen = *length;
|
||||||
|
|
||||||
status = execute_command(nsc, NET_STACK_RECV, &args, sizeof(args));
|
status = execute_command(nsc, NET_STACK_RECV, &args, sizeof(args));
|
||||||
if (status > 0) {
|
if (status > 0) {
|
||||||
@ -337,15 +338,15 @@ net_stack_read(void *cookie, off_t pos, void *buffer, size_t *length)
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
net_stack_write(void *cookie, off_t pos, const void *buffer, size_t *length)
|
net_server_write(void *cookie, off_t pos, const void *buffer, size_t *length)
|
||||||
{
|
{
|
||||||
net_stack_cookie * nsc = (net_stack_cookie *) cookie;
|
net_server_cookie *nsc = cookie;
|
||||||
struct data_xfer_args args;
|
struct stack_driver_args args;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
memset(&args, 0, sizeof(args));
|
memset(&args, 0, sizeof(args));
|
||||||
args.data = (void *) buffer;
|
args.u.transfer.data = (void *) buffer;
|
||||||
args.datalen = *length;
|
args.u.transfer.datalen = *length;
|
||||||
|
|
||||||
status = execute_command(nsc, NET_STACK_SEND, &args, sizeof(args));
|
status = execute_command(nsc, NET_STACK_SEND, &args, sizeof(args));
|
||||||
if (status > 0) {
|
if (status > 0) {
|
||||||
@ -357,11 +358,11 @@ net_stack_write(void *cookie, off_t pos, const void *buffer, size_t *length)
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
net_stack_select(void *cookie, uint8 event, uint32 ref, selectsync *sync)
|
net_server_select(void *cookie, uint8 event, uint32 ref, selectsync *sync)
|
||||||
{
|
{
|
||||||
net_stack_cookie * nsc = (net_stack_cookie *) cookie;
|
net_server_cookie *nsc = cookie;
|
||||||
struct notify_socket_event_args args;
|
struct notify_socket_event_args args;
|
||||||
selecter * s;
|
selecter *s;
|
||||||
status_t status;
|
status_t status;
|
||||||
|
|
||||||
FUNCTION_START(("cookie = %p, event = %d, ref = %lx, sync =%p\n", cookie, event, ref, sync));
|
FUNCTION_START(("cookie = %p, event = %d, ref = %lx, sync =%p\n", cookie, event, ref, sync));
|
||||||
@ -400,11 +401,11 @@ net_stack_select(void *cookie, uint8 event, uint32 ref, selectsync *sync)
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
net_stack_deselect(void *cookie, uint8 event, selectsync *sync)
|
net_server_deselect(void *cookie, uint8 event, selectsync *sync)
|
||||||
{
|
{
|
||||||
net_stack_cookie *nsc = (net_stack_cookie *) cookie;
|
net_server_cookie *nsc = cookie;
|
||||||
selecter * previous;
|
selecter *previous;
|
||||||
selecter * s;
|
selecter *s;
|
||||||
thread_id current_thread;
|
thread_id current_thread;
|
||||||
status_t status;
|
status_t status;
|
||||||
|
|
||||||
@ -476,7 +477,7 @@ net_stack_deselect(void *cookie, uint8 event, selectsync *sync)
|
|||||||
Okay, I should stop watch this movie *now*.
|
Okay, I should stop watch this movie *now*.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int32 socket_event_listener(void * data)
|
static int32 socket_event_listener(void *data)
|
||||||
{
|
{
|
||||||
struct socket_event_data sed;
|
struct socket_event_data sed;
|
||||||
int32 msg;
|
int32 msg;
|
||||||
@ -495,10 +496,10 @@ static int32 socket_event_listener(void * data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void on_socket_event(void * socket, uint32 event, void * cookie)
|
static void on_socket_event(void *socket, uint32 event, void *cookie)
|
||||||
{
|
{
|
||||||
net_stack_cookie * nsc = (net_stack_cookie *) cookie;
|
net_server_cookie *nsc = cookie;
|
||||||
selecter * s;
|
selecter *s;
|
||||||
|
|
||||||
if (!nsc)
|
if (!nsc)
|
||||||
return;
|
return;
|
||||||
@ -529,10 +530,10 @@ static void on_socket_event(void * socket, uint32 event, void * cookie)
|
|||||||
So, here is our own notify_select_event() implementation, the driver-side pair
|
So, here is our own notify_select_event() implementation, the driver-side pair
|
||||||
of the our libnet.so select() implementation...
|
of the our libnet.so select() implementation...
|
||||||
*/
|
*/
|
||||||
static void r5_notify_select_event(selectsync * sync, uint32 ref)
|
static void r5_notify_select_event(selectsync *sync, uint32 ref)
|
||||||
{
|
{
|
||||||
area_id area;
|
area_id area;
|
||||||
struct r5_selectsync * rss;
|
struct r5_selectsync *rss;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
FUNCTION_START(("sync = %p, ref = %lx\n", sync, ref));
|
FUNCTION_START(("sync = %p, ref = %lx\n", sync, ref));
|
||||||
@ -589,7 +590,7 @@ error:
|
|||||||
|
|
||||||
|
|
||||||
static net_command *
|
static net_command *
|
||||||
get_command(net_stack_cookie *nsc, int32 *index)
|
get_command(net_server_cookie *nsc, int32 *index)
|
||||||
{
|
{
|
||||||
int32 i, count = 0;
|
int32 i, count = 0;
|
||||||
net_command *command;
|
net_command *command;
|
||||||
@ -632,77 +633,60 @@ get_area_from_address(net_area_info *info, void *data)
|
|||||||
static void
|
static void
|
||||||
set_command_areas(net_command *command)
|
set_command_areas(net_command *command)
|
||||||
{
|
{
|
||||||
void *data = command->data;
|
struct stack_driver_args *args = (void *) command->data;
|
||||||
if (data == NULL)
|
|
||||||
|
if (args == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (get_area_from_address(&command->area[0],data) < B_OK)
|
if (get_area_from_address(&command->area[0], args) < B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch (command->op) {
|
switch (command->op) {
|
||||||
case NET_STACK_GETSOCKOPT:
|
case NET_STACK_GETSOCKOPT:
|
||||||
case NET_STACK_SETSOCKOPT:
|
case NET_STACK_SETSOCKOPT:
|
||||||
{
|
get_area_from_address(&command->area[1], args->u.sockopt.optval);
|
||||||
struct sockopt_args *sockopt = (struct sockopt_args *)data;
|
|
||||||
|
|
||||||
get_area_from_address(&command->area[1],sockopt->optval);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case NET_STACK_CONNECT:
|
case NET_STACK_CONNECT:
|
||||||
case NET_STACK_BIND:
|
case NET_STACK_BIND:
|
||||||
case NET_STACK_GETSOCKNAME:
|
case NET_STACK_GETSOCKNAME:
|
||||||
case NET_STACK_GETPEERNAME:
|
case NET_STACK_GETPEERNAME:
|
||||||
{
|
get_area_from_address(&command->area[1], args->u.sockaddr.addr);
|
||||||
struct sockaddr_args *args = (struct sockaddr_args *)data;
|
|
||||||
|
|
||||||
get_area_from_address(&command->area[1],args->addr);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case NET_STACK_RECV:
|
case NET_STACK_RECV:
|
||||||
case NET_STACK_SEND:
|
case NET_STACK_SEND:
|
||||||
{
|
get_area_from_address(&command->area[1], args->u.transfer.data);
|
||||||
struct data_xfer_args *args = (struct data_xfer_args *)data;
|
get_area_from_address(&command->area[2], args->u.transfer.addr);
|
||||||
get_area_from_address(&command->area[1],args->data);
|
|
||||||
get_area_from_address(&command->area[2],args->addr);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case NET_STACK_RECVFROM:
|
case NET_STACK_RECVFROM:
|
||||||
case NET_STACK_SENDTO:
|
case NET_STACK_SENDTO: {
|
||||||
{
|
struct msghdr *mh = (void *) args;
|
||||||
struct msghdr *mh = (struct msghdr *)data;
|
|
||||||
get_area_from_address(&command->area[1],mh->msg_name);
|
get_area_from_address(&command->area[1],mh->msg_name);
|
||||||
get_area_from_address(&command->area[2],mh->msg_iov);
|
get_area_from_address(&command->area[2],mh->msg_iov);
|
||||||
get_area_from_address(&command->area[3],mh->msg_control);
|
get_area_from_address(&command->area[3],mh->msg_control);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case NET_STACK_ACCEPT:
|
case NET_STACK_ACCEPT:
|
||||||
{
|
/* accept_args.cookie is always in the address space of the server */
|
||||||
struct accept_args *args = (struct accept_args *)data;
|
get_area_from_address(&command->area[1], args->u.accept.addr);
|
||||||
/* accept_args.cookie is always in the address space of the server */
|
break;
|
||||||
get_area_from_address(&command->area[1],args->addr);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case NET_STACK_SYSCTL:
|
case NET_STACK_SYSCTL:
|
||||||
{
|
get_area_from_address(&command->area[1], args->u.sysctl.name);
|
||||||
struct sysctl_args *sysctl = (struct sysctl_args *)data;
|
get_area_from_address(&command->area[2], args->u.sysctl.oldp);
|
||||||
|
get_area_from_address(&command->area[3], args->u.sysctl.oldlenp);
|
||||||
get_area_from_address(&command->area[1],sysctl->name);
|
get_area_from_address(&command->area[4], args->u.sysctl.newp);
|
||||||
get_area_from_address(&command->area[2],sysctl->oldp);
|
|
||||||
get_area_from_address(&command->area[3],sysctl->oldlenp);
|
|
||||||
get_area_from_address(&command->area[4],sysctl->newp);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO/FIXME: phoudoin: where are these opcodes defined!?!
|
TODO/FIXME: phoudoin: where are these opcodes defined!?!
|
||||||
case OSIOCGIFCONF:
|
case OSIOCGIFCONF:
|
||||||
case SIOCGIFCONF:
|
case SIOCGIFCONF:
|
||||||
{
|
{
|
||||||
struct ifconf *ifc = (struct ifconf *)data;
|
struct ifconf *ifc = data;
|
||||||
|
|
||||||
get_area_from_address(&command->area[1],ifc->ifc_buf);
|
get_area_from_address(&command->area[1],ifc->ifc_buf);
|
||||||
break;
|
break;
|
||||||
@ -713,7 +697,7 @@ set_command_areas(net_command *command)
|
|||||||
|
|
||||||
|
|
||||||
static status_t
|
static status_t
|
||||||
execute_command(net_stack_cookie *nsc, int32 op, void *data, uint32 length)
|
execute_command(net_server_cookie *nsc, int32 op, void *data, uint32 length)
|
||||||
{
|
{
|
||||||
uint32 command_index;
|
uint32 command_index;
|
||||||
net_command *command = get_command(nsc, (long *) &command_index);
|
net_command *command = get_command(nsc, (long *) &command_index);
|
||||||
@ -769,7 +753,7 @@ init_connection(void **cookie)
|
|||||||
ssize_t bytes;
|
ssize_t bytes;
|
||||||
int32 msg;
|
int32 msg;
|
||||||
|
|
||||||
net_stack_cookie * nsc = (net_stack_cookie *) malloc(sizeof(net_stack_cookie));
|
net_server_cookie *nsc = (net_server_cookie *) malloc(sizeof(net_server_cookie));
|
||||||
if (nsc == NULL)
|
if (nsc == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
@ -849,9 +833,9 @@ init_connection(void **cookie)
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
shutdown_connection(net_stack_cookie *nsc)
|
shutdown_connection(net_server_cookie *nsc)
|
||||||
{
|
{
|
||||||
selecter * s;
|
selecter *s;
|
||||||
|
|
||||||
delete_area(nsc->area);
|
delete_area(nsc->area);
|
||||||
delete_port(nsc->local_port);
|
delete_port(nsc->local_port);
|
||||||
|
@ -366,55 +366,46 @@ static status_t net_stack_control(void *cookie, uint32 op, void *data, size_t le
|
|||||||
// TODO: This is where the open flags need to be addressed
|
// TODO: This is where the open flags need to be addressed
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
case NET_STACK_ASSOCIATE_SOCKET:
|
case NET_STACK_GET_COOKIE: {
|
||||||
nsc->socket = args->u.associate.socket;
|
/* this is needed by accept() call, allowing libnet.so accept() to pass back
|
||||||
|
* in NET_STACK_ACCEPT opcode the cookie (aka the net_stack_cookie!)
|
||||||
|
* of the filedescriptor to use for the new accepted socket
|
||||||
|
*/
|
||||||
|
|
||||||
|
*((void **) data) = cookie;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case NET_STACK_CONNECT:
|
case NET_STACK_CONNECT:
|
||||||
return core->socket_connect(nsc->socket, (caddr_t) args->u.sockaddr.addr, args->u.sockaddr.addrlen);
|
return core->socket_connect(nsc->socket, (caddr_t) args->u.sockaddr.addr, args->u.sockaddr.addrlen);
|
||||||
|
|
||||||
|
case NET_STACK_SHUTDOWN:
|
||||||
|
return core->socket_shutdown(nsc->socket, args->u.integer);
|
||||||
|
|
||||||
case NET_STACK_BIND:
|
case NET_STACK_BIND:
|
||||||
return core->socket_bind(nsc->socket, (caddr_t) args->u.sockaddr.addr, args->u.sockaddr.addrlen);
|
return core->socket_bind(nsc->socket, (caddr_t) args->u.sockaddr.addr, args->u.sockaddr.addrlen);
|
||||||
|
|
||||||
case NET_STACK_LISTEN:
|
case NET_STACK_LISTEN:
|
||||||
// backlog to set
|
// backlog to set
|
||||||
return core->socket_listen(nsc->socket, args->u.integer.value);
|
return core->socket_listen(nsc->socket, args->u.integer);
|
||||||
|
|
||||||
case NET_STACK_ACCEPT: {
|
case NET_STACK_ACCEPT: {
|
||||||
int fd;
|
/* args->u.accept.cookie == net_stack_cookie of the already opened fd
|
||||||
struct socket *s;
|
* in libnet.so accept() call to bind to newly accepted socket
|
||||||
struct associate_socket_args associate;
|
*/
|
||||||
|
|
||||||
err = core->socket_accept(nsc->socket, &s, (void *) args->u.sockaddr.addr, &args->u.sockaddr.addrlen);
|
net_stack_cookie *ansc = args->u.accept.cookie;
|
||||||
if (err < 0)
|
return core->socket_accept(nsc->socket, &ansc->socket, (void *)args->u.accept.addr, &args->u.accept.addrlen);
|
||||||
return err;
|
|
||||||
|
|
||||||
// Okay, we have a new socket, but it should be a file descriptor too:
|
|
||||||
fd = open(NET_STACK_DRIVER_PATH, O_RDWR);
|
|
||||||
if (fd < 0) {
|
|
||||||
core->socket_close(s);
|
|
||||||
return fd;
|
|
||||||
};
|
|
||||||
|
|
||||||
associate.socket = s;
|
|
||||||
err = ioctl(fd, NET_STACK_ASSOCIATE_SOCKET, &associate, sizeof(associate));
|
|
||||||
if (err < 0) {
|
|
||||||
core->socket_close(s);
|
|
||||||
close(fd);
|
|
||||||
return err;
|
|
||||||
};
|
|
||||||
|
|
||||||
return fd;
|
|
||||||
}
|
}
|
||||||
case NET_STACK_SEND:
|
case NET_STACK_SEND:
|
||||||
// TODO: flags gets ignored here...
|
// TODO: flags gets ignored here...
|
||||||
return net_stack_write(cookie, 0, args->u.xfer.data, &args->u.xfer.datalen);
|
return net_stack_write(cookie, 0, args->u.transfer.data, &args->u.transfer.datalen);
|
||||||
|
|
||||||
case NET_STACK_RECV:
|
case NET_STACK_RECV:
|
||||||
// TODO: flags gets ignored here...
|
// TODO: flags gets ignored here...
|
||||||
return net_stack_read(cookie, 0, args->u.xfer.data, &args->u.xfer.datalen);
|
return net_stack_read(cookie, 0, args->u.transfer.data, &args->u.transfer.datalen);
|
||||||
|
|
||||||
case NET_STACK_RECVFROM: {
|
case NET_STACK_RECVFROM: {
|
||||||
struct msghdr * mh = (struct msghdr *) data;
|
struct msghdr * mh = (struct msghdr *) data;
|
||||||
@ -454,7 +445,7 @@ static status_t net_stack_control(void *cookie, uint32 op, void *data, size_t le
|
|||||||
|
|
||||||
case NET_STACK_GETPEERNAME:
|
case NET_STACK_GETPEERNAME:
|
||||||
return core->socket_getpeername(nsc->socket, args->u.sockaddr.addr, &args->u.sockaddr.addrlen);
|
return core->socket_getpeername(nsc->socket, args->u.sockaddr.addr, &args->u.sockaddr.addrlen);
|
||||||
|
|
||||||
case B_SET_BLOCKING_IO:
|
case B_SET_BLOCKING_IO:
|
||||||
nsc->open_flags &= ~O_NONBLOCK;
|
nsc->open_flags &= ~O_NONBLOCK;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
@ -187,7 +187,8 @@ struct core_module_info core_info = {
|
|||||||
socket_getsockopt,
|
socket_getsockopt,
|
||||||
socket_getpeername,
|
socket_getpeername,
|
||||||
socket_getsockname,
|
socket_getsockname,
|
||||||
socket_set_event_callback
|
socket_set_event_callback,
|
||||||
|
socket_shutdown
|
||||||
};
|
};
|
||||||
|
|
||||||
static int32 if_thread(void *data)
|
static int32 if_thread(void *data)
|
||||||
|
Loading…
Reference in New Issue
Block a user