📄 haudp.h
字号:
/******************************************************************* * * * This file is a part of the eXtremeDB-HA Application Framework * * Copyright (c) 2001-2006 McObject LLC * * All Rights Reserved * * * *******************************************************************//** *\file haudp.h * ++ * * PROJECT: eXtremeDB(tm) (c) 2003 McObject LLC * * SUBSYSTEM: HA support * * MODULE: haudp.h * * ABSTRACT: definitions of UDP sockets IPC * * * VERSION: 1.0 * * HISTORY: * 1.0- 1 SS 9-Jul-2003 Created it was * * -- */#ifndef _UDP_H_#define _UDP_H_#ifdef CFG_UDP_SOCKET_CHANNEL#define INCLUDE_SOCKETS /**< includes socket.h from platform include files */#include "platform.h"#include "mco.h"#include "mcoHA.h"#ifdef __cplusplusextern "C" { #endif/* change this as you please *//********************************************************************** definitions of HA endpoints **********************************************************************/#ifdef _DOC_ // for docuventation/** ***********************************************************************\n * Transport layer. Used by an application for providing of communication \n * channels, guaranteed data transfer. Can be used by an application for \n * the implementation of it's own communications channels. \n * Some details of a communication channel are accessible to application \n * \n * Remark: \n * Transfer protocols usually use frame descriptors (headers) for data \n * transfer control. \n * Each created UDP channel MUST have a framebuffer for \n * data transfer. \n * \n * The framebuffer has the following format: \n * \n * \n * -------------------- <- pointer to framebuffer \n * | frame header | \n * |------------------| <- (pointer to framebuffer)+(header length) \n * | message body | \n * -------------------- \n * \n * Application MUST create it's own framebuffers and attach them to each \n * created channel with the function nw_attach_buffer() \n * \n * Mco HA uses the one and only internal static buffer for all master's \n * channels or for replica's channel. \n ****************************************************************************/#define UDP_TRANSPORT_PROTOCOL // in order to place this description to doc#endif/** * Connection parameters for IP. * For master: port number * For replica: master address: "hostname:port" * * ATTENTION! In this version of haframework the last 2 symbols of master's * logical name (port number for TCP and UDP or pipename for pipes) MUST ALWAYS BE * "00". These symbols indicate the HA instance of master and are to be replaced * by the index of current HA instance. */#define CHANNEL_NAME "UDP/IP"#define nw_MasterName "10000" /**< for MASTER HA instance *///#define nw_ConnectionString "127.0.0.1:10000" /**< for REPLICA, addres of the master to connect *///#define nw_ConnectionString "192.168.255.1:10000"//#define nw_ConnectionString "192.168.1.210:10000"//#define nw_ConnectionString "87.248.173.239:10000"#define nw_DefaultPort "10000"/********************************************************************** definitions of HA timeouts **********************************************************************//** Master/replica timeouts. These parameters * are passed to the mco_HA_attach_replica() & mco_HA_attach_master() */ #define TM_ATTACH_REPLICA 1000*5 /**< time to establish the initial connection and the initial */ /**< databases synchronization */#define TM_DETACH_REPLICA 1000*5 /**< time to disconnect a replica from the master */#define TM_MASTER_COMMIT 1000*3 /**< total commit time (master) */#define TM_REPLICA_COMMIT 1000*3 /**< total database update time at the replica side */ /**< "replica commit" */#define TM_WAIT_FOR_DATA 1000*6 /**< amount of time a replica waits for the next transaction. */#define TM_SYNCH 1000*8 /**< amount of time a replica waits for the synchronization of the 2-nd phase of commit *///#define RECONNECTION_DELAY 300 /**< pause before the next attempt to connect after the connection fails */#define TM_CONNECTION_TIMEOUT 1000*5 /**< connection timeout from peplica side */#define TM_ACCEPT_TIMEOUT 1000*60 /**< accepting connection timeout from master side */#define TM_INFINITE ((timer_unit)-1) ///< also used if the parameter is irrelevant/* local TCP address:port for the cancel point */#define CANCELPOINT_ADDR "127.0.0.1:9990" // for replica#define CANCELPOINT_PORT "9990" // for master/*************************************************************************** * Channel-Over-UDP frame definitions ***************************************************************************/#define MSG_BUFFER_SIZE 2048 ///< size of the message buffer#define RCV_ACK_TIME 2000 ///< sending acknowlege on received frame timeout#define SEND_ACK_TIME 2000 ///< receiving acknowlege timeout#define MAGIC 'HA' ///< "magic word" of a frame#define REPEAT_COUNT 3 ///< resend attempts counterenum UdpCtrlFields { FC_SEQN_OFFS = 4,// FC_TYPE_MASK = 0xf, FC_SEQN_MASK = 0xf<<FC_SEQN_OFFS};enum UdpFrameTypes { FT_CONNECT = 0, FT_CONN_ACK, FT_ACCEPT, FT_ACC_ACK, FT_DATA, FT_DATA_ACK};/**\struct _udp_header_ Frame header is included to the body of frames of a Channel-Over-UDP for protocol purposes. */typedef struct _udp_header_ { uint2 magic; ///< data for checking integrity of a header uint1 ctrl; ///< frame control uint2 length; ///< length of data field of a frame}udp_header_t, *udp_header_h;/**\struct _msg_buf_ communication protocol over UDP message buffer. In this version of the communication protocol the same frame is shared among all communication channels. */typedef struct _msg_buf_ { udp_header_t hd; ///< frame header uint1 buffer[MSG_BUFFER_SIZE]; ///< data buffer}udp_msg_buf_t, *udp_msg_buf_h;/* internal channel-over-UDP messages *//**\struct udp_conn_msg_ channel-over-UDP connect message structure */typedef struct udp_conn_msg_ { udp_header_t hd; ///< space reserved for header struct _msg_ { uint2 index; uint2 port; ///< IO port number of connected host } body;}conn_msg_t, *conn_msg_h;/*************************************************************************** * Definitions of channel-over-UDP * ***************************************************************************/#ifndef _WIN32 typedef int SOCKET; typedef struct sockaddr_in SOCKADDR_IN; typedef struct sockaddr * LPSOCKADDR; typedef struct timeval TIMEVAL;#endif/** Maximum number of indexes in index map, which is used to allocate index of the free poft from the predefined area. NW_MAX_INDEXES is the number of indexes in the area */ #define NW_MAX_INDEXES 32 #define NW_MAX_NAMELENGTH 64 /**< max length of host name */ /* Connection timeout */ #define TM_CONN_MASTER 1000*1000 /**< master connection timeout */ #define MAX_DATALENGTH 32767/**\struct udp_nw_channel_ wrapper on mco_channel_t */ typedef struct udp_nw_channel_ { mco_channel_t mco_channel; /**< base mco channel descriptor */ uint2 status; /**< internal channel status */ SOCKET socket; /**< socket used by channel */#ifndef _WIN32 SOCKET cancel_socket; /**< socket for cancelling the IO */#endif SOCKADDR_IN sin; /**< socket address descripror of open channel */ void * db; /**< database handle */#ifdef _WIN32 HANDLE event; HANDLE event1;#endif uint2 port; /**< port used by channel */ int2 index; /**< internal channel index */ uint1 recv_seqn; /**< current sequence number of received frame */ uint1 send_seqn; /**< current sequence number of sent frame */ uint4 destaddr; /**< destination net address */ uint2 destport; /**< destination port */ uint4 inaddr; /**< source net address */ uint2 inport; /**< source port */ udp_header_t header; /**< area for receiving acknowlege frames */ udp_msg_buf_h pMsg; /**< pointer to a message buffer */ uint1 * pBuffer; /**< current pointer to data buffer */ uint2 currlen; /**< current buffer length */ uint2 bufsize; /**< data buffer size */ } nw_channel_t, *nw_channel_h;#ifdef __cplusplus }#endif //__cplusplus#endif //CFG_UDP_SOCKET_CHANNEL#endif //_UDP_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -