modbusconnection.h

来自「Convert Interface on a embedded System」· C头文件 代码 · 共 53 行

H
53
字号
#pragma once

#include <winsock2.h>

// Arbitrary max number of concurrent client connections
#define MAX_CLIENTS 4

// "Connection Info" structure
typedef struct tagCONNINFO
{
  SOCKET socket;
  CHAR   szAddr[sizeof "255.255.255.255:65535"]; // client's IP address
  DWORD  dwLastTime;	// time of last transaction with client
  DWORD  dwRcvd;		// total number of bytes received
  DWORD  dwSent;		// total number of bytes sent
  DWORD  dwGood;		// total number of accepted client requests
  DWORD  dwBad;			// total number of rejected client requests
} CONNINFO, *LPCONNINFO;

// CONNECTION structure
typedef struct tagCONNECTION
{
  CRITICAL_SECTION cs;	// Critical Section for access control to CONNINFO
  CONNINFO ci;			// 'Connection Info' for the connection
  HANDLE hStop;			// 'Stop' event object for the connection
} CONNECTION, *LPCONNECTION;

class CModbusConnection
{
public:
	CModbusConnection(void);
	~CModbusConnection(void);

	static void CreateConnections( void );
	static void DeleteConnections( void );
	static void EnableConnections( void );
	static void DisableConnections( void );
	static HANDLE OpenConnection( SOCKET socket, LPSOCKADDR_IN lpSocketAddr );
	static void CloseConnection( HANDLE hConn );
	static void GetConnInfo( INT idConn, LPCONNINFO lpInfo );
	static void IncrementConnCounters( HANDLE hConn, BOOL fGoodRequest, WORD wRcvd, WORD wSent );
	static SOCKET GetConnSocket( HANDLE hConn );
	static HANDLE GetConnStopEvent( HANDLE hConn );

	// Array of client connections
	static CONNECTION connections[MAX_CLIENTS];

	// Count of free (closed) client connections
	static HANDLE hFreeConnections;


};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?