.ad 8
.bm 8
.fm 4
.bt $Copyright by   Software AG, 1993$$Page %$
.tm 12
.hm 6
.hs 3
.tt 1 $NME$Project Distributed Database System$vos00cmc$
.tt 2 $$$
.tt 3 $R.Roedling$RTE communication include module$1997-02-07$
***********************************************************
.nf


    ========== licence begin LGPL
    Copyright (C) 2002 SAP AG

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    ========== licence end

.fo
.nf
.sp
Module  : RTE_communication_include_module
=========
.sp
Purpose :
.CM *-END-* purpose -------------------------------------
.sp
.cp 3
Define  :

.CM *-END-* define --------------------------------------
.sp;.cp 3
Use     :

.CM *-END-* use -----------------------------------------
.sp;.cp 3
Synonym :

.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  : R.Roedling
.sp
.cp 3
Created : 1992-10-10
.sp
.cp 3
Version : 1994-01-27
.sp
.cp 3
Release :  6.2 	 Date : 1997-02-07
.br
.sp
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Specification:

.CM *-END-* specification -------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Description:

.CM *-END-* description ---------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.nf
.oc _/1
Structure:

.CM *-END-* structure -----------------------------------
.sp 2
**********************************************************
.sp
.cp 10
.nf
.oc _/1
.CM -lll-
Code    :
/*PRETTY*/
//
// +---------------------------------------------------------------+
// |   DEFINES                                                     |
// +---------------------------------------------------------------+
//
#define NODESEPARATORLIST               "!#:"
#define MAXPACKET                       100


#define MAXCONNECTIONS                  2000
#define MIN_COMSEG_SIZE                 8192
#define RETRYCOUNT                      3
#define LOCAL_CONN_RETRY_SLEEP_TIME     3            // - sec
#define LOCAL_CONN_TIMEOUT              120          // - sec
#define SOCKET_CONN_TIMEOUT             180          // - sec
#define MIN_COMMAND_TIMEOUT             30           // - sec
#define MIN_UNREL_CONN_TEST             120          // - sec

#define CS_IN_USE                       0x1
#define CS_CONN_ESTABLISHED             0x2
#define CS_CONN_RELEASED                0x4

#define PROT_UNDEF                      0
#define PROT_SHM                        1
#define PROT_SOCKET                     2
#define PROT_CMS                        3
#define PROT_PASREM                     4
#define PROT_PASLCL                     5
#define PROT_NETWRK                     6
#define NPROTOCOLS                      7

/*
 *  protocol_id
 */
#define RSQL_RTE_PROT_UNDEF             0
#define RSQL_RTE_PROT_VTAM              1
#define RSQL_RTE_PROT_CMX               2
#define RSQL_RTE_PROT_TCP               3
#define RSQL_RTE_PROT_DECNET            4

/*
 *  mess_class  ( old )
 */
#define RSQL_RTE_REQUEST_CONN           1
#define RSQL_RTE_REPLY_CONN             2
#define RSQL_RTE_REQUEST_USER           3
#define RSQL_RTE_REPLY_USER             4
#define RSQL_RTE_OPEN_SESSION           16
#define RSQL_RTE_CLOSE_SESSION          17
#define RSQL_RTE_SEND_DATA              18
#define RSQL_RTE_OPEN_SESSION_REPLY     19
#define RSQL_RTE_CANCEL                 31
#define RSQL_RTE_DUMP                   32
#define RSQL_RTE_ADDRESS_REQUEST        41
#define RSQL_RTE_ADDRESS_REPLY          42

/*
 *  mess_class  ( new )
 */
#define RSQL_INFO_REQUEST               51
#define RSQL_INFO_REPLY                 52

#define RSQL_USER_CONN_REQUEST          61
#define RSQL_USER_CONN_REPLY            62
#define RSQL_USER_DATA_REQUEST          63
#define RSQL_USER_DATA_REPLY            64
#define RSQL_USER_CANCEL_REQUEST        65
#define RSQL_USER_RELEASE_REQUEST       66

#define RSQL_KERN_CONN_REQUEST          71
#define RSQL_KERN_CONN_REPLY            72
#define RSQL_KERN_DATA_REQUEST          73
#define RSQL_KERN_DATA_REPLY            74
#define RSQL_KERN_RELEASE_REQUEST       76

#define RSQL_DUMP_REQUEST               81

#define RSQL_CTRL_CONN_REQUEST		91
#define RSQL_CTRL_CONN_REPLY		92


/*
 *  rte flags
 */
#define RSQL_NORMAL                     0


/*
 *  ostype
 */
#define RSQL_MVSBATCH_OS                0
#define RSQL_MVSCICS_OS                 1
#define RSQL_MVSTSO_OS                  2
#define RSQL_VSEBATCH_OS                3
#define RSQL_VSECICS_OS                 4
#define RSQL_VMSP_OS                    5
#define RSQL_VMCICS_OS                  6
#define RSQL_VMS_OS                     7
#define RSQL_MSDOS_OS                   8
#define RSQL_OS2_OS                     9
#define RSQL_BS2000_OS                  10
#define RSQL_UNIX_OS                    11
#define RSQL_SINIX_OS                   12
#define RSQL_WIN32                      13

