Signaled sockets forward a signal to their server counterparts,

which interrupt the server's socket thread, deleted when the socket close.
IPC message trace now reports message name instead of hexa opcode, which
increase a little their usefullness for an human reader :-)


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5715 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin
2003-12-19 20:32:01 +00:00
parent 153f2c3012
commit 9e4f133fe8
3 changed files with 81 additions and 25 deletions
+1
View File
@@ -45,6 +45,7 @@ typedef struct {
typedef struct { typedef struct {
port_id port; port_id port;
area_id area; area_id area;
thread_id socket_thread;
sem_id commandSemaphore; // command queue sem_id commandSemaphore; // command queue
uint32 numCommands,bufferSize; uint32 numCommands,bufferSize;
@@ -95,6 +95,7 @@ typedef struct {
port_id local_port; port_id local_port;
port_id remote_port; port_id remote_port;
area_id area; area_id area;
thread_id socket_thread;
sem_id command_sem; sem_id command_sem;
net_command *commands; net_command *commands;
@@ -738,6 +739,9 @@ execute_command(net_server_cookie *nsc, uint32 op, void *data, uint32 length)
return command->result; return command->result;
} }
FATAL(("command couldn't be executed: %s\n", strerror(status))); FATAL(("command couldn't be executed: %s\n", strerror(status)));
// if (status == B_INTERRUPTED)
// Signaling our net_server counterpart, so his socket thread awake too...
// send_signal_etc(nsc->socket_thread, SIGINT, 0);
return status; return status;
} }
} }
@@ -809,6 +813,7 @@ init_connection(void **cookie)
return err; return err;
} }
nsc->socket_thread = connection.socket_thread;
nsc->nb_commands = connection.numCommands; nsc->nb_commands = connection.numCommands;
nsc->command_index = 0; nsc->command_index = 0;
nsc->selecters = NULL; nsc->selecters = NULL;
@@ -18,6 +18,44 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
typedef struct commands_info {
int op;
const char *name
} commands_info;
#define C2N(op) { op, #op }
commands_info g_commands_info[] = {
C2N(NET_STACK_SOCKET),
C2N(NET_STACK_BIND),
C2N(NET_STACK_RECVFROM),
C2N(NET_STACK_RECV),
C2N(NET_STACK_SENDTO),
C2N(NET_STACK_SEND),
C2N(NET_STACK_LISTEN),
C2N(NET_STACK_ACCEPT),
C2N(NET_STACK_CONNECT),
C2N(NET_STACK_SHUTDOWN),
C2N(NET_STACK_GETSOCKOPT),
C2N(NET_STACK_SETSOCKOPT),
C2N(NET_STACK_GETSOCKNAME),
C2N(NET_STACK_GETPEERNAME),
C2N(NET_STACK_SYSCTL),
C2N(NET_STACK_SELECT),
C2N(NET_STACK_DESELECT),
C2N(NET_STACK_GET_COOKIE),
C2N(NET_STACK_STOP),
C2N(NET_STACK_NOTIFY_SOCKET_EVENT),
C2N(NET_STACK_OPEN),
C2N(NET_STACK_CLOSE),
C2N(NET_STACK_NEW_CONNECTION),
{ 0, "Unknown!" }
};
#undef C2N
extern struct core_module_info *core; extern struct core_module_info *core;
@@ -157,6 +195,7 @@ connection_runner(void *_cookie)
{ {
connection_cookie *cookie = (connection_cookie *)_cookie; connection_cookie *cookie = (connection_cookie *)_cookie;
bool run = true; bool run = true;
commands_info *ci;
while (run) { while (run) {
net_area_info area[MAX_NET_AREAS]; net_area_info area[MAX_NET_AREAS];
@@ -178,23 +217,31 @@ connection_runner(void *_cookie)
continue; continue;
} }
ci = g_commands_info;
while(ci && ci->op) {
if (ci->op == command->op)
break;
ci++;
}
args = convert_to_local(&command->area[0],&area[0], command->data); args = convert_to_local(&command->area[0],&area[0], command->data);
printf("command %lx (index = %ld), buffer = %p, length = %ld, result = %ld\n", printf("command %s (0x%lx) (index = %ld), buffer = %p, length = %ld, result = %ld\n",
command->op, index, args, command->length, command->result); ci->name, command->op, index, args, command->length, command->result);
switch (command->op) { switch (command->op) {
case NET_STACK_OPEN: case NET_STACK_OPEN:
cookie->openFlags = args->u.integer; cookie->openFlags = args->u.integer;
printf("opening socket, mode = %lx!\n", cookie->openFlags); printf("Opening socket connection, mode = %lx!\n", cookie->openFlags);
break; break;
case NET_STACK_CLOSE: case NET_STACK_CLOSE:
printf("closing socket...\n"); printf("Closing socket connection...\n");
run = false; run = false;
break; break;
case NET_STACK_SOCKET: case NET_STACK_SOCKET:
printf("open a socket... family = %d, type = %d, proto = %d\n", printf("Creating stack socket... family = %d, type = %d, proto = %d\n",
args->u.socket.family, args->u.socket.type, args->u.socket.proto); args->u.socket.family, args->u.socket.type, args->u.socket.proto);
status = core->socket_init(&cookie->socket); status = core->socket_init(&cookie->socket);
if (status == 0) if (status == 0)
@@ -434,6 +481,8 @@ init_connection(net_connection *connection,connection_cookie **_cookie)
return B_ERROR; return B_ERROR;
} }
connection->socket_thread = cookie->runner;
connection->numCommands = NUM_COMMANDS; connection->numCommands = NUM_COMMANDS;
connection->bufferSize = CONNECTION_BUFFER_SIZE; connection->bufferSize = CONNECTION_BUFFER_SIZE;
@@ -487,7 +536,8 @@ connection_opener(void *_unused)
if (init_connection(&connection, &cookie) == B_OK) if (init_connection(&connection, &cookie) == B_OK)
write_port(port, NET_STACK_NEW_CONNECTION, &connection, sizeof(net_connection)); write_port(port, NET_STACK_NEW_CONNECTION, &connection, sizeof(net_connection));
} else } else
fprintf(stderr,"connection_opener: received unknown command: %lx (expected = %lx)\n",msg,(int32)NET_STACK_NEW_CONNECTION); fprintf(stderr, "connection_opener: received unknown command: %lx (expected = %lx)\n",
msg, (int32) NET_STACK_NEW_CONNECTION);
} }
return 0; return 0;
} }