/* c4com.h   (c)Copyright Sequiter Software Inc., 1988-1996.  All rights reserved. */

#ifdef __cplusplus
   extern "C" {
#endif

S4EXPORT long S4FUNCTION code4timeout( CODE4 S4PTR * ) ;
S4EXPORT void S4FUNCTION code4timeoutSet( CODE4 S4PTR *, long ) ;

#ifdef __cplusplus
   }
#endif


#ifndef S4OFF_COMMUNICATIONS

struct CONNECTION4NETSt ;
#define CONNECTION4ID long
#define COM4DEFAULT_MESSAGE_LEN 1024

#ifndef S4SPX
   #ifndef S4WINSOCK
      #ifndef S4LOCAL
         typedef struct CONNECTION4NETSt
         {
            void * c4null ;
         } CONNECTION4NET ;
         typedef struct SOCKET4NETSt
         {
            void * c4null ;
         } SOCKET4NET ;
      #endif
   #endif
#endif

typedef struct PACKET4HEADERSt
{
   CONNECTION4ID  connectionId ;    /* who is sending the packet? */
   long  replyNo ;  /* for a particular request, to ensure duplicate requests are not performed, and etc. */
   unsigned char numParts ; /* total #parts to the packet */
   unsigned char partNo ;   /* what part # of the packet this part is */
   unsigned short int packetDataOffset ;  /* where does the data start in the packet? */
   unsigned short int packetDataLen ;     /* what is the data length for this packet? */
} PACKET4HEADER ;

typedef struct PACKET4St
{
   CONNECTION4ID  connectionId ;    /* who is sending the packet? */
   long  replyNo ;  /* for a particular request, to ensure duplicate requests are not performed, and etc. */
   unsigned char numParts ; /* total #parts to the packet */
   unsigned char partNo ;   /* what part # of the packet this part is */
   unsigned short int packetDataOffset ;  /* where does the data start in the packet? */
   unsigned short int packetDataLen ;     /* what is the data length for this packet? */

   /* if partNo == 0, this header follows... */
   short int      type ;
   long int dataLen ;
   short int      status ;   /* function rc */
   long  int      errCode2 ;
   long clientDataId ;   /* which client-data4 id is being referred to? */
   long serverDataId ;   /* which server-data4 id is being referred to? */
   short int      readLock ;
/*   short int      lockEnforce ;*/
   short int      unlockAuto ;
   short int      didUnlock ;     /* did the server perform unlocks for the client? */
   short int      didUnlockData ; /* did the server perform data-level unlocks for the client? */
   short int      requestLockedInfo ;
/*   char     name[S4STAND_ALONE_ALIAS_LEN+1] ;*/
/*   char    data[remainingPacketLength] ;*/
} PACKET4 ;

typedef struct MESSAGE4St
{
   LINK4 link ;
   #ifdef S4SERVER
      struct SERVER4CLIENTSt *client ;
   #endif
   PACKET4 *packet ;
   unsigned short int len ;
} MESSAGE4 ;

typedef struct SOCKET4St
{
   LINK4 link ;

   CODE4 *cb ;
   struct SOCKET4NETSt *net ;
   struct CONNECTION4St *connect ;
   #ifdef S4SERVER
      LIST4 connections ;    /* connection list of CONNECTION4's */
   #else
      char serverName[S4MAX_SERVER_NAME_SIZE] ;
   #endif
   #ifdef E4ANALYZE
      short int initUndone ;
   #endif
} SOCKET4 ;

typedef struct MESSAGE4DATASt
{
   LINK4 link ;
   S4CONST char *data ;
   char *allocatedData ;
   unsigned long int len ;
   unsigned long int allocLen ;
   char didAlloc ;
} MESSAGE4DATA ;

typedef struct CONNECTION4St
{
   LINK4 link ;
   LINK4 confirmLink ;

   MESSAGE4 *message ;
   LIST4 messageData ;
   unsigned short dataLen ;
   unsigned long int totalDataLen ;

   char connected ;
   short int connectionFailure ;    /* true if a communications failure occurs */

   short int adjustForLocked ;

   SOCKET4 *socket ;
   CODE4 *cb ;
   struct CONNECTION4NETSt *net ;
   LIST4 receivedMessages ;    /* a list of received, unprocessed, partial messages */

   #ifdef E4ANALYZE
      short int initUndone ;
   #endif
} CONNECTION4 ;

