home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-07-04 | 23.7 KB | 1,002 lines | [TEXT/MPCC] |
- /*
- ** CTCPEndpoint.cp
- **
- ** TurboTCP support library
- ** TCP generic protocol interpreter
- **
- ** Copyright © 1993-94, FrostByte Design / Eric Scouten
- **
- */
-
-
- #include "CTCPEndpoint.h"
-
- #include "CDecorator.h"
- #include "CError.h"
- #include "Constants.h"
- #include "Global.h"
- #include "TBUtilities.h"
- #include "TCLUtilities.h"
-
- #include "CTCPDriver.h"
- #include "CTCPResolverCall.h"
- #include "CTCPStream.h"
- #include "UTurboTCP.h"
-
-
- #define sessionOpen (cState >= strSYNReceived) && (cState <= strTimeWait)
- #define sessionOpening (cState >= strListen) && (cState <= strSYNSent)
- #define sessionClosing (cState >= strFINWait1) && (cState <= strTimeWait)
-
-
- #define ALRT_TCPOpenFailed 23000
- #define ALRT_TCPUnexpError 23001
- #define ALRT_TCPSendFailed 23002
- #define ALRT_TCPTerminated 23003
- #define ESTR_TerminBase 23010
-
- #define STR__WindowStrings 23000
- #define Wstr_NoSession 1
- #define Wstr_Separator 2
- #define Wstr_NotReadyPrefix 3
- #define Wstr_NotReadySuffix 4
- #define Wstr_Untitled 5
- #define Wstr_PortDelimiter 6
-
- extern CDecorator* gDecorator;
- extern CError* gError;
-
- TCL_DEFINE_CLASS_M0(CTCPEndpoint);
-
-
- // —— constructor/destructor ——
-
- /*______________________________________________________________________
- **
- ** constructor
- **
- ** Initialize the protocol interpreter.
- **
- ** theDefaultPort (unsigned short): default IP port number (the only required parameter)
- ** recBufferSize (unsigned long): size of receive buffer to create
- ** autoReceiveSize (unsigned short): number of entries in RDS for auto-receive,
- ** 0 to disable autoreceiving
- ** autoReceiveNum (unsigned short): number of auto-receive calls to issue at once
- ** must be at least 1
- ** doUseCName (Boolean): TRUE to get canonical name of remote host
- ** whenever possible
- **
- */
-
- CTCPEndpoint::CTCPEndpoint(unsigned short theDefaultPort, unsigned long recBufferSize,
- unsigned short autoReceiveSize, unsigned short autoReceiveNum,
- Boolean doUseCName)
-
- {
-
- // blank out the usual variables
-
- itsStream = NULL;
- itsResolver = NULL;
- pendingOpenByName = closeAndQuit = FALSE;
- actualPort = defaultPort = theDefaultPort;
- hostCName[0] = '\0';
- useCName = doUseCName;
- goAwayOnClose = FALSE;
- showFileName = TRUE;
- showHostName = TRUE;
- untitledNumber = 0;
- localPort = 0;
-
-
- // create a TCP stream
-
- TRY {
- itsStream = new CTCPStream(*this, recBufferSize, autoReceiveSize, autoReceiveNum);
- itsResolver = new CTCPResolverCall(*this);
- }
-
- CATCH {
- if (itsStream)
- itsStream->Dispose();
- itsStream = NULL;
- if (itsResolver)
- itsResolver->Dispose();
- itsResolver = NULL;
- }
-
- ENDTRY;
-
- }
-
- /*______________________________________________________________________
- **
- ** destructor
- **
- ** Get rid of the stream and resolver objects.
- **
- */
-
- CTCPEndpoint::~CTCPEndpoint()
-
- {
- if (itsStream)
- itsStream->Dispose();
- if (itsResolver)
- itsResolver->Dispose();
- }
-
-
- // —— opening/closing session ——
-
- /*______________________________________________________________________
- **
- ** OpenUserHost
- **
- ** Open a connection to the host named by the string. Hostname may be either dotted decimal
- ** notation or a DNS name. A port number may be specified at the end of the hostname
- ** (separated by a single space) if the caller permits it.
- **
- ** theHostName (char*): the hostname (and optional port#) string
- ** theDefaultPort (unsigned short): the default port number
- ** allowPortChange (Boolean): TRUE to allow port number overrides
- **
- */
-
- void CTCPEndpoint::OpenUserHost(char* theHostName, unsigned short theDefaultPort,
- Boolean allowPortChange)
-
- {
- Str255 portNumStr;
- long newPortNum = 0;
- register char* s;
- register char* d;
- register short i;
-
-
- // ensure that there is a host to open
-
- if (*theHostName == '\0') {
- HandleOpenFailed(nameSyntaxErr);
- return;
- }
-
-
- // parse for port number
-
- pendingPortNumber = theDefaultPort;
- if (allowPortChange) {
- s = theHostName;
- d = (char*) &hostCName;
- while ((*s != ' ') & (*s != '\0'))
- *d++ = *s++;
- *d = '\0';
- if (*s == ' ') {
- d = (char*) &portNumStr;
- i = -1;
- while (*s != '\0')
- *d++ = *s++, i++;
- portNumStr[0] = (char) i;
- if (i > 0)
- StringToNum(portNumStr, &newPortNum);
- }
- }
- else
- BlockMove(theHostName, &hostCName, 255);
-
- if (newPortNum != 0)
- pendingPortNumber = newPortNum;
-
-
- // issue resolver command
-
- pendingOpenByName = TRUE;
- actualPort = pendingPortNumber;
- itsResolver->DoStrToAddr((char*) &hostCName);
-
- }
-
-
- /*______________________________________________________________________
- **
- ** OpenHost
- **
- ** Open a connection to the host named by the IP address and port number specified.
- ** This routine provides a way to bypass the DNR when opening connections. If the
- ** doUseCName option was specified when the object was constructed, this method will
- ** issue a DNR call to obtain the remote host’s canonical name.
- **
- ** remoteHostIP (unsigned long): the remote host’s address
- ** remoteHostPort (unsigned short): the remote host’s port number
- **
- */
-
- void CTCPEndpoint::OpenHost(unsigned long remoteHostIP, unsigned short remoteHostPort)
-
- {
-
- // open the connection
-
- pendingOpenByName = TRUE;
- itsStream->OpenConnection(FALSE, remoteHostIP, remoteHostPort, localPort);
-
-
- // set window title to dotted IP address until we can get the canonical name
-
- itsResolver->DoAddrToStr(remoteHostIP, hostCName);
- StateChanged();
-
-
- // if desired, get the canonical name
-
- if (useCName) {
- itsResolver->DoAddrToName(hostAddress);
- pendingOpenByName = TRUE;
- }
-
- }
-
-
- /*______________________________________________________________________
- **
- ** Listen
- **
- ** Initiate a “passive open” command. Wait for a remote host to attempt to connect to this
- ** machine. If the connection is to come from a specific host, the host’s IP address must be
- ** specified and the port number may be specified. If the connection may come from any host,
- ** both the IP address and port number must be left blank.
- **
- ** remoteHostIP (unsigned long): the remote host’s address
- ** remoteHostPort (unsigned short): the remote host’s port number
- **
- */
-
- void CTCPEndpoint::Listen(unsigned long remoteHostIP, unsigned short remoteHostPort)
-
- {
- pendingOpenByName = TRUE;
- itsStream->OpenConnection(TRUE, remoteHostIP, remoteHostPort, localPort);
- }
-
-
- /*______________________________________________________________________
- **
- ** LocalClose
- **
- ** Use this method when the user clicks the close box, or your application is done with
- ** this session. Ensures that the TCP stream is gracefully closed. If not quitting, delays
- ** closure until MacTCP says the stream has been terminated. Note that this method
- ** has the same interface as the CDirector::Close.
- **
- ** This method is not called by the CTCPEndpoint class and need not be overriden.
- **
- ** quitting (Boolean): TRUE if quitting
- **
- ** return (Boolean): FALSE if close/quit should be aborted
- **
- */
-
- Boolean CTCPEndpoint::LocalClose(Boolean quitting)
-
- {
- Boolean hadSessionOpen;
- unsigned short cState;
-
-
- // if session is open, give time for session to close
-
- if (itsStream) {
- cState = itsStream->ConnectionState();
- hadSessionOpen = sessionOpen;
- if (sessionOpen)
- itsStream->Close();
- if (sessionOpening)
- itsStream->Abort();
- }
- else
- hadSessionOpen = FALSE;
-
-
- // close the document – maybe?
-
- return (quitting || !hadSessionOpen || !goAwayOnClose);
-
- }
-
-
- /*______________________________________________________________________
- **
- ** SessionEstablished
- **
- ** Indicates whether a TCP session is established and ready for data.
- **
- ** return (Boolean): TRUE if session is currently established
- **
- */
-
- Boolean CTCPEndpoint::SessionEstablished()
-
- {
- if (itsStream)
- return (itsStream->ConnectionState() == strEstablished);
- else
- return FALSE;
- }
-
-
- // —— sending data ——
-
- /*______________________________________________________________________
- **
- ** SendBfrCpy
- **
- ** Send bytes to the TCP stream. Copies the data to a buffer which can persist beyond the
- ** function or object which generated the data.
- **
- ** theData (const void*): the bytes to send
- ** theDataSize (unsigned short): number of bytes to send
- **
- */
-
- void CTCPEndpoint::SendBfrCpy(const void* theData, unsigned short theDataSize)
-
- {
- itsStream->SendBfrCpy(theData, theDataSize);
- }
-
-
- /*______________________________________________________________________
- **
- ** SendBfrNoCpy
- **
- ** Send bytes to the TCP stream. Does not copy the data. The caller is responsible for
- ** ensuring that the data are available until the call is completed. You may detect the safe
- ** transmittal of your data by overriding the HandleDataSent() method and comparing
- ** pointers. You may also request that the data be disposed (using the DisposPtr routine)
- ** when the call completes by setting disposeWhenDone to TRUE.
- **
- ** theData (const void*): the bytes to send
- ** theDataSize (unsigned short): number of bytes to send
- ** disposeWhenDone (Boolean): set to TRUE to dispose of the buffer (DisposPtr)
- ** when completed (only if this pointer was
- ** allocated as a pointer, not a handle deref)
- ** notifyWhenDone (Boolean): set to TRUE to notify the endpoint object
- ** when completed (via HandleDataSent or
- ** HandleSendFailed)
- **
- */
-
- void CTCPEndpoint::SendBfrNoCpy(const void* theData, unsigned short theDataSize,
- Boolean disposeWhenDone, Boolean notifyWhenDone)
-
- {
- itsStream->SendBfrNoCpy(theData, theDataSize, disposeWhenDone, notifyWhenDone);
- }
-
-
- /*______________________________________________________________________
- **
- ** SendChar
- **
- ** Send a single character to the TCP stream.
- **
- ** theChar (char): the character to send
- **
- */
-
- void CTCPEndpoint::SendChar(const char theChar)
-
- {
- SendBfrCpy(&theChar, 1);
- }
-
-
- /*______________________________________________________________________
- **
- ** SendCString
- **
- ** Send a C string to the TCP stream.
- **
- ** theString (char*): the string to send
- **
- */
-
- void CTCPEndpoint::SendCString(const char* theString)
-
- {
- SendBfrCpy(theString, cstrlen((char*) theString));
- }
-
-
- /*______________________________________________________________________
- **
- ** SendPString
- **
- ** Send a Pascal string to the TCP stream.
- **
- ** theString (unsigned char* ): the string to send
- **
- */
-
- void CTCPEndpoint::SendPString(const unsigned char* theString)
-
- {
- SendBfrCpy((char*) theString + 1, theString[0]);
- }
-
-
- /*______________________________________________________________________
- **
- ** SetNextPush
- **
- ** The next data will be send with the “push” flag set.
- **
- */
-
- void CTCPEndpoint::SetNextPush()
-
- {
- itsStream->SetNextPush();
- }
-
-
- /*______________________________________________________________________
- **
- ** SetNextUrgent
- **
- ** The next data will be send with the “urgent” flag set.
- **
- */
-
- void CTCPEndpoint::SetNextUrgent()
-
- {
- itsStream->SetNextUrgent(FALSE);
- }
-
-
- /*______________________________________________________________________
- **
- ** endl (manipulator for CTCPEndpoint)
- **
- ** Send end-of-line character.
- **
- */
-
- CTCPEndpoint& endl(CTCPEndpoint& ep)
- {
- ep.SendChar('\r');
- return ep;
- }
-
-
- /*______________________________________________________________________
- **
- ** local_IP (manipulator for CTCPEndpoint)
- **
- ** Send local IP address in dotted IP format.
- **
- */
-
- CTCPEndpoint& local_IP(CTCPEndpoint& ep)
- {
- char ip_addr[16];
- UTurboTCP::DoAddrToStr(ep.GetLocalHostIP(), ip_addr);
- ep << ip_addr;
- return ep;
- }
-
-
- /*______________________________________________________________________
- **
- ** remote_IP (manipulator for CTCPEndpoint)
- **
- ** Send remote IP address in dotted IP format.
- **
- */
-
- CTCPEndpoint& remote_IP(CTCPEndpoint& ep)
- {
- char ip_addr[16];
- UTurboTCP::DoAddrToStr(ep.GetRemoteHostIP(), ip_addr);
- ep << ip_addr;
- return ep;
- }
-
-
- /*______________________________________________________________________
- **
- ** push (manipulator for CTCPEndpoint)
- **
- ** Send next data with “push” flag set.
- **
- */
-
- CTCPEndpoint& push(CTCPEndpoint& ep)
-
- {
- ep.SetNextPush();
- return ep;
- }
-
-
- /*______________________________________________________________________
- **
- ** urgent (manipulator for CTCPEndpoint)
- **
- ** Send next data with “urgent” flag set.
- **
- */
-
- CTCPEndpoint& urgent(CTCPEndpoint& ep)
-
- {
- ep.SetNextUrgent();
- return ep;
- }
-
-
- // —— configuration methods ——
-
- /*______________________________________________________________________
- **
- ** Use these methods to set various IP parameters for the next connection built on this
- ** endpoint. If a session has been opened already on this endpoint, these methods will have
- ** no effect on the current session.
- **
- */
-
- void CTCPEndpoint::SetDefaultPort(unsigned short newDefaultPort) // set default remot host port
- { defaultPort = newDefaultPort; }
- void CTCPEndpoint::SetLocalHostPort(unsigned short newLocalPort) // set a new local host port for next connection
- { localPort = newLocalPort; }
- void CTCPEndpoint::SetOpenTimeout(unsigned short openMaxSeconds) // max time to establish session for next connection
- { itsStream->SetULPTimeoutValue(openMaxSeconds); }
- void CTCPEndpoint::SetListenTimeout(unsigned short openMaxSeconds) // max time to wait for passive connection
- { itsStream->SetCommandTimeout((short) openMaxSeconds); }
- void CTCPEndpoint::SetTypeOfService(Boolean lowDelay, // set type of service for next connection
- Boolean highThroughput, Boolean highReliability)
- { itsStream->SetTypeOfService((lowDelay ? 0x01 : 0) |
- (highThroughput ? 0x02 : 0) | (highReliability ? 0x04 : 0)); }
- void CTCPEndpoint::SetPrecedence(TCPPrecedence newPrecedence) // set precedence for next connection
- { itsStream->SetPrecedence((short) newPrecedence); }
- void CTCPEndpoint::SetDontFragment(Boolean newDontFragment) // set/clear don’t fragment for next connection
- { itsStream->SetDontFrag((short) newDontFragment); }
- void CTCPEndpoint::SetTimeToLive(unsigned short newTimeToLive) // maximum hop count for IP connection
- { itsStream->SetTimeToLive(newTimeToLive); }
- void CTCPEndpoint::SetSecurity(unsigned short newSecurity) // security flag
- { itsStream->SetSecurity(newSecurity); }
-
-
- // —— selectors ——
-
- /*______________________________________________________________________
- **
- ** Use these methods to get information on the current endpoint and connection.
- **
- */
-
- void CTCPEndpoint::GetRemoteHostName(char* hostStringBfr) // get the name of the remote host machine
- { BlockMove(hostCName, hostStringBfr, cstrlen(hostCName)); }
- unsigned long CTCPEndpoint::GetRemoteHostIP()
- { return hostAddress; }
- unsigned short CTCPEndpoint::GetRemoteHostPort()
- { return actualPort; }
- unsigned long CTCPEndpoint::GetLocalHostIP()
- { return UTurboTCP::GetLocalIPAddr(); }
- unsigned short CTCPEndpoint::GetLocalHostPort()
- { return localPort; }
- unsigned short CTCPEndpoint::GetDefaultPort()
- { return defaultPort; }
-
-
- // —— state change notifications ——
-
- /*______________________________________________________________________
- **
- ** RemoteClose (protected method)
- **
- ** This method is called when the remote host closes or aborts a session. Override this
- ** to ensure that your windows are closed or the user is somehow notified. (Be sure to
- ** call this method as well.)
- **
- */
-
- void CTCPEndpoint::RemoteClose()
-
- {
- Boolean hadSessionOpen;
- unsigned short cState;
-
-
- // be sure to acknowledge the remote host’s intention to close
-
- if (itsStream) {
- cState = itsStream->ConnectionState();
- if (sessionOpen)
- itsStream->Close();
- if (sessionOpening)
- itsStream->Abort();
- }
- }
-
-
- /*______________________________________________________________________
- **
- ** StateChanged (protected method)
- **
- ** Called by other methods when the connection state changes (i.e. opens, aborts, or closes).
- ** Builds a new window title, then calls the SetWindowTitle() method to signal that the
- ** window’s title should be changed.
- **
- ** If working with CDocument or CDialogDirector, SetWindowTitle() should look like this:
- **
- ** CYourClass::SetWindowTitle(Str255 newTitle)
- ** {
- ** if (itsWindow)
- ** itsWindow->SetTitle(newTitle);
- ** }
- **
- */
-
- void CTCPEndpoint::StateChanged()
-
- {
- Str255 fileStr = "\p";
- Str255 hostStr = "\p";
- Str255 tempStr = "\p";
- Boolean sessionReady = SessionEstablished();
-
-
- // build document name string (if requested)
-
- if (showFileName) {
- GetFileName(fileStr);
- if (fileStr[0] == '\0') {
- if (!untitledNumber)
- untitledNumber = gDecorator->GetWCount();
- GetIndString(fileStr, STR__WindowStrings, Wstr_Untitled);
- NumToString(untitledNumber, tempStr);
- ConcatPStrings(fileStr, tempStr);
- }
- }
-
-
- // build host name string
-
- if (showHostName) {
- if (!hostCName[0])
- GetIndString(hostStr, STR__WindowStrings, Wstr_NoSession);
- else {
-
- if (!sessionReady) // left “(” if not ready
- GetIndString(hostStr, STR__WindowStrings, Wstr_NotReadyPrefix);
-
- BlockMove(&hostCName, &tempStr, 255); // host name, minus trailing “.”
- CtoPstr((char*) &tempStr);
- if (tempStr[tempStr[0]] == '.')
- tempStr[0]--;
- ConcatPStrings(hostStr, tempStr);
-
- if (actualPort != defaultPort) { // port number if non-standard
- GetIndString(tempStr, STR__WindowStrings, Wstr_PortDelimiter);
- ConcatPStrings(hostStr, tempStr);
- NumToString(actualPort, tempStr);
- ConcatPStrings(hostStr, tempStr);
- }
-
- if (!sessionReady) { // right “)” if not ready
- GetIndString(tempStr, STR__WindowStrings, Wstr_NotReadySuffix);
- ConcatPStrings(hostStr, tempStr);
- }
-
- }
-
- if (showFileName) { // “ : ” between file & host name
- GetIndString(tempStr, STR__WindowStrings, Wstr_Separator);
- ConcatPStrings(fileStr, tempStr);
- }
- ConcatPStrings(fileStr, hostStr);
- }
-
-
- // set the title
-
- if (showFileName || showHostName) // if neither file nor hostname are requested,
- // assume subclass will specify window titles
- SetWindowTitle(fileStr);
-
- }
-
-
- // —— error handling ——
-
- /*______________________________________________________________________
- **
- ** TCPErrorAlert (protected method)
- **
- ** Display a customized message to indicate to the user that the connection failed. This
- ** routine is copied from the TCL’s routine ErrorAlert.
- **
- ** err (OSErr): the error number
- ** message (long): message code (same as for ErrorAlert, see <TCLUtilities.cp>
- ** alertID (short): the ALRT/DITL resources to use
- ** parm3 (short): the number to plug into ^3
- **
- ** return (short): the item which caused the alert to return
- **
- */
-
- short CTCPEndpoint::TCPErrorAlert(OSErr err, long message, short alertID, short parm3)
-
- {
- Str255 errStr;
- Str255 hostStr;
- Str63 numStr;
- Str63 numStr3;
- short strIndex, strID;
-
-
- // silence any further messages
-
- gLastError = kSilentErr;
-
-
- // see if anyone filled in the message field
-
- errStr[0] = 0;
- strIndex = LoShort(message);
-
- if (strIndex > 0) {
- strID = HiShort(message);
- if (strID == 0)
- strID = STR_TCLfailMsgs; // use built-in messages
- else
- strID += kUserFailMsgBase; // use user’s message STR#
- GetIndString(errStr, strID, strIndex);
- }
-
-
- // if still no message, check for 'Estr' resource
-
- if (errStr[0] == 0) {
- StringHandle strH;
-
- strH = (StringHandle) GetResource(ErrMsg_Res, err);
- if (!strH)
- strH = GetString(STRosError2);
- if (strH)
- CopyPString(*strH, errStr);
- }
-
-
- // convert Mac error# and user’s host name to strings
-
- NumToString(err, numStr);
- NumToString(parm3, numStr3);
-
- BlockMove(&hostCName, &hostStr, 255);
- CtoPstr((char*) &hostStr);
- if (hostStr[hostStr[0]] == '.')
- hostStr[0]--;
-
- ParamText(errStr, numStr, hostStr, numStr3);
-
-
- // avoid infinite recursion in error handling by specifically
- // testing if the ALRT and DITL resources we need are there
-
- if ((GetResource('ALRT', alertID) == NULL) ||
- (GetResource('DITL', alertID) == NULL))
- {
- if (gError)
- gError->MissingResources();
- else
- ExitToShell(); // nothing else we can do...
- }
-
-
- // show the error alert
-
- PositionDialog('ALRT', alertID);
- InitCursor();
- return StopAlert(alertID, NULL);
-
- }
-
-
- // —— TCP/DNR notification routines ——
-
- /*______________________________________________________________________
- **
- ** HandleClosing (protected method)
- **
- ** Respond to notification that the session is being closed.
- **
- ** remoteClosing (Boolean): TRUE if close initiated by remote host
- **
- */
-
- void CTCPEndpoint::HandleClosing(Boolean remoteClosing)
-
- {
- StateChanged();
- if (remoteClosing)
- RemoteClose();
- }
-
-
- /*______________________________________________________________________
- **
- ** HandleOpened (protected method)
- **
- ** Respond to successful completion of a TCPPassiveOpen or TCPActiveOpen command.
- **
- */
-
- void CTCPEndpoint::HandleOpened()
-
- {
- actualPort = itsStream->itsRemotePort;
- StateChanged();
- }
-
-
- /*______________________________________________________________________
- **
- ** HandleOpenFailed (protected method)
- **
- ** Respond to notification that a TCPOpen command failed.
- **
- ** theResultCode (OSErr): the reason for failure
- */
-
- void CTCPEndpoint::HandleOpenFailed(OSErr theResultCode)
-
- {
- TCPErrorAlert(theResultCode, 0L, ALRT_TCPOpenFailed, 1);
- RemoteClose();
- FailOSErr(kSilentErr);
- }
-
-
- /*______________________________________________________________________
- **
- ** HandleTCPError (protected method)
- **
- ** Respond to failure of a TCP command that was not expected. Default method displays a
- ** dialog, but takes no other action.
- **
- ** theResultCode (OSErr): the result code
- ** theCsCode (short): the TCP command number that failed
- **
- */
-
- void CTCPEndpoint::HandleTCPError(OSErr theResultCode, short theCsCode)
-
- {
- TCPErrorAlert(theResultCode, 0L, ALRT_TCPUnexpError, theCsCode);
- }
-
-
- /*______________________________________________________________________
- **
- ** HandleTerminated (protected method)
- **
- ** Respond to session termination event.
- **
- ** terminReason (unsigned short): reason for termination (see TCP dev guide, p93)
- ** aboutToDispose (Boolean): TRUE if TCP stream will now dispose of itself
- **
- */
-
- void CTCPEndpoint::HandleTerminated(TCPTerminReason terminReason, Boolean aboutToDispose)
-
- {
-
- // display error alert unless due to normal closure
-
- if ((terminReason != tcpTermAbort) && (terminReason != tcpTermClose))
- TCPErrorAlert(terminReason + ESTR_TerminBase, 0L, ALRT_TCPTerminated, 0);
-
-
- // retitle window & close if requested
-
- StateChanged();
- RemoteClose();
-
-
- // mark TCP stream as gone if appropriate
-
- if (aboutToDispose)
- itsStream = NULL;
-
- }
-
-
- /*______________________________________________________________________
- **
- ** HandleStrToAddr (protected method)
- **
- ** Respond to nofitication that a resolver StrToAddr call has completed. Most of this code
- ** is written to complete the OpenUserHost method. If OpenUserHost was issued, this method
- ** proceeds to establish a connection with the IP host which was named by the user.
- **
- ** theHostInfo (struct hostInfo*): the hostInfo record (see MacTCP Dev Guide, p70)
- **
- */
-
- void CTCPEndpoint::HandleStrToAddr(struct hostInfo* theHostInfo)
-
- {
-
- // if OpenUserHost was issued, finish the job
-
- if ((pendingOpenByName) && (itsStream)) {
- if ((*theHostInfo).rtnCode == noErr) {
-
-
- // success, open the connection
-
- hostAddress = (*theHostInfo).addr[0];
- pendingOpenByName = FALSE;
- itsStream->OpenConnection(FALSE, hostAddress, pendingPortNumber, localPort);
-
-
- // if desired, get the canonical name
-
- if (useCName) {
- if ((*theHostInfo).cname[0] == 0) {
- itsResolver->DoAddrToName(hostAddress);
- pendingOpenByName = TRUE;
- }
- else
- BlockMove(&(*theHostInfo).cname, &hostCName, 255);
- }
-
-
- // set the window title to reflect the name
-
- StateChanged();
-
- } else {
-
-
- // failed, issue alert & quit
-
- pendingOpenByName = FALSE;
- HandleOpenFailed((*theHostInfo).rtnCode);
-
- } // if (...noErr)
- } // if (pendingOpenByName)
-
- }
-
-
- /*______________________________________________________________________
- **
- ** HandleAddrToName (protected method)
- **
- ** Respond to nofitication that a resolver AddrToName call has completed.
- **
- ** theHostInfo (struct hostInfo*): the hostInfo record (see MacTCP Dev Guide, p75)
- **
- */
-
- void CTCPEndpoint::HandleAddrToName(struct hostInfo* theHostInfo)
-
- {
-
- // if OpenUserHost was issued, grab the hostname
-
- if ((pendingOpenByName) && (useCName)) {
- if ((*theHostInfo).rtnCode == noErr) {
- pendingOpenByName = FALSE;
- if ((*theHostInfo).cname[0])
- BlockMove(&(*theHostInfo).cname, &hostCName, 255);
- StateChanged();
- }
- }
-
- }
-