diff --git a/common.c b/common.c index c93440e..03d9b31 100644 --- a/common.c +++ b/common.c @@ -26,13 +26,17 @@ int read_binary(Word ipid, FILE *file) rrBuff rb; Word count; + IncBusy(); rv = TCPIPReadTCP(ipid, 0, (Ref)buffer, 512, &rb); - + DecBusy(); + count = rb.rrBuffCount; if (!count) { if (rv) break; + IncBusy(); TCPIPPoll(); + DecBusy(); continue; } @@ -59,9 +63,11 @@ int ConnectLoop(char *host, Word port, Connection *connection) { fprintf(stderr, "Connection timed out.\n"); + IncBusy(); TCPIPAbortTCP(connection->ipid); TCPIPLogout(connection->ipid); - + DecBusy(); + return 0; } } diff --git a/gopher.c b/gopher.c index ab0af1c..7e648b1 100644 --- a/gopher.c +++ b/gopher.c @@ -45,8 +45,10 @@ static int gopher_text(Word ipid, FILE *file) int rv = 0; Word lastTerm = 0; + IncBusy(); TCPIPPoll(); - + DecBusy(); + for(;;) { Word count; @@ -62,7 +64,10 @@ static int gopher_text(Word ipid, FILE *file) if (rv < 0) break; // eof if (rv == 0) // no data available (yet) { + IncBusy(); TCPIPPoll(); + DecBusy(); + continue; } @@ -146,11 +151,17 @@ static int gopher_dir(Word ipid, FILE *file) if (rv < 0) break; if (rv == 0) { + IncBusy(); TCPIPPoll(); + DecBusy(); continue; } - if (!rb.moreFlag) TCPIPPoll(); - + if (!rb.moreFlag) + { + IncBusy(); + TCPIPPoll(); + DecBusy(); + } if (!count) { @@ -351,6 +362,8 @@ int do_gopher(const char *url, URLComponents *components) // path is /[type][resource] // where [type] is 1 char and the leading / is ignored. + + IncBusy(); if (path) { @@ -370,6 +383,7 @@ int do_gopher(const char *url, URLComponents *components) } // TCPIPWriteTCP(connection.ipid, "\r\n", 2, true, false); + DecBusy(); diff --git a/http.c b/http.c index 43c4539..1c534ab 100644 --- a/http.c +++ b/http.c @@ -49,9 +49,9 @@ static int do_http_0_9( char *cp; int length; - + IncBusy(); TCPIPWriteTCP(ipid, "GET ", 4, false, false); - + length = components->pathAndQuery.length; cp = url + components->pathAndQuery.location; @@ -61,9 +61,11 @@ static int do_http_0_9( cp = "/"; } + TCPIPWriteTCP(ipid, cp, length, false, false); TCPIPWriteTCP(ipid, "\r\n", 2, true, false); + DecBusy(); ok = read_binary(ipid, file); return 0; @@ -90,7 +92,9 @@ static int parseHeaders(Word ipid, FILE *file, Handle dict) line = 0; + IncBusy(); TCPIPPoll(); + DecBusy(); for (;;) { @@ -103,7 +107,9 @@ static int parseHeaders(Word ipid, FILE *file, Handle dict) if (ok == 0) { + IncBusy(); TCPIPPoll(); + DecBusy(); continue; } @@ -288,9 +294,10 @@ int read_response(Word ipid, FILE *file, Handle dict) { LongWord count = 256; - + IncBusy(); TCPIPPoll(); TCPIPStatusTCP(ipid, &sr); + DecBusy(); count = sr.srRcvQueued; if (count > contentSize) count = contentSize; @@ -300,7 +307,9 @@ int read_response(Word ipid, FILE *file, Handle dict) continue; } + IncBusy(); terr = TCPIPReadTCP(ipid, 2, (Ref)0, count, &rr); + DecBusy(); if (_toolErr) break; @@ -375,6 +384,7 @@ static int do_http_1_1( // send the request. // GET path HTTP/version\r\n + IncBusy(); if (flags._I) TCPIPWriteTCP(ipid, "HEAD ", 5, false, false); @@ -416,6 +426,7 @@ static int do_http_1_1( // end headers and push. TCPIPWriteTCP(ipid, "\r\n", 2, true, false); + DecBusy(); DisposeHandle(dict); dict = NULL; diff --git a/prototypes.h b/prototypes.h index bba0506..aefa764 100644 --- a/prototypes.h +++ b/prototypes.h @@ -3,6 +3,17 @@ #include + +#define IncBusy() asm { jsl 0xE10064 } +#define DecBusy() asm { jsl 0xE10068 } +#define Resched() asm { cop 0x7f } + +#define BusyFlag ((byte *)0xE100FFl) + +#define SEI() asm { sei } +#define CLI() asm { cli } + + int read_binary(unsigned ipid, FILE *file); int setfiletype(const char *filename);