/* structures for d4open/d4create communication information between client/server */
typedef struct
{
   unsigned short int headerLen ;
   unsigned short int recWidth ;
   char version ;
   long serverId ;   /* for when referring to the data on the server */
   unsigned short int infoLen ;
   unsigned short int numTags ;
   short int readOnly ;
   /* char *info */
   /* void *tagInfo (for each tag...) */
} CONNECTION4OPEN_INFO_OUT ;

typedef struct
{
   unsigned short int numTags ;
   /* void *tagInfo (for each tag...) */
} CONNECTION4INDEX_INFO_OUT ;

typedef struct
{
   char name[even4up( LEN4PATH + 1 )] ;
   short int errDefaultUnique ;
   short int accessMode ;
   short int openForCreate ;
   unsigned short int readOnly ;
   unsigned short int safety ;    /* for catalog only */
   unsigned short int singleOpen ;
   unsigned short int log ;
} CONNECTION4OPEN_INFO_IN ;

typedef struct
{
   char password[even4up( LEN4DATA_ALIAS + 1 )] ;
} CONNECTION4PASSWORD_INFO_IN ;

typedef struct
{
   short int accessMode ;
   unsigned short int readOnly ;
   short int nameLen ;
   short int errDefaultUnique ;
   short int openForCreate ;
   unsigned short int safety ;    /* for catalog only */
/*   char accessName[nameLen] ;*/
} CONNECTION4OPEN_INDEX_INFO_IN ;

typedef struct
{
   unsigned short int numTags ;
   /* void *tagInfo (for each tag...) */
} CONNECTION4OPEN_INDEX_INFO_OUT ;

typedef struct
{
   short int accessMode ;
   unsigned short int readOnly ;
   short int nameLen ;
   short int errDefaultUnique ;
   short int openForCreate ;
   unsigned short int safety ;    /* for catalog only */
   char tagName[even4up( LEN4PATH + 1 )] ;
   short int hasIndex ;
   char indexName[even4up( LEN4PATH + 1 )] ;  /* if t4open is deriving from i4open */
/*   char indexName[nameLen] ;*/
} CONNECTION4OPEN_TAG_INFO_IN ;

typedef struct
{
   short int autoOpened ;   /* flag for whether or not server had to do the open */
/*    void *tagInfo (for each tag...) */
} CONNECTION4OPEN_TAG_INFO_OUT ;

typedef union
{
   char S4PTR *ptr ;
   unsigned short int offset ;
} CONNECTION4PTR_UNION ;

typedef struct
{
   CONNECTION4PTR_UNION name ;
   short int         type ;
   unsigned short int len ;
   unsigned short int dec ;
   unsigned short int nulls ;
} CONNECTION4FIELD_INFO ;

typedef struct
{
   CONNECTION4PTR_UNION name ;
   CONNECTION4PTR_UNION expression ;
   CONNECTION4PTR_UNION filter ;
   short int unique ;
   unsigned short int descending ;
   /* void *data */
} CONNECTION4TAG_INFO ;

typedef struct
{
   char     name[even4up( LEN4PATH + 1 )] ;
   unsigned short int numFields ;
   unsigned short int numTags ;
   unsigned short int fieldInfoLen ;
   unsigned short int createTemp ;      /* temporary create only ( name null ) */
   unsigned short int safety ;
   unsigned short int readOnly ;        /* for catalog purposes */
   unsigned short int log ;
   short int compatibility ;            /* what type of data file to create */
/*   unsigned short int tagInfoLen ;*/
   /* start of info... */
} CONNECTION4CREATE_INFO_IN ;

/*typedef struct*/
/*{*/
/*   char     name[even4up( LEN4PATH + 1 )] ;*/
/*} CONNECTION4CREATE_TEMP_INFO_OUT ;*/

