mirror of
https://github.com/jeremysrand/Listener.git
synced 2024-06-10 00:29:56 +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>
|
<key>Archive.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>3</integer>
|
<integer>1</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>Binary.xcscheme_^#shared#^_</key>
|
<key>Binary.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>2</integer>
|
<integer>3</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>DiskImage.xcscheme_^#shared#^_</key>
|
<key>DiskImage.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>4</integer>
|
<integer>2</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>Listener.xcscheme_^#shared#^_</key>
|
<key>Listener.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
<key>doNotBuild.xcscheme_^#shared#^_</key>
|
<key>doNotBuild.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>1</integer>
|
<integer>4</integer>
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
|
|
107
Listener/main.c
107
Listener/main.c
|
@ -141,44 +141,41 @@ static char * stateMessages[NUM_LISTEN_STATES] = {
|
||||||
|
|
||||||
// Implementation
|
// Implementation
|
||||||
|
|
||||||
void NDAClose(void)
|
void delayToNextTick()
|
||||||
{
|
{
|
||||||
if ((globals != NULL) &&
|
LongWord oldTickCounter = GetTick();
|
||||||
(globals->ndaActive)) {
|
while (oldTickCounter == GetTick())
|
||||||
CloseWindow(globals->winPtr);
|
;
|
||||||
globals->winPtr = NULL;
|
|
||||||
globals->ndaActive = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ResourceShutDown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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) {
|
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);
|
TCPIPLogout(globals->connIpid);
|
||||||
}
|
}
|
||||||
globals->hasConnIpid = FALSE;
|
globals->hasConnIpid = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void teardownNetwork(void)
|
||||||
|
{
|
||||||
|
closeConnection();
|
||||||
|
|
||||||
if (globals->hasListenIpid) {
|
if (globals->hasListenIpid) {
|
||||||
TCPIPCloseTCP(globals->listenIpid);
|
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)
|
void NDAInit(int code)
|
||||||
{
|
{
|
||||||
/* When code is 1, this is tool startup, otherwise tool
|
/* When code is 1, this is tool startup, otherwise tool
|
||||||
|
@ -444,9 +480,7 @@ void handleAwaitingMsgHeaderState(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (srBuffer.srState != TCPSESTABLISHED) {
|
if (srBuffer.srState != TCPSESTABLISHED) {
|
||||||
TCPIPAbortTCP(globals->connIpid);
|
closeConnection();
|
||||||
TCPIPLogout(globals->connIpid);
|
|
||||||
globals->hasConnIpid = FALSE;
|
|
||||||
newState(LISTEN_STATE_AWAITING_CONNECTION);
|
newState(LISTEN_STATE_AWAITING_CONNECTION);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -507,9 +541,7 @@ void handleAwaitingTextState(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (srBuffer.srState != TCPSESTABLISHED) {
|
if (srBuffer.srState != TCPSESTABLISHED) {
|
||||||
TCPIPAbortTCP(globals->connIpid);
|
closeConnection();
|
||||||
TCPIPLogout(globals->connIpid);
|
|
||||||
globals->hasConnIpid = FALSE;
|
|
||||||
newState(LISTEN_STATE_AWAITING_CONNECTION);
|
newState(LISTEN_STATE_AWAITING_CONNECTION);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -556,8 +588,13 @@ void runStateMachine(void)
|
||||||
|
|
||||||
void sendKey(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]);
|
PostEvent(keyDownEvt, 0x00C00000 | textList->text[textList->header.position]);
|
||||||
textList->header.position++;
|
textList->header.position++;
|
||||||
if (textList->header.position < textList->header.size)
|
if (textList->header.position < textList->header.size)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user