#if defined (_WIN32)
 #define RSQL_OS_TYPE   RSQL_OS2_OS
#else
 #define RSQL_OS_TYPE   RSQL_WIN32
#endif


/*
 *  local request types
 */
#define SQL_RTE_CONNECT                 1
#define SQL_RTE_CANCEL                  2

#define SQL_RTE_DUMP                    15   // -- max.= 15

/*
 *  communication segment version
 */
#define COMM_SEG_VERSION                1

/*
 *  States for DB-Communication
 */
#define CON_INITIALIZED                 1
#define CON_CONNECTED                   2
#define CON_REQUESTED                   3
#define CON_RECEIVED                    4
#define CON_CANCELLED                   5
#define CON_RELEASED                    6

//
// +---------------------------------------------------------------+
// |   TYPEDEFS AND STRUCTS                                        |
// +---------------------------------------------------------------+
//

//
// --- unions for mapping checks
//
union map_check_i2_b2
  {
  INT2                            int2;
  C2                              c2;
  };

union map_check_i4_b4
  {
  INT4                            int4;
  C4                              c4;
  };

//
// -- RTE HEADER for communication packets.
//
typedef struct rte_header_record
  {
  INT4                            ActSendLen;
  INT1                            ProtocolID;
  INT1                            MessClass;
  INT1                            RTEFlags;
  INT1                            ResidualPackets;
  INT4                            SenderRef;
  INT4                            ReceiverRef;
  INT2                            RTEReturnCode;
  INT2                            Filler;
  INT4                            MaxSendLen;
  } RTE_HEADER_REC;            // - 8 byte alignment!

typedef RTE_HEADER_REC       *PRTE_HEADER_REC;

#define RTE_HEADER_SIZE      (sizeof(RTE_HEADER_REC))


typedef struct comm_packet_record
  {
  RTE_HEADER_REC                  RTEHeader;
  CHAR                            pDataPart[1];
  } COMM_PACKET_REC;

typedef COMM_PACKET_REC      *PCOMM_PACKET_REC;


/*
 * - Structure of the remote communication record
 *
 *    Remote connect:
 *
 *      +------------------------------------+
 *      |     rte_header_record              |
 *      +------------------------------------+
 *      |     rte_connect_packet_record      |
 *      +------------------------------------+
 *
 *    Remote transfer:
 *
 *      +------------------------------------+
 *      |     comm_packet_record             |
 *      +---------------------------\--------+
 *                                   \
 *                                  +-\----------------------------------+
 *                                  |  \  rte_header_record +            |
 *                                  |     sql_packet (data)              |
 *                                  +------------------------------------+
 *
 *
 */

// --- Record is used for REMOTE connects only
typedef struct rte_connect_packet_record
  {
  C2                              sMessCode;
  INT2                            ConnectLength;
  INT1                            ServiceType;
  INT1                            OSType;
  INT1                            Filler1;
  INT1                            Filler2;
  INT4                            MaxSegmentSize;
  INT4                            MaxDataLen;
  INT4                            PacketSize;
  INT4                            MinReplySize;
  C8                              ReceiverServerDB;
  C8                              SenderServerDB;
  C256                            VarPart;
  } RTE_CONNECT_PACKET_REC;

typedef RTE_CONNECT_PACKET_REC   *PRTE_CONNECT_PACKET_REC;


//
// ---  Local connect request (via message queue to REQUESTOR thread)
//
//
#if defined(_WIN32)

typedef struct comm_request_record
  {
  ULONG                           ulReqType;
  ULONG                           ulServerRef;
  ULONG                           ulCSSize;
  IPC_BASE_OBJ_NAME               szClientObjName;
  } COMM_REQUEST_REC;

#else

typedef struct comm_request_record  // - must not be greater than 32 Bit
  {
  INT                             bf28ServerRef: 28,
                                  bf4ReqType   : 4;
  } COMM_REQUEST_REC;

#endif

/*
 *  - Structure of the communication segment
 *
 *       +------------------------------------+
 *    +--|     comm_seg_header_record         |
 *    |  +------------------------------------+
 *    +->|     comm_seg_offset_record         |--+
 *       +------------------------------------+  |
 *       | 1.  comm_packet_record             |<-+
 *       |     (request)                      |  |
 *       |  --------------------------------  |  |
 *       |     comm_packet_record             |  |
 *       |     (receive)                      |  |
 *       +------------------------------------+  |
 *       .                                    .  .
 *       .                                    .  .
 *       +------------------------------------+  |
 *       | n.  comm_packet_record             |<-+
 *       |     (request)         \            |
 *       |  ----------------------\---------  |
 *       |     comm_packet_record  \          |
 *       |     (receive)            \         |
 *       +---------------------------\--------+
 *                                    \
 *      n <= MAX_SQL_PACKETS           \
 *                                +-----+------------------------------+
 *                                |     rte_header_record +            |
 *                                |     sql_packet (data)              |
 *                                +------------------------------------+
 *
 *
 *    The usage of ulClientFlag and ulServerFlag is as follows:
 *
 *
 *                             c s
 *                     init->  -+-
 *                             0 0
 *                                \
 *                          sqlaconnect,vconnect
 *                                /
 *                 c s         c s
 *                 -+-         -+-
 *                 0 2         0 2
 *                /   \       /
 *      sqlareceive   sqlarequest,sqlarelease
 *              /       \   /
 *           c s         c s
 *           -+-         -+-          0: no event
 *           2 1         1 2          1: event pending
 *              \       /             2: destination has received the event
 *           vreply   vreceive
 *                \   /
 *                 c s
 *                 -+-
 *                 2 0
 *
 *
 *
 *    if the communication is crashing:
 *
 *      kernel:   c s         client:   c s
 *                -+-                   -+-
 *                ? 1                   1 ?
 *
 *
 */