typedef struct
{
   short int catalogAdd ;
   short int catalogStatus ;
} CONNECTION4CATALOG_SET_INFO_IN ;

typedef struct
{
   short int isProduction ;
   unsigned short int numTags ;
   char indexFileName[even4up( LEN4PATH + 1 )] ;
   unsigned short int createTemp ;      /* temporary create only ( name null ) */
   unsigned short int safety ;
   unsigned short int readOnly ;        /* for catalog purposes */
   /* start of info... */
} CONNECTION4INDEX_CREATE_INFO_IN ;

typedef struct
{
   char indexFileName[even4up( LEN4PATH + 1 )] ;
   unsigned short int numTags ;
   /* start of info... */
} CONNECTION4TAG_ADD_INFO_IN ;

typedef struct
{
   short int lockedDatafile ;
} CONNECTION4TAG_ADD_INFO_OUT ;

typedef struct
{
   short int lockedDatafile ;
} CONNECTION4INDEX_CREATE_INFO_OUT ;

typedef struct
{
   short int lockedDatafile ;
} CONNECTION4REINDEX_INFO_OUT ;

typedef struct
{
   short int lockedDatafile ;
} CONNECTION4CHECK_INFO_OUT ;

typedef struct
{
   short int lockedDatafile ;
} CONNECTION4PACK_INFO_OUT ;

typedef struct
{
   short int lockedDatafile ;
} CONNECTION4ZAP_INFO_OUT ;

/*
typedef struct
{
} CONNECTION4INDEX_CLOSE_INFO_IN ;
*/

typedef struct
{
   short int  usesTag ;
   char tagName[even4up( LEN4TAG_ALIAS + 1 )] ;
   long startRecno ;
} CONNECTION4DATA_POS_IN ;

typedef struct
{
   double position ;
} CONNECTION4DATA_POS_OUT ;

typedef struct
{
   double position ;
   short int  usesTag ;
   char tagName[even4up( LEN4TAG_ALIAS + 1 )] ;
} CONNECTION4DATA_POS_SET_IN ;

typedef struct
{
   long recNo ;
} CONNECTION4DATA_POS_SET_OUT ;

/* structures for d4seek communication information between client/server */
typedef struct
{
   char tagName[even4up( LEN4TAG_ALIAS + 1 )] ;
   unsigned short int keyLen ;
   unsigned short int fromCurrentPos ;
   long startPos ;  /* for seek next */
   /* char *key */
} CONNECTION4SEEK_INFO_IN ;

typedef struct
{
   char tagName[even4up( LEN4TAG_ALIAS + 1 )] ;
   long recno ;
} CONNECTION4TAG_SYNCH_INFO_IN ;

typedef struct
{
   long recNo ;
} CONNECTION4TAG_SYNCH_INFO_OUT ;

/* structures for d4skip communication information between client/server */
typedef struct
{
   char tagName[even4up( LEN4TAG_ALIAS + 1 )] ;
   short int usesTag ;
   long startPos ;
   long numSkip ;
} CONNECTION4SKIP_INFO_IN ;

#ifndef S4SINGLE
/*
typedef struct
{
   short int type ;
   long  recNum ;
   long clientId ;
   long serverId ;
} CONNECTION4LOCK_SINGLE_INFO_IN ;
*/

typedef struct
{
   short int numLocks ;
   /* locks */
} CONNECTION4LOCK_GROUP_INFO_IN ;
#endif

/* structures for d4go communication information between client/server */
typedef struct
{
   long recNo ;
} CONNECTION4GO_INFO_IN ;

typedef struct
{
   short int skipRc ;    /* used by d4skip to distinguish return codes */
   short int recordLocked ;
   long recNo ;
/*   char *record ;  */
} CONNECTION4GO_INFO_OUT ;

typedef struct
{
   char tagName[even4up( LEN4TAG_ALIAS + 1 )] ;
   short int  usesTag ;
} CONNECTION4TOP_INFO_IN ;

