Skip to content

Commit

Permalink
add verbose logging for the connection initiation.
Browse files Browse the repository at this point in the history
  • Loading branch information
ksherlock committed Aug 11, 2013
1 parent cd55a2d commit b7e9088
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 9 deletions.
7 changes: 7 additions & 0 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
* orca/merlin compatability


* gopher -I http://yahoo.com ; gopher -I http://someplace else
- the second invocation sometimes returns the results of the first.
- seems to be an issue with the DNS lookup as it is, in fact, connecting
to the wrong address.

- gopher -i http://... crashed, possibly in setfileattr (which should have even been called)


----
fixed
Expand Down
5 changes: 3 additions & 2 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@

#include <stdio.h>

#include "options.h"
#include "prototypes.h"
#include "connection.h"
#include "connection.h"

int read_binary(Word ipid, FILE *file, ReadBlock *dcb)
{
Expand Down Expand Up @@ -116,7 +117,7 @@ int ConnectLoop(char *host, Word port, Connection *connection)
{
LongWord qtick;

ConnectionInit(connection, MMStartUp());
ConnectionInit(connection, MMStartUp(), flags._v ? DisplayCallback : NULL);
ConnectionOpenC(connection, host, port);

// 30 second timeout.
Expand Down
63 changes: 61 additions & 2 deletions connection.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#pragma optimize 79
#pragma noroot

#include <IntMath.h>
#include "Memory.h"

#include "connection.h"
#include <string.h>
#include "s16debug.h"


static char pstring[256];


Expand All @@ -13,6 +17,27 @@ static Word LoginAndOpen(Connection *buffer)
Word ipid;
Word terr;

if (buffer->displayPtr)
{
static char message[] = "\pConnecting to xxx.xxx.xxx.xxx:xxxxx";

Word length;
Word tmp;

length = 15;
// first the ip addresss...
tmp = TCPIPConvertIPToCASCII(buffer->dnr.DNRIPaddress, message + length, 0);
length += tmp;

message[length++] = ':';
// now the port...
Int2Dec(buffer->port, message + length, 5, 0);
length += 5;
message[length] = 0;
message[0] = length;
buffer->displayPtr(message);
}

ipid = TCPIPLogin(
buffer->memID,
buffer->dnr.DNRIPaddress,
Expand Down Expand Up @@ -65,6 +90,12 @@ Word ConnectionPoll(Connection *buffer)
else if (buffer->dnr.DNRstatus != DNR_Pending)
{
buffer->state = kConnectionStateError;
if (buffer->displayPtr)
{
static char message[] = "\pDNR lookup failed: $xxxx";
Int2Hex(buffer->dnr.DNRstatus, message + 21, 4);
buffer->displayPtr(message);
}
return -1;
}
}
Expand Down Expand Up @@ -152,7 +183,7 @@ Word ConnectionOpen(Connection *buffer, const char *host, Word port)
buffer->terr = 0;
buffer->port = port;

if (!buffer || !*buffer) return -1;
if (!buffer || !*buffer || !host || !*host) return -1;

// 1. check if we need to do DNR.
if (TCPIPValidateIPString(host))
Expand All @@ -165,17 +196,31 @@ Word ConnectionOpen(Connection *buffer, const char *host, Word port)
return LoginAndOpen(buffer);
}
// do dnr.
if (buffer->displayPtr)
{
static char message[256] = "\pDNR lookup: ";
BlockMove(host + 1, message + 13, host[0]);
message[0] = 13 + host[0];
buffer->displayPtr(message);
}

TCPIPDNRNameToIP(host, &buffer->dnr);
if (_toolErr)
{
buffer->state = kConnectionStateError;
if (buffer->displayPtr)
{
static char message[] = "\pDNR lookup tool error: $xxxx";
Int2Hex(_toolErr, message + 25, 4);
buffer->displayPtr(message);
}
return -1;
}
buffer->state = kConnectionStateDNR;
return 0;
}

void ConnectionInit(Connection *buffer, Word memID)
void ConnectionInit(Connection *buffer, Word memID, ConnectionCallback displayPtr)
{
buffer->memID = memID;
buffer->ipid = 0;
Expand All @@ -184,6 +229,7 @@ void ConnectionInit(Connection *buffer, Word memID)
buffer->port = 0;
buffer->dnr.DNRstatus = 0;
buffer->dnr.DNRIPaddress = 0;
buffer->displayPtr = displayPtr;
}

Word ConnectionClose(Connection *buffer)
Expand All @@ -195,13 +241,26 @@ Word ConnectionClose(Connection *buffer)
{
buffer->state = kConnectionStateDisconnecting;
buffer->terr = TCPIPCloseTCP(buffer->ipid);

if (buffer->displayPtr)
{
static char message[] = "\pClosing connection: $0000";
Int2Hex(buffer->terr, message + 22, 4);
buffer->displayPtr(message);
}
return 0;
}

if (state == kConnectionStateDNR)
{
TCPIPCancelDNR(&buffer->dnr);
buffer->state = 0;

if (buffer->displayPtr)
{
static char message[] = "\pDNR lookup canceled";
buffer->displayPtr(message);
}
return 1;
}

Expand Down
4 changes: 3 additions & 1 deletion connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ enum {
kConnectionStateError
};

typedef void (*ConnectionCallback)(const char *message);
typedef struct Connection {
Word memID;
Word ipid;
Word terr;
Word state;
dnrBuffer dnr;
Word port;
ConnectionCallback displayPtr;
} Connection;



void ConnectionInit(Connection *, Word memID);
void ConnectionInit(Connection *, Word memID, ConnectionCallback displayPtr);

Word ConnectionOpen(Connection *, const char *host, Word port);
Word ConnectionOpenC(Connection *, const char *host, Word port);
Expand Down
20 changes: 16 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ void help(void)
puts("");
puts("-h show help");
puts("-V show version");
puts("-v be verbose");
puts("-o file write output to file");
puts("-O write output to file based on URL");
puts("");
Expand All @@ -196,6 +197,19 @@ void help(void)
puts("-I print only headers (HEAD)");
}

// #pragma databank [push | pop] would be nice...
#pragma databank 1
pascal void DisplayCallback(const char *message)
{
unsigned length;

// message is a p-string.
length = message ? message[0] : 0;
if (!length) return;

fprintf(stderr, "%.*s\n", length, message + 1);
}
#pragma databank 0

int main(int argc, char **argv)
{
Expand Down Expand Up @@ -225,7 +239,7 @@ int main(int argc, char **argv)
}


mf = StartUpTCP(NULL);
mf = StartUpTCP(flags._v ? DisplayCallback : NULL);

if (mf < 0)
{
Expand All @@ -236,8 +250,6 @@ int main(int argc, char **argv)





if (argc == 2)
{
const char *url;
Expand Down Expand Up @@ -272,7 +284,7 @@ int main(int argc, char **argv)
}
}

ShutDownTCP(mf, false, NULL);
ShutDownTCP(mf, false, flags._v ? DisplayCallback : NULL);
ShutDownTZ(tf);

return 0;
Expand Down
3 changes: 3 additions & 0 deletions prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
#define CLI() asm { cli }


pascal void DisplayCallback(const char *message);


typedef struct ReadBlock
{
LongWord requestCount;
Expand Down

0 comments on commit b7e9088

Please sign in to comment.