// --- local communication segment header

typedef struct comm_seg_header_record
  {
  ULONG                           ulCSSize;
  INT                             iCSVersion;
  ULONG                           ulPacketCnt;
  ULONG                           ulPacketSize;
  ULONG                           ulMaxDataLen;
  ULONG                           ulMinReplySize;
  ULONG                           ulOffsetRecord;
  ULONG                           ulCurrentPacket;
  PID                             pidClientOrPeerPID;
  PID                             pidServerPID;
  ULONG                           ulClientOrPeerRef;
  ULONG                           ulServerRef;
  ULONG                           ulClientCommState;
  ULONG                           ulServerCommState;
  ULONG                           ulClientFlag;
  ULONG                           ulServerFlag;
  ULONG                           ulServiceType;

  // -- operating system specific part
  ULONG                           ulCommFlagNo;
  ULONG                           ulSemaFlagNo;

  SQL_NODEIDC                     szClientOrPeerNode; // comm. xserver/kernel only

  #if defined(_WIN32)
   PID                            pidLocalPID;
   CHAR                           szSemPath[ 40 ];
   IPC_BASE_OBJ_NAME              szSemName;
  #else
   HEV                            hevClientSem;
   HEV                            hevServerSem;
  #endif

  SQL_DBNAMEC                     szClientOrPeerServerDB; // distrib. only
  SQL_NODEIDC                     szServerNode;           // distrib. only
  SQL_DBNAMEC                     szServerDB;             // distrib. only

  } COMM_SEG_HEADER_REC;

typedef COMM_SEG_HEADER_REC       *PCOMM_SEG_HEADER_REC;

#define COMM_SEG_HEADER_SIZE  (sizeof(COMM_SEG_HEADER_REC))

// --- offsets to the communication packets
typedef struct comm_seg_offset_record
  {
  ULONG                           ulOffsetCnt;
  ULONG                           ulOffset[MAX_SQL_PACKETS];
  } COMM_SEG_OFFSET_REC;

typedef COMM_SEG_OFFSET_REC       *PCOMM_SEG_OFFSET_REC;

#define COMM_OFFSET_LIST_SIZE     (sizeof(COMM_SEG_OFFSET_REC))


//
// --- OLD RTE HEADER  and SQL packets.
//

#define OLD_RTE_HEADER_PART                                \
        INT2                            ActSendLen;        \
        INT2                            MaxSendLen;        \
        INT1                            ProtocolID;        \
        INT1                            MessClass;         \
        INT1                            RTEFlags;          \
        INT1                            ResidualPackets;   \
        INT4                            SenderRefID;       \
        INT4                            ReceiverRefID;     \
        INT2                            RTEReturnCode;     \
        INT2                            Filler;


typedef struct old_rte_header_record
  {
  OLD_RTE_HEADER_PART
  } OLD_RTE_HEADER_REC;

typedef OLD_RTE_HEADER_REC       *POLD_RTE_HEADER_REC;

#define OLD_RTE_HEADER_SIZE     (sizeof(OLD_RTE_HEADER_REC))


typedef struct old_sql_packet_record
  {
  OLD_RTE_HEADER_PART

  C2                              mess_code;
  INT2                            mess_type;
  C8                              senderid;
  INT2                            part1_length;
  INT2                            part2_length;
  INT2                            return_code;
  INT2                            error_code;
  char                            var_part [ 8240 ];
  } OLD_SQL_PACKET_REC;

typedef OLD_SQL_PACKET_REC      *POLD_SQL_PACKET_REC;

typedef struct old_shm_info_record
  {
  SQL_DBNAMEC                     szServerDB;
  ULONG                           ulKernelRef;
  ULONG                           ulApplicRef;
  SQL_SERVICE                     ServiceType;

  HANDLE                          hCommHandle;
  HEV                             hevApplicSem;
  HEV                             hevUKTSem;
  struct old_comm_segment_record  *pCommSeg;
  HANDLE                          hCommSeg;      // - NT
  IPC_BASE_OBJ_NAME               szUKTSemName;  // - NT
  } OLD_SHM_INFO_REC;

typedef OLD_SHM_INFO_REC          *POLD_SHM_INFO_REC;

.CM *-END-* code ----------------------------------------
.SP 2
***********************************************************
.PA