typedef struct
{
   long recNo ;
   short int recordLocked ;
   short int eofFlag ;
   short int bofFlag ;
/*   char *record ; */
} CONNECTION4TOP_INFO_OUT ;

typedef struct
{
   char tagName[even4up( LEN4TAG_ALIAS + 1 )] ;
   short int  usesTag ;
} CONNECTION4BOTTOM_INFO_IN ;

typedef struct
{
   char calcName[even4up( E4MAX_CALC_NAME ) ] ;
/*   char *expr */
} CONNECTION4CALC_CREATE_INFO_IN ;

typedef struct
{
   long recNo ;
   short int recordLocked ;
   short int eofFlag ;
   short int bofFlag ;
/*   char *record ; */
} CONNECTION4BOTTOM_INFO_OUT ;

/* structure for d4recCount communication information between client/server */
typedef struct
{
   long recCount ;
   short int  appendLocked ;
} CONNECTION4RECCOUNT_INFO_OUT ;

#ifndef S4SINGLE
/* structures for d4lock communication information between client/server */
typedef struct
{
   short int type ;
   short int test ;    /* are we testing for a lock only? */
   /* record info if appropriate */
} CONNECTION4LOCK_INFO_IN ;
#endif

/* structures for d4write communication information between client/server */
typedef struct
{
   long recNo ;
   short int numMemoFields ;   /* number of memo fields with data included */
   short int unlock ;   /* should a general unlock call be performed (d4appendStart) */
   /* char record[recWidth] */
   /* CONNECTION4MEMO memo[numMemoFields] */
} CONNECTION4WRITE_INFO_IN ;

typedef struct
{
   short int recordLocked ;
} CONNECTION4WRITE_INFO_OUT ;

typedef struct
{
   unsigned short int fieldNum ;
   unsigned long int memoLen ;
   /* char memo[memoLen] */
} CONNECTION4MEMO ;

typedef struct
{
   long recNo ;
   short int fieldNo ;
} CONNECTION4MEMO_INFO_IN ;

typedef struct
{
   unsigned long int memoLen ;
   /* char memo[memoLen] */
} CONNECTION4MEMO_INFO_OUT ;

typedef struct
{
   short int numMemoFields ;   /* number of memo fields with data included */
   /* char record[recWidth] */
   /* CONNECTION4MEMO memo[numMemoFields] */
} CONNECTION4APPEND_INFO_IN ;

typedef struct
{
   short int bofFlag ;
   short int eofFlag ;
   short int recordChanged ;
   short int recordLocked ;
   short int appendLocked ;
   long recNum ;
} CONNECTION4APPEND_INFO_OUT ;

/* structures for d4zap communication information between client/server */
typedef struct
{
   long recStart ;
   long recStop ;
} CONNECTION4ZAP_INFO_IN ;

typedef struct
{
   unsigned short int numServers ;
   /* start of info... */
} CONNECTION4COMMIT_INFO_IN ;

typedef struct
{
   char alias[even4up( LEN4TAG_ALIAS + 1 )] ;
   short int unique ;
} CONNECTION4UNIQUE_TAG_INFO ;

typedef struct
{
   unsigned short int numTags ;
/* for each tag...
   CONNECTION4UNIQUE_TAG_INFO tags[numTags] ;
*/
} CONNECTION4UNIQUE_INFO_IN ;

typedef struct
{
   char dateFormat[20] ;
} CONNECTION4DATE_FORMAT_SET_INFO_IN ;

typedef struct
{
   short int matchLen ;
   short int relationType ;
/*   short int sortType ;*/
   short int errorAction ;
   short int numSlaves ;
   short int dataId ;
   long clientId ;
   CONNECTION4PTR_UNION dataTagName ;
   CONNECTION4PTR_UNION masterExpr ;
   CONNECTION4PTR_UNION dataAccessName ;
} CONNECTION4RELATE ;

typedef struct
{
   unsigned short int skipBackwards ;
   CONNECTION4PTR_UNION exprSource ;
   CONNECTION4PTR_UNION sortSource ;
} CONNECTION4RELATION ;

