Skip to content

Commit

Permalink
kCommandWrite, move logout to separate list.
Browse files Browse the repository at this point in the history
  • Loading branch information
ksherlock committed May 6, 2012
1 parent 69a5fb0 commit 0353485
Showing 1 changed file with 90 additions and 30 deletions.
120 changes: 90 additions & 30 deletions table.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,22 @@
#define TABLE_MASK 15
static struct Entry *table[TABLE_SIZE];

// ipids waiting to close + logout.
static struct Entry *dlist;

static void destroy_entry(Entry *e, Boolean abort);

void init_table(void)
{
dlist = NULL;
memset(table, 0, sizeof(table));
}

void destroy_table(void)
{

Entry *e;
Entry *next;
unsigned i;

for (i = 0; i < TABLE_SIZE; ++i)
Expand All @@ -32,26 +39,34 @@ void destroy_table(void)

while (e)
{
Entry *next;

IncBusy();

next = e->next;

TCPIPAbortTCP(e->ipid);
TCPIPLogout(e->ipid);

sdelete(e->semaphore);
free(e);

destroy_entry(e, true);
e = next;

DecBusy();
}

}

e = dlist;
while (e)
{
next = e->next;
destroy_entry(e, true);
e = next;
}
}

static void destroy_entry(Entry *e, Boolean abort)
{
if (abort) TCPIPAbortTCP(e->ipid);

TCPIPLogout(e->ipid);
sdelete(e->semaphore);
free(e);
}

Entry *find_entry(Word ipid)
{
Entry *e;
Expand Down Expand Up @@ -151,6 +166,7 @@ void process_table(void)
switch(command)
{
case kCommandRead:
// block until data available.
if (e->sr.srRcvQueued >= e->cookie
|| expired
|| terr)
Expand All @@ -159,7 +175,20 @@ void process_table(void)
}
break;


case kCommandWrite:
// block until data sent.
if (e->sr.srSndQueued <= e->cookie
|| expired
|| terr)
{
sig = 1;
}
break;


case kCommandConnect:
// block until connection established.
if (state >= TCPSESTABLISHED || state == TCPSCLOSED)
{
sig = 1;
Expand All @@ -171,36 +200,32 @@ void process_table(void)
break;

case kCommandDisconnect:
// block until connection closed.
if (state == TCPSCLOSED)
{
sig = 1;
}
break;

case kCommandDisconnectAndLogout:
// logout and remove entry.
if (expired)

// move to other list
// since it's no longer a valid fd

if (prev)
{
// sweet 16 link layer?
TCPIPAbortTCP(e->ipid);
state = TCPSCLOSED;
prev->next = next;
}

if (state == TCPSCLOSED || state == TCPSTIMEWAIT)
else
{
TCPIPLogout(e->ipid);
sdelete(e->semaphore);
free(e);
e = NULL;
if (prev)
{
prev->next = next;
}
else
{
table[i] = next;
}
table[i] = next;
}

// add to the dlist.
e->next = dlist;
dlist = e;
e = NULL;

break;

}
Expand All @@ -214,11 +239,46 @@ void process_table(void)

DecBusy();
} // e->command


if (e) prev = e;
e = next;
}


}


// now process the disconnect list.
e = dlist;
prev = NULL;
while (e)
{
next = e->next;

IncBusy();
terr = TCPIPStatusTCP(e->ipid, &e->sr);
t = _toolErr;
if (t) terr = t;
DecBusy();

if (e->sr.srState == TCPSCLOSED)
{
destroy_entry(e, false);

e = NULL;
// remove..
if (prev)
{
prev->next = next;
}
else
{
dlist = next;
}
}

if (e) prev = e;
e = next;
}

}

0 comments on commit 0353485

Please sign in to comment.