mirror of
https://github.com/jeremysrand/Listener.git
synced 2024-08-31 17:29:00 +00:00
Add some code to pace sending key events when typing. Also, improve the error handling code for the network connection.
This commit is contained in:
parent
a41590bc06
commit
70d98a135a
@ -7,17 +7,17 @@
|
||||
<key>Archive.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>3</integer>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
<key>Binary.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>2</integer>
|
||||
<integer>3</integer>
|
||||
</dict>
|
||||
<key>DiskImage.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>4</integer>
|
||||
<integer>2</integer>
|
||||
</dict>
|
||||
<key>Listener.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
@ -27,7 +27,7 @@
|
||||
<key>doNotBuild.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>1</integer>
|
||||
<integer>4</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
|
107
Listener/main.c
107
Listener/main.c
@ -141,44 +141,41 @@ static char * stateMessages[NUM_LISTEN_STATES] = {
|
||||
|
||||
// Implementation
|
||||
|
||||
void NDAClose(void)
|
||||
void delayToNextTick()
|
||||
{
|
||||
if ((globals != NULL) &&
|
||||
(globals->ndaActive)) {
|
||||
CloseWindow(globals->winPtr);
|
||||
globals->winPtr = NULL;
|
||||
globals->ndaActive = FALSE;
|
||||
}
|
||||
|
||||
ResourceShutDown();
|
||||
LongWord oldTickCounter = GetTick();
|
||||
while (oldTickCounter == GetTick())
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
void freeGlobals(void)
|
||||
void closeConnection(void)
|
||||
{
|
||||
tTextList * textList = globals->textListHead;
|
||||
static srBuff srBuffer;
|
||||
int counter;
|
||||
|
||||
if (globals->textTransfer != NULL)
|
||||
free(globals->textTransfer);
|
||||
|
||||
while (textList != NULL) {
|
||||
tTextList * prev = textList;
|
||||
textList = textList->header.next;
|
||||
free(prev);
|
||||
}
|
||||
|
||||
free(globals);
|
||||
globals = NULL;
|
||||
}
|
||||
|
||||
|
||||
void teardownNetwork(void)
|
||||
{
|
||||
if (globals->hasConnIpid) {
|
||||
TCPIPAbortTCP(globals->connIpid);
|
||||
TCPIPCloseTCP(globals->connIpid);
|
||||
for (counter = 0; counter < 20; counter++)
|
||||
{
|
||||
TCPIPPoll();
|
||||
delayToNextTick();
|
||||
TCPIPStatusTCP(globals->connIpid, &srBuffer);
|
||||
if ((srBuffer.srState == TCPSCLOSED) ||
|
||||
(srBuffer.srState == TCPSTIMEWAIT))
|
||||
break;
|
||||
}
|
||||
if ((srBuffer.srState != TCPSCLOSED) &
|
||||
(srBuffer.srState != TCPSTIMEWAIT))
|
||||
TCPIPAbortTCP(globals->connIpid);
|
||||
TCPIPLogout(globals->connIpid);
|
||||
}
|
||||
globals->hasConnIpid = FALSE;
|
||||
}
|
||||
|
||||
void teardownNetwork(void)
|
||||
{
|
||||
closeConnection();
|
||||
|
||||
if (globals->hasListenIpid) {
|
||||
TCPIPCloseTCP(globals->listenIpid);
|
||||
@ -196,6 +193,45 @@ void teardownNetwork(void)
|
||||
}
|
||||
|
||||
|
||||
void freeText(void)
|
||||
{
|
||||
tTextList * textList = globals->textListHead;
|
||||
|
||||
if (globals->textTransfer != NULL)
|
||||
free(globals->textTransfer);
|
||||
|
||||
while (textList != NULL) {
|
||||
tTextList * prev = textList;
|
||||
textList = textList->header.next;
|
||||
free(prev);
|
||||
}
|
||||
}
|
||||
|
||||
void NDAClose(void)
|
||||
{
|
||||
if ((globals != NULL) &&
|
||||
(globals->ndaActive)) {
|
||||
CloseWindow(globals->winPtr);
|
||||
globals->winPtr = NULL;
|
||||
globals->ndaActive = FALSE;
|
||||
}
|
||||
|
||||
teardownNetwork();
|
||||
ResourceShutDown();
|
||||
freeText();
|
||||
memset(globals, 0, sizeof(*globals));
|
||||
}
|
||||
|
||||
|
||||
void freeGlobals(void)
|
||||
{
|
||||
freeText();
|
||||
|
||||
free(globals);
|
||||
globals = NULL;
|
||||
}
|
||||
|
||||
|
||||
void NDAInit(int code)
|
||||
{
|
||||
/* When code is 1, this is tool startup, otherwise tool
|
||||
@ -444,9 +480,7 @@ void handleAwaitingMsgHeaderState(void)
|
||||
return;
|
||||
}
|
||||
if (srBuffer.srState != TCPSESTABLISHED) {
|
||||
TCPIPAbortTCP(globals->connIpid);
|
||||
TCPIPLogout(globals->connIpid);
|
||||
globals->hasConnIpid = FALSE;
|
||||
closeConnection();
|
||||
newState(LISTEN_STATE_AWAITING_CONNECTION);
|
||||
return;
|
||||
}
|
||||
@ -507,9 +541,7 @@ void handleAwaitingTextState(void)
|
||||
return;
|
||||
}
|
||||
if (srBuffer.srState != TCPSESTABLISHED) {
|
||||
TCPIPAbortTCP(globals->connIpid);
|
||||
TCPIPLogout(globals->connIpid);
|
||||
globals->hasConnIpid = FALSE;
|
||||
closeConnection();
|
||||
newState(LISTEN_STATE_AWAITING_CONNECTION);
|
||||
return;
|
||||
}
|
||||
@ -556,8 +588,13 @@ void runStateMachine(void)
|
||||
|
||||
void sendKey(void)
|
||||
{
|
||||
tTextList * textList = globals->textListHead;
|
||||
EventRecord eventRecord;
|
||||
|
||||
// If there is still a key down waiting to be processed, then don't send another one.
|
||||
if (EventAvail(keyDownMask, &eventRecord))
|
||||
return;
|
||||
|
||||
tTextList * textList = globals->textListHead;
|
||||
PostEvent(keyDownEvt, 0x00C00000 | textList->text[textList->header.position]);
|
||||
textList->header.position++;
|
||||
if (textList->header.position < textList->header.size)
|
||||
|
Loading…
Reference in New Issue
Block a user