typedef struct
{
   unsigned long relationId ;
   unsigned short int relateOffset ;
   unsigned short int flexOffset ;
   long masterClientId ;
   CONNECTION4RELATION relation ;
   unsigned short int bitmapDisable ;
/*   CONNECTION4RELATE relates[] ; */
/*   flex data */
} CONNECTION4RELATE_INIT_INFO_IN ;

typedef struct
{
   unsigned long relationId ;
/* list of relateid's for each relate */
} CONNECTION4RELATE_INIT_INFO_OUT ;

/* the output from relate4top, relate4bottom, relate4skip, relate4seek */
typedef struct
{
   unsigned long relationId ;
   /* record_num, record_count, record for each record */
} CONNECTION4RELATION_DATA_OUT ;

typedef struct
{
   unsigned long relationId ;
} CONNECTION4RELATE_TOP_INFO_IN ;

typedef struct
{
   unsigned long relationId ;
   long numSkips ;
} CONNECTION4RELATE_SKIP_INFO_IN ;

typedef struct
{
   unsigned long relationId ;
} CONNECTION4RELATE_BOTTOM_INFO_IN ;

typedef struct
{
   unsigned long relationId ;
} CONNECTION4RELATE_OPT_INFO_IN ;

typedef struct
{
   unsigned long relationId ;
   unsigned short int relateId ;
   long masterStartPos ;
} CONNECTION4RELATE_DO_INFO_IN ;

typedef struct
{
   unsigned long relationId ;
   unsigned short int relateId ;
   long masterStartPos ;
} CONNECTION4RELATE_DO_ONE_INFO_IN ;

typedef struct
{
   long recNo ;
} CONNECTION4RELATE_DO_ONE_INFO_OUT ;

typedef struct
{
   unsigned long eof ;
} CONNECTION4TRAN_EOF_INFO_OUT ;

typedef struct
{
   unsigned long eof ;
} CONNECTION4TRAN_EOF_HALT_INFO_OUT ;

typedef struct
{
   unsigned long relationId ;
} CONNECTION4RELATE_FREE_INFO_IN ;

/*
typedef struct
{
   unsigned long relationId ;
} CONNECTION4RELATE_CHANGED_INFO_IN ;
*/

#ifndef S4SINGLE
typedef struct
{
   long clientId ;
   long serverId ;
} CONNECTION4RELATE_LOCK_SUB_DATA ;

typedef struct
{
   unsigned long relationId ;
} CONNECTION4RELATE_LOCK_INFO_IN ;

typedef struct
{
   unsigned short int count ;
} CONNECTION4RELATE_LOCK_INFO_OUT ;

typedef struct
{
   unsigned long relationId ;
} CONNECTION4RELATE_UNLOCK_INFO_IN ;

/*typedef struct*/
/*{*/
/*   unsigned long unlockAuto ;*/
/*} CONNECTION4UNLOCK_INFO_IN ;*/

/*typedef struct*/
/*{*/
/*   unsigned short int unlockedData ;*/
/*} CONNECTION4LOCK_INFO_OUT ;*/

typedef struct
{
   long lockPos ;  /* ( record no if > 0, appendBytes if 0, file if -1 ) */
/*   char fileName[] ;*/
/*   char userId[] ;*/
/*   char netId[] ;*/
} CONNECTION4LOCKED_INFO_OUT ;
#endif

typedef struct
{
   long clientId ;
   unsigned short int numData ;
   unsigned short int numRelate ;
   unsigned long numRequests ;
   unsigned long numTransactions ;
   unsigned long numCompletedTransactions ;
   unsigned long numRollbacks ;
   short int activeTransaction ;   /* is there a current transaction? */
   double elapsedSeconds ;
} CONNECTION4CLIENT_INFO ;

typedef struct
{
   long clientId ;
} CONNECTION4CLIENT_CANCEL_INFO_IN ;

typedef struct CONNECTION4SERVER_INFO_OUTSt
{
   long memMax ;
   long memAlloc ;
   unsigned long numRequests ;
   unsigned short int numClients ;
   double elapsedSeconds ;
   /* CONNECTION4CLIENT_INFO clients[numClients] */
} CONNECTION4SERVER_INFO_OUT ;

