From 73c0ae48a607d1d3255f6660c9d8adc02a58e394 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 Nov 2023 18:09:08 +0800 Subject: [PATCH] buban104.cpp --- common.h | 5 ++- commport.cpp | 124 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 123 insertions(+), 6 deletions(-) diff --git a/common.h b/common.h index b43f523..315dfd4 100644 --- a/common.h +++ b/common.h @@ -366,8 +366,8 @@ typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR; // wen 2005.10.08 解决malloc分配内存不能释放的问题 #define MIN_MALLOC_SIZE 200 // malloc分配内存的最小尺寸 -#define MAX_NO_WRITE_NUM 6000 // 网络最大不可写尺寸 -#define MAX_BUFUNIT_NUM 100 // 缓冲区单元最大数量 +#define MAX_NO_WRITE_NUM 600000 // 网络最大不可写尺寸 +#define MAX_BUFUNIT_NUM 1000 // 缓冲区单元最大数量 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // 增加fend功能的宏定义 @@ -673,6 +673,7 @@ typedef struct DATA_BUF RecvBuf; // 接收数据缓冲区 struct WR_DATA *WriteData; // 下行数据缓冲区 + int iWriteDataNo; // 下行数据缓冲区序号 //******************** 统计信息 **************************** u_long MsgNum; // 端口信息计数 u_long LostSyncCnt; // 端口失步次数 diff --git a/commport.cpp b/commport.cpp index 00dfae7..8374177 100644 --- a/commport.cpp +++ b/commport.cpp @@ -2549,6 +2549,122 @@ int ProvHaveSoeData(int provport) return SioParam[provport].m_psBaoHu->ProvSoeBuf.iSoeNum; } +//鎻掑埌鏈鍚庝竴涓粨鐐逛箣鍚 +int AddNodeEx(int commid, char *buf, int len) +{ + int iMallocSize; + struct WR_DATA *wdata; + + // wen 2004.12.28 鍋滄绯荤粺鍙戦佹暟鎹 + //if (StopSend) + //{ + // return 0; + //} + + // wen 2005.07.02 濡傛灉绔彛鏈墦寮锛屼笉杩涜缂撳啿 + if (!ShmGetPortFlag(commid, FLAG_OPEN)) + { + return 0; + } + + // 澧炲姞缂撳啿鍖哄閲忓ぇ灏忕殑闄愬埗(???) + if (SioParam[commid].iWriteDataNo > MAX_BUFUNIT_NUM) + { + return 0; + } + + if (len <= 0) + { + // wen 2004.12.03 + printf("TIP_: AddNode (commid = %d) buf is empty or invalid(len=%d)\n", commid, len); + return 0; + } + + /*if (WatchPort == commid) + { + FillUdpSetBuf(commid, SDS_SIO_SEND_DATA, buf, len); + SetUdpSend(); + }*/ + + iMallocSize = sizeof(struct WR_DATA) + len; + if (MIN_MALLOC_SIZE > iMallocSize) + { + iMallocSize = MIN_MALLOC_SIZE; + } + + if (!SioParam[commid].WriteData) //empty before insert + { + SioParam[commid].WriteData = (struct WR_DATA*)HEAP_MALLOC(iMallocSize); + if (!SioParam[commid].WriteData) + { + // wen 2004.12.03 + printf("TIP_(): AddNode (commid = %d) memory malloc error1(len=%d, totallen=%d)\n", + commid, len, iMallocSize); + return 0; + } + + SioParam[commid].WriteData->Next = NULL; + + memmove(SioParam[commid].WriteData->MsgData, buf, len); + + SioParam[commid].WriteData->MsgLen = len; + SioParam[commid].WriteData->PLen = 0; + SioParam[commid].SendCharNum += len; + + SioParam[commid].iWriteDataNo++; + + // test + //if(commid == 16) + //{ + // printf("TIP_(%04d): AddNode(commid=%d, len=%d), No=%d, MallocSize=%d\n", + // getpid(), commid, len, SioParam[commid].iWriteDataNo, iMallocSize); + //} + + return len; + } + + wdata = SioParam[commid].WriteData; //old link head + while (wdata->Next != NULL) + { + wdata = wdata->Next; + }; + + wdata->Next = (struct WR_DATA*)HEAP_MALLOC(iMallocSize); + if (!wdata->Next) + { + // wen 2004.12.03 + printf("TIP_(): AddNode (commid = %d) memory malloc error3(len=%d, totallen=%d)\n", + commid, len, iMallocSize); + return 0; + } + + wdata->Next->Next = NULL; + + //memmove(wdata->Next->MsgData, buf, len); + memcpy(wdata->Next->MsgData, buf, len); + + wdata->Next->MsgLen = len; + wdata->Next->PLen = 0; + SioParam[commid].SendCharNum += len; + + SioParam[commid].iWriteDataNo++; + + // test + //if(commid >= 16) + //{ + // printf("TIP_(%04d): AddNode(commid=%d, len=%d), No=%d, MallocSize=%d\n", + // getpid(), commid, len, SioParam[commid].iWriteDataNo, iMallocSize); + //} + + return len; +} + +int AddNode(int commid, char *buf, int len) +{ + // 淇敼鍐呭瓨鍒嗛厤绛栫暐 + return AddNodeEx(commid, buf, len); +} + //******************************************************************** //* 鍙戦佹暟鎹嚱鏁 * //*鍙傛暟锛 int commid : 绔彛鍙 * @@ -2566,13 +2682,13 @@ void SendDataToPort(int commid, char *buf, int len) } #endif -#ifdef OS_LINUX +//#ifdef OS_LINUX AddNode(commid, (char *)buf, len); -#else +//#else // FillAndSendCmd(0, commid, SDS_SIO_SEND_DATA, (u_char*)buf, len); // wen 2004.12.21 鍙戦佽鏁板凡缁忓湪鍙戦佹椂鍋氫簡璁$畻 - SioParam[commid].SendCharNum += len; -#endif +// SioParam[commid].SendCharNum += len; +//#endif } //********************************************************************