home *** CD-ROM | disk | FTP | other *** search
- /*****
- *
- * TCPUtil.c
- *
- * This is a support file for "Grant's CGI Framework".
- * Please see the license agreement that accompanies the distribution package
- * for licensing details.
- *
- * Copyright ©1996 by Grant Neufeld
- * grant@acm.com
- * http://arpp.carleton.ca/cgi/framework/
- *
- *****/
-
- #include "MyConfiguration.h"
- #if kCompileWithTCPCode
-
- #if kCompilingForWSAPI
- #include <WSAPI.h>
- #endif
-
- #include "CGI.h"
- #include "DebugUtil.h"
- #include "MemoryUtil.h"
-
- #include "TCPUtil.h"
-
-
- /*** LOCAL VARIABLES ***/
-
- /*** LOCAL CONSTANTS ***/
-
- /*** LOCAL PROTOTYPES ***/
-
- /*** FUNCTIONS ***/
-
- /* */
- p_export
- SInt32
- TCPOpenClientStream ( CGIHdl theCGIHdl, UInt32 serverIP, UInt16 serverPort )
- {
- #if kCompilingForWSAPI
-
- WSAPI_ErrorCode theErr;
- SInt8 savedHandleState;
-
- my_assert ( theCGIHdl != NULL, "\pTCPOpenClientStream: theCGIHdl is NULL" );
-
- savedHandleState = HGetState ( (Handle)theCGIHdl );
- HLock ( (Handle)theCGIHdl );
-
- theErr = WSAPI_OpenStream ( (*theCGIHdl)->wsapi, &((*theCGIHdl)->tcpStream), serverIP, serverPort );
-
- HSetState ( (Handle)theCGIHdl, savedHandleState );
-
- #else
-
- #pragma unused(theCGIHdl,serverIP,serverPort)
-
- OSErr theErr;
-
- theErr = 1;
-
- #endif
-
- return theErr;
- } /* TCPOpenClientStream */
-
-
- /* */
- p_export
- SInt32
- TCPCloseClientStream ( CGIHdl theCGIHdl, UInt32 serverIP, UInt16 serverPort )
- {
- #if kCompilingForWSAPI
-
- WSAPI_ErrorCode theErr;
- SInt8 savedHandleState;
-
- my_assert ( theCGIHdl != NULL, "\pTCPCloseClientStream: theCGIHdl is NULL" );
-
- savedHandleState = HGetState ( (Handle)theCGIHdl );
- HLock ( (Handle)theCGIHdl );
-
- theErr = WSAPI_CloseStream ( (*theCGIHdl)->wsapi, &((*theCGIHdl)->tcpStream) );
-
- HSetState ( (Handle)theCGIHdl, savedHandleState );
-
- #else
-
- #pragma unused(theCGIHdl,serverIP,serverPort)
-
- OSErr theErr;
-
- theErr = 1;
-
- #endif
-
- return theErr;
- } /* TCPCloseClientStream */
-
-
- /* */
- p_export
- SInt32
- TCPReadFromClientStream ( CGIHdl theCGIHdl, void *outData, UInt32 *outDataSize )
- {
- #if kCompilingForWSAPI
-
- WSAPI_ErrorCode theErr;
- SInt8 savedHandleState;
-
- my_assert ( theCGIHdl != NULL, "\pTCPReadFromClientStream: theCGIHdl is NULL" );
-
- savedHandleState = HGetState ( (Handle)theCGIHdl );
- HLock ( (Handle)theCGIHdl );
-
- theErr = WSAPI_ReadStream ( (*theCGIHdl)->wsapi, &((*theCGIHdl)->tcpStream), outData, outDataSize );
-
- HSetState ( (Handle)theCGIHdl, savedHandleState );
-
- #else
-
- #pragma unused(theCGIHdl,outData,outDataSize)
-
- OSErr theErr;
-
- theErr = 1;
-
- #endif
-
- return theErr;
- } /* TCPReadFromClientStream */
-
-
- /* */
- p_export
- SInt32
- TCPWriteToClientStream ( CGIHdl theCGIHdl, void *dataToSend, UInt32 dataLength )
- {
- #if kCompilingForWSAPI
-
- WSAPI_ErrorCode theErr;
- SInt8 savedHandleState;
-
- my_assert ( theCGIHdl != NULL, "\pTCPWriteToClientStream: theCGIHdl is NULL" );
-
- savedHandleState = HGetState ( (Handle)theCGIHdl );
- HLock ( (Handle)theCGIHdl );
-
- theErr = WSAPI_WriteStream ( (*theCGIHdl)->wsapi, &((*theCGIHdl)->tcpStream), dataToSend, dataLength );
-
- HSetState ( (Handle)theCGIHdl, savedHandleState );
-
- #else
-
- #pragma unused(theCGIHdl,dataToSend,dataLength)
-
- OSErr theErr;
-
- theErr = 1;
-
- #endif
-
- return theErr;
- } /* TCPWriteToClientStream */
-
-
- /* */
- p_export
- SInt32
- TCPClientStreamStatus ( CGIHdl theCGIHdl, UInt32 serverIP, TCPStreamStatus *outStatus, UInt32 *bytesUnread )
- {
- #if kCompilingForWSAPI
-
- WSAPI_ErrorCode theErr;
- SInt8 savedHandleState;
- WSAPI_ConnectionStatus theStatus;
-
- my_assert ( theCGIHdl != NULL, "\pTCPClientStreamStatus: theCGIHdl is NULL" );
-
- savedHandleState = HGetState ( (Handle)theCGIHdl );
- HLock ( (Handle)theCGIHdl );
-
- theErr = WSAPI_Stream ( (*theCGIHdl)->wsapi, &((*theCGIHdl)->tcpStream), outStatus, bytesUnread );
-
- HSetState ( (Handle)theCGIHdl, savedHandleState );
-
- #else
-
- #pragma unused(theCGIHdl,serverIP,outStatus,bytesUnread)
-
- OSErr theErr;
-
- theErr = 1;
-
- #endif
-
- return theErr;
- } /* TCPClientStreamStatus */
-
-
- /* */
- p_export
- SInt32
- TCPNameToIPAddress ( CGIHdl theCGIHdl, char *name, UInt32 *ipAddress )
- {
- #if kCompilingForWSAPI
-
- WSAPI_ErrorCode theErr;
-
- my_assert ( theCGIHdl != NULL, "\pTCPNameToIPAddress: theCGIHdl is NULL" );
- my_assert ( name != NULL, "\pTCPNameToIPAddress: name is NULL" );
- my_assert ( ipAddress != NULL, "\pTCPNameToIPAddress: ipAddress is NULL" );
-
- theErr = WSAPI_IPNameToAddr ( (*theCGIHdl)->wsapi, name, ipAddress );
-
- #else
-
- #pragma unused(theCGIHdl,name,ipAddress)
-
- OSErr theErr;
-
- theErr = 1;
-
- #endif
-
- return theErr;
- } /* TCPNameToIPAddress */
-
-
- #endif /* kCompileWithTCPCode */
- /*** EOF ***/
-