#ifdef __cplusplus
   extern "C" {
#endif
int    connection4clear( CONNECTION4 * ) ;
#define connection4addData( a, b, c, d ) ( connection4insertData( (a), (b), (c), (d), 0 ) )
CONNECTION4 *connection4alloc( SOCKET4 * ) ;
#define packet4didUnlockData( p ) ( (p)->didUnlockData )

int connection4disconnect( CONNECTION4 * ) ;
int connection4errorDescribeExecute( const CONNECTION4 *, CODE4 *, int, long, const char *, const char *, const char * ) ;
int connection4free( CONNECTION4 * ) ;
int connection4init( CONNECTION4 *, SOCKET4 * ) ;
int connection4initUndo( CONNECTION4 * ) ;
int connection4insertData( CONNECTION4 *, const void *, const unsigned int, const int, const int ) ;
#define connection4requestLockedInfo( c ) ( packet4requestLockedInfo( (c)->message->packet ) )
int connection4setStatus( CONNECTION4 *, const int ) ;
#define connection4yield( c ) ( socket4netYield( (c)->socket->net ) )

#ifdef S4UTILS
   int S4FUNCTION connection4assign( CONNECTION4 *, const int, const long, const long ) ;
   S4CONST char * S4FUNCTION connection4dataOffset( const CONNECTION4 *, const unsigned int ) ;
   int S4FUNCTION connection4receive( CONNECTION4 * ) ;
   int S4FUNCTION connection4send( CONNECTION4 * ) ;
#else
   int connection4assign( CONNECTION4 *, const int, const long, const long ) ;
   S4CONST char *connection4dataOffset( const CONNECTION4 *, const unsigned int ) ;
   int connection4receive( CONNECTION4 * ) ;
   int connection4send( CONNECTION4 * ) ;
#endif

#ifndef S4SERVER
   int connection4repeat( CONNECTION4 *, const int, const int, const int, DATA4 * ) ;
#endif
#ifdef E4PARM_LOW
   int  connection4type( const CONNECTION4 * ) ;
   long connection4errCode2( const CONNECTION4 * ) ;
   S4EXPORT int connection4status( const CONNECTION4 * ) ;
   int  connection4setLen( CONNECTION4 *, const long int ) ;
   void  connection4setRequestLockedInfo( CONNECTION4 *, int ) ;
   long connection4clientId( const CONNECTION4 * ) ;
   S4CONST char *connection4data( const CONNECTION4 * ) ;
   int    connection4free( CONNECTION4 * ) ;
   long   connection4id( const CONNECTION4 * ) ;
   int    connection4didUnlock( const CONNECTION4 * ) ;
   int    connection4readLock( const CONNECTION4 * ) ;
   int    connection4unlockAuto( const CONNECTION4 * ) ;
   long connection4serverId( const CONNECTION4 * ) ;
   long int  connection4len( const CONNECTION4 * ) ;
   int    socket4free( SOCKET4 * ) ;
   int    socket4init( SOCKET4 *, CODE4 *, const char *, const char * ) ;
   #ifdef S4SERVER
      int    socket4shutdownAdvertising( SOCKET4 * ) ;
   #endif
   void packet4setDidUnlock( PACKET4 *, const int ) ;
   int packet4requestLockedInfo( const PACKET4 * ) ;
#else
   #define connection4type( c ) ( packet4type( (c)->message->packet ) )
   #define connection4errCode2( c ) ( packet4errCode2( (c)->message->packet ) )
   #define connection4status( c ) ( packet4status( (c)->message->packet ) )
   #define connection4setLen( c, l ) ( packet4setLen( (c)->message->packet, (l) ) )
   #define connection4setRequestLockedInfo( c, v ) ( packet4setRequestLockedInfo( (c)->message->packet, (v) ) )
   #define connection4clientId( c ) ( ((c)->message == 0) ? 0 : packet4clientId( (c)->message->packet ) )
   #define connection4data( c ) ( connection4dataOffset( (c), 0 ) )
   #define connection4free( c ) ( ((c) == 0 ) ? 0 : ( mem4free( (c)->cb->connectionMemory, c ), 0 ) )
   #define connection4id( c ) ( ((c) == 0 ) ? 0 : ( connection4netId( (c)->net ) ) )
   #define connection4didUnlock( c ) ( packet4didUnlock( (c)->message->packet ) )
   #define connection4readLock( c ) ( packet4readLock( (c)->message->packet ) )
   #define connection4unlockAuto( c ) ( packet4unlockAuto( (c)->message->packet ) )
   #define connection4serverId( c ) ( packet4serverId( (c)->message->packet ) )
   #define connection4len( c ) ( packet4len( (c)->message->packet ) - (c)->adjustForLocked )
   #define socket4free( s ) ( ( (s) == 0 ) ? 0 : ( u4free( s ), 0 ) )
   #ifdef S4SERVER
      #define socket4init( s, c4, sn, pi ) ( ((s)->cb = (c4)), ( socket4netInitServer( (s)->net, (sn), (pi) ) ) )
      #define socket4shutdownAdvertising( s ) ( socket4netShutdownAdvertising( (s)->net ) )
   #else
      #define socket4init( s, c4, sn, pi ) ( ( (s)->cb = (c4) ), 0 )
   #endif
   #define packet4len( p ) ( (p)->dataLen )
   #define packet4setLen( p, l ) ( ( (p)->dataLen = (l) ), 0 )
   #define packet4setStatus( p, s ) ( ( (p)->status = (s) ) )
   #define packet4setType( p, t ) ( ( (p)->type = (t) ) )
   #define packet4status( p ) ( (p)->status )
   #define packet4setErrCode2( p, e ) ( ((p)->errCode2 = (e)), 0 )
   #define packet4errCode2( p ) ( (p)->errCode2 )
   #define packet4type( p ) ( (p)->type )
   #define packet4serverId( p ) ( (p)->serverDataId )
   #define packet4clientId( p ) ( (p)->clientDataId )
   #define packet4readLock( p ) ( (p)->readLock )
   #define packet4didUnlock( p ) ( (p)->didUnlock )
   #define packet4setRequestLockedInfo( p, r )  ( ((p)->requestLockedInfo = (r)) )
   #define packet4unlockAuto( p ) ( (p)->unlockAuto )
   #define packet4setClientId( p, i ) ( ((p)->clientDataId = (i)) )
   #define packet4setServerId( p, i ) ( ((p)->serverDataId = (i)) )
   #define packet4setReadLock( p, r ) ( ((p)->readLock = (r)) )
   #define packet4requestLockedInfo( p ) ( (p)->requestLockedInfo )
   #define packet4setDidUnlock( p, v ) ( ((p)->didUnlock = (v)) )
   #define packet4setUnlockAuto( p, v ) ( ((p)->unlockAuto = (v)) )
   #define packet4partNo( p ) ( (p)->partNo )
   #define packet4numParts( p ) ( (p)->numParts )
#endif

#ifdef E4FILE_LINE
   #define connection4error( a, b, c, d ) ( s4fileName = __FILE__ , s4lineNo = __LINE__ , connection4errorDescribeExecute( a, b, c, d, 0, 0, 0 ) )
   #define connection4errorDescribe( a, b, c, d, e, f, g ) ( s4fileName = __FILE__ , s4lineNo = __LINE__ , connection4errorDescribeExecute( a, b, c, d, e, f, g ) )
#else
   #define connection4error( a, b, c, d ) ( connection4errorDescribeExecute( a, b, c, d, 0, 0, 0 ) )
   #define connection4errorDescribe( a, b, c, d, e, f, g ) ( connection4errorDescribeExecute( a, b, c, d, e, f, g ) )
#endif

CONNECTION4 * socket4receiveMessage( SOCKET4 * ) ;
SOCKET4 * socket4alloc( CODE4 * ) ;
int    socket4connect( SOCKET4 *, const char *, const char * ) ;
CODE4 S4PTR *S4FUNCTION socket4codeBase( SOCKET4 S4PTR * ) ;
int    socket4initUndo( SOCKET4 * ) ;
MESSAGE4 *socket4receive( SOCKET4 * ) ;

struct SOCKET4NETSt S4PTR * S4FUNCTION socket4netAlloc( SOCKET4 S4PTR * ) ;
int    S4FUNCTION socket4netInitUndo( struct SOCKET4NETSt S4PTR * ) ;
int    S4FUNCTION socket4netFree( struct SOCKET4NETSt S4PTR * ) ;
void   S4FUNCTION socket4netYield( const struct SOCKET4NETSt S4PTR * ) ;

struct CONNECTION4NETSt S4PTR * S4FUNCTION connection4netAlloc( struct SOCKET4NETSt S4PTR * ) ;
int    S4FUNCTION connection4netDisconnect( struct CONNECTION4NETSt S4PTR * ) ;
int    S4FUNCTION connection4netFree( struct CONNECTION4NETSt S4PTR * ) ;
CONNECTION4ID S4FUNCTION connection4netId( const struct CONNECTION4NETSt S4PTR * ) ;
int    S4FUNCTION connection4netInit( struct CONNECTION4NETSt S4PTR *, struct SOCKET4NETSt S4PTR * ) ;
int    S4FUNCTION connection4netInitUndo( struct CONNECTION4NETSt S4PTR * ) ;
int    S4FUNCTION connection4netSend( struct CONNECTION4NETSt S4PTR *, const MESSAGE4 S4PTR * ) ;
CONNECTION4ID S4FUNCTION connection4netDestId( const struct CONNECTION4NETSt S4PTR * ) ;
S4CONST unsigned short S4FUNCTION connection4netMessageLen( struct CONNECTION4NETSt S4PTR * ) ;
MESSAGE4 S4PTR * S4FUNCTION socket4netReceive( struct SOCKET4NETSt S4PTR * ) ;
S4CONST int connection4netMessageSendLen( struct CONNECTION4NETSt * ) ;
char *connection4netMessageSendData( struct CONNECTION4NETSt * ) ;
int packet4copy( PACKET4 *, PACKET4 *, unsigned int ) ;
#define packet4setDidUnlockData( p, v ) ( ((p)->didUnlockData = (v)) )
S4EXPORT struct MESSAGE4St S4PTR *S4FUNCTION message4alloc( CODE4 S4PTR *, unsigned int ) ;
S4EXPORT void S4FUNCTION message4free( CODE4 S4PTR *, struct MESSAGE4St S4PTR * ) ;
void message4release( CODE4 * ) ;
/* cannot be inline due to DLL CODE4 structure potential mismatches */

#ifdef S4DISTRIBUTED
   CONNECTION4ID S4FUNCTION connection4netSourceId( const struct CONNECTION4NETSt S4PTR * ) ;
#endif

#ifdef S4SERVER
   char  *S4FUNCTION connection4netUserId( struct CONNECTION4NETSt S4PTR * ) ;
   int socket4verifyConnections( SOCKET4 * ) ;
   int socket4connected( SOCKET4 * ) ;
   int S4FUNCTION socket4netShutdownAdvertising( struct SOCKET4NETSt S4PTR * ) ;
   int S4FUNCTION connection4netDisconnected( struct CONNECTION4NETSt S4PTR * ) ;
   int S4FUNCTION socket4netConnected( struct SOCKET4NETSt S4PTR * ) ;
   int S4FUNCTION socket4netConnectClient( struct SOCKET4NETSt S4PTR *, CONNECTION4 S4PTR *, struct CONNECTION4NETSt S4PTR * ) ;
   int S4FUNCTION socket4netInitServer( struct SOCKET4NETSt S4PTR *, const char *, const char * ) ;
#endif
#ifndef S4SERVER
   int    S4FUNCTION socket4netConnectServer( struct SOCKET4NETSt S4PTR *, struct CONNECTION4NETSt S4PTR *, const char S4PTR *, const char S4PTR * ) ;
#endif

#ifdef __cplusplus
   }
#endif

#endif  /* S4OFF_COMMUNICATIONS */