Fix a output bug in dump_memory() where 0x7f was displayed as-is.

Add a better interface(s) reader thread handling.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3270 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin
2003-05-20 22:51:23 +00:00
parent 8f16d01827
commit 266a39bd55
2 changed files with 32 additions and 9 deletions
+2 -1
View File
@@ -842,7 +842,7 @@ void dump_memory
for (j = i; j < len && j < i+16;j++) for (j = i; j < len && j < i+16;j++)
{ {
if ( byte[j] >= ' ' && byte[j] < 0x7f ) if ( byte[j] >= ' ' && byte[j] <= 0x7e )
*ptr = byte[j]; *ptr = byte[j];
else else
*ptr = '.'; *ptr = '.';
@@ -853,6 +853,7 @@ void dump_memory
ptr++; ptr++;
*ptr = '\0'; *ptr = '\0';
if (prefix)
DPRINTF(prefix); DPRINTF(prefix);
DPRINTF(text); DPRINTF(text);
+28 -6
View File
@@ -6,7 +6,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
// #include <unistd.h> #include <signal.h>
#include <KernelExport.h> #include <KernelExport.h>
#include <OS.h> #include <OS.h>
@@ -68,6 +68,7 @@ status_t start_datalink_layer()
close_module_list(module_list); close_module_list(module_list);
}; };
// auto-start interface(s)
acquire_sem(g_interfaces.lock); acquire_sem(g_interfaces.lock);
iface = g_interfaces.first; iface = g_interfaces.first;
while (iface) { while (iface) {
@@ -169,7 +170,12 @@ status_t unregister_interface(ifnet_t *iface)
release_sem(g_interfaces.lock); release_sem(g_interfaces.lock);
printf("datalink: unregister_interface(%s)\n", iface->if_name); printf("datalink: unregister_interface(%s)\n", iface->if_name);
return iface->module->uninit(iface);
enable_interface(iface, false);
iface->module->uninit(iface);
put_module(iface->module->info.name);
free(iface);
return B_OK;
} }
@@ -177,7 +183,9 @@ status_t unregister_interface(ifnet_t *iface)
status_t enable_interface(ifnet_t *iface, bool enable) status_t enable_interface(ifnet_t *iface, bool enable)
{ {
if (enable) { if (enable) {
// enable this interface
thread_id tid; thread_id tid;
char name[B_OS_NAME_LENGTH * 2];
if (iface->if_flags & IFF_UP) if (iface->if_flags & IFF_UP)
// already up // already up
@@ -185,8 +193,9 @@ status_t enable_interface(ifnet_t *iface, bool enable)
iface->module->up(iface); iface->module->up(iface);
tid = spawn_kernel_thread(interface_reader, iface->if_name, strncpy(name, iface->if_name, sizeof(name));
B_NORMAL_PRIORITY, iface); strncat(name, " reader", sizeof(name));
tid = spawn_kernel_thread(interface_reader, name, B_NORMAL_PRIORITY, iface);
if (tid < 0) { if (tid < 0) {
printf("datalink: enable_interface(%s): failed to start reader thread -> %d [%s]\n", printf("datalink: enable_interface(%s): failed to start reader thread -> %d [%s]\n",
iface->if_name, (int) tid, strerror(tid)); iface->if_name, (int) tid, strerror(tid));
@@ -195,13 +204,25 @@ status_t enable_interface(ifnet_t *iface, bool enable)
iface->if_reader_thread = tid; iface->if_reader_thread = tid;
iface->if_flags |= IFF_UP; iface->if_flags |= IFF_UP;
printf("datalink: starting interface %s...\n", iface->if_name); printf("datalink: %s interface reader started.\n", iface->if_name);
return resume_thread(tid); return resume_thread(tid);
} else { } else {
// disable this interface
if ((iface->if_flags & IFF_UP) == 0)
// already down
return B_OK;
if (iface->if_reader_thread) { if (iface->if_reader_thread) {
kill_thread(iface->if_reader_thread); status_t status;
send_signal_etc(iface->if_reader_thread, SIGTERM, 0);
wait_for_thread(iface->if_reader_thread, &status);
iface->if_reader_thread = -1; iface->if_reader_thread = -1;
printf("datalink: %s interface reader stopped.\n", iface->if_name);
}; };
iface->if_flags &= ~IFF_UP; iface->if_flags &= ~IFF_UP;
return iface->module->down(iface); return iface->module->down(iface);
}; };
@@ -222,6 +243,7 @@ status_t interface_reader(void *args)
status = iface->module->receive_data(iface, &nd); status = iface->module->receive_data(iface, &nd);
if (status < B_OK || nd == NULL) if (status < B_OK || nd == NULL)
continue; continue;
dump_data(nd); dump_data(nd);
delete_data(nd, false); delete_data(nd, false);
}; };