From aa868d6ff6c988eea3ed21c735c44b5256bc4f64 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Thu, 15 Sep 2016 22:25:02 -0500 Subject: [PATCH] Move TCP read routines to a separate file. Also, clean up some of the includes in various files. --- clipboard.cc | 9 +--- copyrect.cc | 9 +--- desktopsize.cc | 8 --- hextile.cc | 8 +-- keyboard.cc | 8 --- make | 6 +-- mouse.cc | 7 +-- raw.cc | 8 +-- readtcp.cc | 132 +++++++++++++++++++++++++++++++++++++++++++++++++ readtcp.h | 16 ++++++ vncdisplay.cc | 1 + vncsession.cc | 118 +------------------------------------------ vncsession.h | 12 ----- vncview.cc | 4 +- 14 files changed, 161 insertions(+), 185 deletions(-) create mode 100644 readtcp.cc create mode 100644 readtcp.h diff --git a/clipboard.cc b/clipboard.cc index b1d37eb..23c5dc0 100644 --- a/clipboard.cc +++ b/clipboard.cc @@ -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. */ diff --git a/copyrect.cc b/copyrect.cc index f2e91b2..6bbb9fc 100644 --- a/copyrect.cc +++ b/copyrect.cc @@ -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() */ diff --git a/desktopsize.cc b/desktopsize.cc index 980900b..82be65c 100644 --- a/desktopsize.cc +++ b/desktopsize.cc @@ -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 but is bogusly commented out there */ extern pascal void SetContentOrigin2(Word, Word, Word, GrafPortPtr) inline(0x570E,dispatcher); diff --git a/hextile.cc b/hextile.cc index cf67821..0db0852 100644 --- a/hextile.cc +++ b/hextile.cc @@ -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 */ diff --git a/keyboard.cc b/keyboard.cc index 6d59f85..9bc87c5 100644 --- a/keyboard.cc +++ b/keyboard.cc @@ -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 */ diff --git a/make b/make index 73793bf..143d7a2 100644 --- a/make +++ b/make @@ -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 diff --git a/mouse.cc b/mouse.cc index 4ffc8bf..0665a26 100644 --- a/mouse.cc +++ b/mouse.cc @@ -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 */ diff --git a/raw.cc b/raw.cc index a74fd55..46c096c 100644 --- a/raw.cc +++ b/raw.cc @@ -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 */ diff --git a/readtcp.cc b/readtcp.cc new file mode 100644 index 0000000..a39483f --- /dev/null +++ b/readtcp.cc @@ -0,0 +1,132 @@ +#if __ORCAC__ +#pragma lint -1 +#pragma noroot +segment "VNCview GS"; +#endif + +#include +#include +#include +#include + +#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; +} diff --git a/readtcp.h b/readtcp.h new file mode 100644 index 0000000..69abe7e --- /dev/null +++ b/readtcp.h @@ -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); diff --git a/vncdisplay.cc b/vncdisplay.cc index 82a7bd7..ccdbd70 100644 --- a/vncdisplay.cc +++ b/vncdisplay.cc @@ -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" diff --git a/vncsession.cc b/vncsession.cc index 0c0dee4..6eeca68 100644 --- a/vncsession.cc +++ b/vncsession.cc @@ -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 diff --git a/vncsession.h b/vncsession.h index 4ce3b6e..3619909 100644 --- a/vncsession.h +++ b/vncsession.h @@ -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); diff --git a/vncview.cc b/vncview.cc index 2121a82..3f87adf 100644 --- a/vncview.cc +++ b/vncview.cc @@ -29,9 +29,11 @@ segment "VNCview GS"; #include #include #include + #include "vncview.h" -#include "VNCsession.h" +#include "vncsession.h" #include "vncdisplay.h" +#include "readtcp.h" #include "menus.h" #include "colortables.h" #include "mouse.h"