buban104.cpp

main
unknown 2 years ago
parent a5efd0b593
commit 73c0ae48a6

@ -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; // 端口失步次数

@ -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
}
//********************************************************************

Loading…
Cancel
Save