From 1883b2ce7a917995d5fd7092eb60696f4e665d13 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Sat, 5 May 2012 02:20:05 -0400 Subject: [PATCH] fix bugs --- driver.c | 8 ++++++-- marignotti.h | 2 +- mattach.c | 2 +- mconnect.c | 6 +++++- mdetach.c | 6 ++++-- mread.c | 2 +- table.c | 40 +++++++++++++++++++++++++++++++--------- 7 files changed, 49 insertions(+), 17 deletions(-) diff --git a/driver.c b/driver.c index 0df86b2..a51a72f 100644 --- a/driver.c +++ b/driver.c @@ -2,6 +2,7 @@ #include #include #include "net.h" +#include "s16debug.h" #pragma noroot #pragma optimize 79 @@ -13,12 +14,12 @@ int block(int sem) return xerrno; } -int queue_command(Entry *e, word command, LongWord cookie, LongWord timeout) +int queue_command(Entry *e, Word command, LongWord cookie, LongWord timeout) { int xerrno; SEI(); - e->command = kCommandRead; + e->command = command; e->cookie = cookie; e->timeout = timeout; CLI(); @@ -44,6 +45,9 @@ int driver( int rv; Entry *e; + s16_debug_printf("driver: %04x : %04x", socknum, req); + + if (req == PRU_ATTACH) { return mattach(socknum, p1, p2, p3, p4, p5); diff --git a/marignotti.h b/marignotti.h index bb5c50e..fd93c43 100644 --- a/marignotti.h +++ b/marignotti.h @@ -63,7 +63,7 @@ typedef struct xsockaddr_in { #define CLI() asm { cli } int block(int sem); -int queue_command(Entry *e, word command, LongWord cookie, LongWord timeout); +int queue_command(Entry *e, Word command, LongWord cookie, LongWord timeout); void init_table(void); void destroy_table(void); diff --git a/mattach.c b/mattach.c index 70c62f8..9c98eb7 100644 --- a/mattach.c +++ b/mattach.c @@ -18,7 +18,7 @@ int mattach(int type, void *p1, void *p2, void *p3, void *p4, void *p5) int protocol = *(int *)p3; if (type != SOCK_STREAM) return ESOCKTNOSUPPORT; - if (protocol != 6) return EPROTONOSUPPORT; + //if (protocol != 6) return EPROTONOSUPPORT; // TODO -- check protocol? 6 = tcp, 1 = icmp, 17 = udp. IncBusy(); diff --git a/mconnect.c b/mconnect.c index 4f7f1f9..12b13f2 100644 --- a/mconnect.c +++ b/mconnect.c @@ -2,6 +2,7 @@ #include #include #include +#include "s16debug.h" #pragma noroot #pragma optimize 79 @@ -76,6 +77,9 @@ int mconnect(Entry *e, void *p1, void *p2, void *p3, void *p4, void *p5) xerrno = queue_command(e, kCommandConnect, 0, timeout); + s16_debug_printf("mconnect: %d - %d - %d", + e->semaphore, xerrno, e->command); + // hmmm .. should these abort? if (xerrno == EINTR) { @@ -98,7 +102,7 @@ int mconnect(Entry *e, void *p1, void *p2, void *p3, void *p4, void *p5) // todo -- differentiate ECONNREFUSED vs EHOSTUNREACH return ECONNREFUSED; - if (timeout && timeout > GetTick()) + if (timeout && timeout <= GetTick()) { IncBusy(); TCPIPAbortTCP(e->ipid); diff --git a/mdetach.c b/mdetach.c index 571f3ea..0a8b1b1 100644 --- a/mdetach.c +++ b/mdetach.c @@ -1,7 +1,7 @@ #include "marignotti.h" #include #include - +#include #pragma noroot #pragma optimize 79 @@ -11,11 +11,13 @@ int mdetach(Entry *e, void *p1, void *p2, void *p3, void *p4, void *p5) { // TODO -- SO_LINGER/SO_LINGER_SEC + LongWord timeout; + timeout = GetTick() + 5 * 60; SEI(); e->command = kCommandDisconnectAndLogout; e->cookie = 0; - e->timeout = 0; + e->timeout = timeout; CLI(); return 0; diff --git a/mread.c b/mread.c index 4e3d28c..2f46110 100644 --- a/mread.c +++ b/mread.c @@ -104,7 +104,7 @@ int mread(Entry *e, void *p1, void *p2, void *p3, void *p4, void *p5) return 0; } - if (timeout && timeout > GetTick()) + if (timeout && timeout <= GetTick()) return EAGAIN; } diff --git a/table.c b/table.c index f638bfa..b6cca7e 100644 --- a/table.c +++ b/table.c @@ -2,6 +2,8 @@ #include #include +#include "s16debug.h" + #pragma optimize 79 #pragma noroot @@ -109,7 +111,6 @@ void process_table(void) Entry *next; Entry *prev; - tick = GetTick(); for (i = 0; i < TABLE_SIZE; ++i) { @@ -117,18 +118,21 @@ void process_table(void) e = table[i]; while (e) { + Word command; next = e->next; - if (e->command) + command = e->command; + if (command) { - Word expired = 0; - Word sig = 0; + Word expired; + Word sig; Word state; + tick = GetTick(); IncBusy(); - - if (e->timeout && tick > e->timeout) + expired = 0; + if (e->timeout != 0 && tick > e->timeout) expired = 1; terr = TCPIPStatusTCP(e->ipid, &e->sr); @@ -136,9 +140,15 @@ void process_table(void) if (t) terr = t; e->terr = terr; - state = e->sr.srState; + s16_debug_printf("process: %04x : %04x : expired: %d", + e->ipid, command, expired); + + s16_debug_srbuff(&e->sr); - switch(e->command) + state = e->sr.srState; + sig = 0; + + switch(command) { case kCommandRead: if (e->sr.srRcvQueued >= e->cookie @@ -154,6 +164,10 @@ void process_table(void) { sig = 1; } + if (expired) + { + sig = 1; + } break; case kCommandDisconnect: @@ -165,7 +179,14 @@ void process_table(void) case kCommandDisconnectAndLogout: // logout and remove entry. - if (state == TCPSCLOSED) + if (expired) + { + // sweet 16 link layer? + TCPIPAbortTCP(e->ipid); + state = TCPSCLOSED; + } + + if (state == TCPSCLOSED || state == TCPSTIMEWAIT) { TCPIPLogout(e->ipid); sdelete(e->semaphore); @@ -186,6 +207,7 @@ void process_table(void) if (sig) { + s16_debug_printf("sending signal to %d", e->semaphore); e->command = kCommandNone; ssignal(e->semaphore); }