Move TCP read routines to a separate file.

Also, clean up some of the includes in various files.
This commit is contained in:
Stephen Heumann 2016-09-15 22:25:02 -05:00
parent ceeaeb7767
commit aa868d6ff6
14 changed files with 161 additions and 185 deletions

View File

@ -24,15 +24,8 @@ segment "VNCview GS";
#include "vncsession.h"
#include "vncview.h"
#include "vncdisplay.h"
#include "colortables.h"
#include "menus.h"
#include "readtcp.h"
#include "clipboard.h"
#include "desktopsize.h"
#include "mouse.h"
#include "keyboard.h"
#include "copyrect.h"
#include "raw.h"
#include "hextile.h"
/* Update the Scrap Manager clipboard with new data sent from server.
*/

View File

@ -23,15 +23,8 @@ segment "VNCview GS";
#include "vncsession.h"
#include "vncview.h"
#include "vncdisplay.h"
#include "colortables.h"
#include "menus.h"
#include "clipboard.h"
#include "desktopsize.h"
#include "mouse.h"
#include "keyboard.h"
#include "readtcp.h"
#include "copyrect.h"
#include "raw.h"
#include "hextile.h"
void DoCopyRect (void) {
/* For use with GetContentOrigin() */

View File

@ -23,15 +23,7 @@ segment "VNCview GS";
#include "vncsession.h"
#include "vncview.h"
#include "vncdisplay.h"
#include "colortables.h"
#include "menus.h"
#include "clipboard.h"
#include "desktopsize.h"
#include "mouse.h"
#include "keyboard.h"
#include "copyrect.h"
#include "raw.h"
#include "hextile.h"
/* This prototype should be in <window.h> but is bogusly commented out there */
extern pascal void SetContentOrigin2(Word, Word, Word, GrafPortPtr) inline(0x570E,dispatcher);

View File

@ -24,13 +24,7 @@ segment "VNCview GS";
#include "vncview.h"
#include "vncdisplay.h"
#include "colortables.h"
#include "menus.h"
#include "clipboard.h"
#include "desktopsize.h"
#include "mouse.h"
#include "keyboard.h"
#include "copyrect.h"
#include "raw.h"
#include "readtcp.h"
#include "hextile.h"
static unsigned int hexXTiles, hexYTiles; /* For in-process hextile processing */

View File

@ -23,15 +23,7 @@ segment "VNCview GS";
#include "vncsession.h"
#include "vncview.h"
#include "vncdisplay.h"
#include "colortables.h"
#include "menus.h"
#include "clipboard.h"
#include "desktopsize.h"
#include "mouse.h"
#include "keyboard.h"
#include "copyrect.h"
#include "raw.h"
#include "hextile.h"
/* Send a KeyEvent message to the server
*/

6
make
View File

@ -5,7 +5,7 @@ set rezfork false
clearmem
for {header} in vncview vncsession vncdisplay colortables menus \
for {header} in vncview vncsession vncdisplay colortables readtcp menus \
desktopsize mouse keyboard copyrect raw hextile clipboard
unset exit
newer VNCview.GS {header}.h
@ -15,7 +15,7 @@ for {header} in vncview vncsession vncdisplay colortables menus \
end
end
for file in vncview vncsession vncdisplay colortables \
for file in vncview vncsession vncdisplay colortables readtcp \
desktopsize mouse keyboard copyrect raw hextile clipboard
unset exit
newer {file}.a {file}.cc
@ -45,7 +45,7 @@ if {status} != 0
end
if {link} == true
link vncview vncsession vncdisplay colortables tables rawdec \
link vncview vncsession vncdisplay colortables readtcp tables rawdec \
desktopsize mouse keyboard copyrect raw hextile clipboard \
keep=VNCview.GS
filetype VNCview.GS S16 $DB03

View File

@ -23,15 +23,10 @@ segment "VNCview GS";
#include "vncsession.h"
#include "vncview.h"
#include "vncdisplay.h"
#include "readtcp.h"
#include "colortables.h"
#include "menus.h"
#include "clipboard.h"
#include "desktopsize.h"
#include "mouse.h"
#include "keyboard.h"
#include "copyrect.h"
#include "raw.h"
#include "hextile.h"
unsigned char * cursor = NULL; /* Cursor from server */

8
raw.cc
View File

@ -24,14 +24,8 @@ segment "VNCview GS";
#include "vncview.h"
#include "vncdisplay.h"
#include "colortables.h"
#include "menus.h"
#include "clipboard.h"
#include "desktopsize.h"
#include "mouse.h"
#include "keyboard.h"
#include "copyrect.h"
#include "readtcp.h"
#include "raw.h"
#include "hextile.h"
/* Data on state of raw rectangle drawing routines */
static unsigned int lineBytes; /* Number of bytes in a line of GS pixels */

132
readtcp.cc Normal file
View File

@ -0,0 +1,132 @@
#if __ORCAC__
#pragma lint -1
#pragma noroot
segment "VNCview GS";
#endif
#include <tcpip.h>
#include <memory.h>
#include <event.h>
#include <orca.h>
#include "readtcp.h"
#include "vncsession.h"
#define buffTypePointer 0x0000 /* For TCPIPReadTCP() */
#define buffTypeHandle 0x0001
#define buffTypeNewHandle 0x0002
unsigned char *readBufferPtr; /* Ptr to data read by last DoReadTCP call. */
void ** readBufferHndl; /* User internally by TCP read routines. */
static unsigned int tcperr;
/* Read data, waiting for up to 15 seconds for the data to be ready */
BOOLEAN DoWaitingReadTCP(unsigned long dataLength) {
unsigned long stopTime;
BOOLEAN result = FALSE;
stopTime = TickCount() + 15 * 60;
do {
result = DoReadTCP(dataLength);
} while (result == FALSE && tcperr == tcperrOK && TickCount() < stopTime);
return result;
}
/* Fix things when TCPIPReadTCP returns less data than it's supposed to */
static BOOLEAN ReadFixup (unsigned long requested, unsigned long returned) {
static rrBuff theRRBuff;
SetHandleSize(requested, readBufferHndl);
if (toolerror())
return FALSE;
HLock(readBufferHndl);
do {
TCPIPPoll();
if ((tcperr = TCPIPReadTCP(hostIpid, buffTypeNewHandle, NULL,
requested-returned, &theRRBuff)) != tcperrOK)
return FALSE;
if (toolerror())
return FALSE;
if (theRRBuff.rrBuffCount == 0) /* To avoid infinite loops */
return FALSE;
HandToPtr(theRRBuff.rrBuffHandle, (char *)*readBufferHndl + returned,
theRRBuff.rrBuffCount);
returned += theRRBuff.rrBuffCount;
DisposeHandle(theRRBuff.rrBuffHandle);
} while (returned < requested);
readBufferPtr = *readBufferHndl;
return TRUE;
}
/**********************************************************************
* DoReadTCP() - Issue TCPIPReadTCP() call w/ appropriate parameters
* Return value = did the read succeed?
**********************************************************************/
BOOLEAN DoReadTCP (unsigned long dataLength) {
static srBuff theSRBuff;
static rrBuff theRRBuff;
if (dataLength == 0)
return TRUE;
DoneWithReadBuffer();
TCPIPPoll();
if ((tcperr = TCPIPStatusTCP(hostIpid, &theSRBuff)) != tcperrOK)
return FALSE;
if (toolerror())
return FALSE;
if (theSRBuff.srRcvQueued < dataLength)
return FALSE;
if ((tcperr = TCPIPReadTCP(hostIpid, buffTypeNewHandle, NULL,
dataLength, &theRRBuff)) != tcperrOK)
return FALSE;
if (toolerror())
return FALSE;
if (theRRBuff.rrBuffCount == 0)
return FALSE;
readBufferHndl = theRRBuff.rrBuffHandle;
if (theRRBuff.rrBuffCount != dataLength)
return ReadFixup(dataLength, theRRBuff.rrBuffCount);
HLock(readBufferHndl);
readBufferPtr = *readBufferHndl;
return TRUE;
}
/**********************************************************************
* DoReadMultipleTCP() - Read the largest available multiple of recLen bytes,
* up to a maximum multiple of maxN.
* Return value = the multiple n (meaning n * len bytes have been read)
**********************************************************************/
unsigned DoReadMultipleTCP(unsigned recLen, unsigned maxN) {
static srBuff theSRBuff;
unsigned long n, totalSize;
TCPIPPoll();
if ((tcperr = TCPIPStatusTCP(hostIpid, &theSRBuff)) != tcperrOK)
return 0;
if (toolerror())
return 0;
n = theSRBuff.srRcvQueued / recLen;
if (n > maxN)
n = maxN;
if (n && DoReadTCP(recLen * n))
return n;
return 0;
}

16
readtcp.h Normal file
View File

@ -0,0 +1,16 @@
/* Ptr to data read by last DoReadTCP call. */
extern unsigned char *readBufferPtr;
/* Used internally by TCP read routines.
* Shouldn't be accessed directly otherwise. */
extern void ** readBufferHndl;
#define DoneWithReadBuffer() do \
if (readBufferHndl) { \
DisposeHandle(readBufferHndl); \
readBufferHndl = NULL; \
} while (0) \
extern BOOLEAN DoReadTCP (unsigned long);
extern BOOLEAN DoWaitingReadTCP(unsigned long);
extern unsigned DoReadMultipleTCP(unsigned recLen, unsigned maxN);

View File

@ -25,6 +25,7 @@ segment "VNCview GS";
#include "vncview.h"
#include "vncdisplay.h"
#include "colortables.h"
#include "readtcp.h"
#include "menus.h"
#include "clipboard.h"
#include "desktopsize.h"

View File

@ -38,6 +38,7 @@ segment "VNCview GS";
#include "vncdisplay.h"
#include "menus.h"
#include "colortables.h"
#include "readtcp.h"
#define linServer 3
#define linPassword 7
@ -54,8 +55,6 @@ segment "VNCview GS";
GrafPortPtr connectStatusWindowPtr = NULL;
unsigned int hostIpid;
void ** readBufferHndl; /* User internally by TCP read routines. */
unsigned char *readBufferPtr; /* Ptr to data read by last DoReadTCP call. */
static BOOLEAN alerted = FALSE;
static void CloseConnectStatusWindow (void);
@ -67,10 +66,6 @@ static BOOLEAN FinishVNCHandshaking (void);
static void TuneMarinetti (void);
static void UnTuneMarinetti (void);
#define buffTypePointer 0x0000 /* For TCPIPReadTCP() */
#define buffTypeHandle 0x0001
#define buffTypeNewHandle 0x0002
#define vncConnectionFailed SwapBytes4(0)
#define vncNoAuthentication SwapBytes4(1)
#define vncVNCAuthentication SwapBytes4(2)
@ -295,117 +290,6 @@ static BOOLEAN GetIpid (void)
#undef baseDisplayNum
}
static unsigned int tcperr;
/* Read data, waiting for up to 15 seconds for the data to be ready */
BOOLEAN DoWaitingReadTCP(unsigned long dataLength) {
unsigned long stopTime;
BOOLEAN result = FALSE;
stopTime = TickCount() + 15 * 60;
do {
result = DoReadTCP(dataLength);
} while (result == FALSE && tcperr == tcperrOK && TickCount() < stopTime);
return result;
}
/* Fix things when TCPIPReadTCP returns less data than it's supposed to */
static BOOLEAN ReadFixup (unsigned long requested, unsigned long returned) {
static rrBuff theRRBuff;
SetHandleSize(requested, readBufferHndl);
if (toolerror())
return FALSE;
HLock(readBufferHndl);
do {
TCPIPPoll();
if ((tcperr = TCPIPReadTCP(hostIpid, buffTypeNewHandle, NULL,
requested-returned, &theRRBuff)) != tcperrOK)
return FALSE;
if (toolerror())
return FALSE;
if (theRRBuff.rrBuffCount == 0) /* To avoid infinite loops */
return FALSE;
HandToPtr(theRRBuff.rrBuffHandle, (char *)*readBufferHndl + returned,
theRRBuff.rrBuffCount);
returned += theRRBuff.rrBuffCount;
DisposeHandle(theRRBuff.rrBuffHandle);
} while (returned < requested);
readBufferPtr = *readBufferHndl;
return TRUE;
}
/**********************************************************************
* DoReadTCP() - Issue TCPIPReadTCP() call w/ appropriate parameters
* Return value = did the read succeed?
**********************************************************************/
BOOLEAN DoReadTCP (unsigned long dataLength) {
static srBuff theSRBuff;
static rrBuff theRRBuff;
if (dataLength == 0)
return TRUE;
DoneWithReadBuffer();
TCPIPPoll();
if ((tcperr = TCPIPStatusTCP(hostIpid, &theSRBuff)) != tcperrOK)
return FALSE;
if (toolerror())
return FALSE;
if (theSRBuff.srRcvQueued < dataLength)
return FALSE;
if ((tcperr = TCPIPReadTCP(hostIpid, buffTypeNewHandle, NULL,
dataLength, &theRRBuff)) != tcperrOK)
return FALSE;
if (toolerror())
return FALSE;
if (theRRBuff.rrBuffCount == 0)
return FALSE;
readBufferHndl = theRRBuff.rrBuffHandle;
if (theRRBuff.rrBuffCount != dataLength)
return ReadFixup(dataLength, theRRBuff.rrBuffCount);
HLock(readBufferHndl);
readBufferPtr = *readBufferHndl;
return TRUE;
}
/**********************************************************************
* DoReadMultipleTCP() - Read the largest available multiple of recLen bytes,
* up to a maximum multiple of maxN.
* Return value = the multiple n (meaning n * len bytes have been read)
**********************************************************************/
unsigned DoReadMultipleTCP(unsigned recLen, unsigned maxN) {
static srBuff theSRBuff;
unsigned long n, totalSize;
TCPIPPoll();
if ((tcperr = TCPIPStatusTCP(hostIpid, &theSRBuff)) != tcperrOK)
return 0;
if (toolerror())
return 0;
n = theSRBuff.srRcvQueued / recLen;
if (n > maxN)
n = maxN;
if (n && DoReadTCP(recLen * n))
return n;
return 0;
}
/**********************************************************************
* DoVNCHandshaking() - Establish connection to VNC server

View File

@ -16,22 +16,10 @@
extern GrafPortPtr connectStatusWindowPtr;
extern void ** readBufferHndl; /* User internally by TCP read routines. */
extern unsigned char *readBufferPtr; /* Ptr to data read by last DoReadTCP call. */
extern unsigned int hostIpid;
extern void DisplayConnectStatus(char *, BOOLEAN);
extern void DoConnect (void);
#define DoneWithReadBuffer() do \
if (readBufferHndl) { \
DisposeHandle(readBufferHndl); \
readBufferHndl = NULL; \
} while (0) \
extern BOOLEAN DoReadTCP (unsigned long);
extern BOOLEAN DoWaitingReadTCP(unsigned long);
extern unsigned DoReadMultipleTCP(unsigned recLen, unsigned maxN);
extern void CloseTCPConnection (void);

View File

@ -29,9 +29,11 @@ segment "VNCview GS";
#include <LineEdit.h>
#include <TCPIP.h>
#include <Scrap.h>
#include "vncview.h"
#include "VNCsession.h"
#include "vncsession.h"
#include "vncdisplay.h"
#include "readtcp.h"
#include "menus.h"
#include "colortables.h"
#include "mouse.h"