完成端口地址非法!!强烈求助!!!兄弟们,帮帮忙哦!

jasonM2008 2009-12-04 05:43:23
IOCP写的UDP!
在测试中,我不断的创建套接字,并在此套接字上发送和接收数据,会同时有很多个套接字在发送和接收数据!!!
运行一段时间之后,会弹出对话框报错:
Access violation at address 00000010 Read address of 00000010.
有时候还报错USER32.DLL中非法!!
郁闷了!!!!!
应该不是我代码中访问非法,应该是IOCP内部的报出来的,到底是怎么回事啊????
有哪位能给我说说,造成这个问题的可能原因也好!!!!!
我在网上也查了很多,但是都是说的TCP的IOCP,我在调试的过程中,查看日志,实在没看出来是什么问题,难道是overlapped结构的问题???我资源的释放是采取的引用计数方式来的,感觉应该没有什么问题!!!!!
有经验的,给我指点,谢谢!!!
...全文
231 31 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
31 条回复
切换为时间正序
请发表友善的回复…
发表回复
Rain7758 2010-01-22
  • 打赏
  • 举报
回复
1,UDP 其实没必要 IOCP
2,对于 IOCP 线程的理解,以及内存释放的控制,要求还是挺高的
楼主的错误就跟 0xC0000005 一样的,非法访问内存,检查初始化分配和释放吧
精锐掷矛手 2010-01-20
  • 打赏
  • 举报
回复
兄弟,我今天仿佛见到了阳光,我在一段代码上看到这样一段话:
/*
* Comments about bug in OnWrite() added 051227..
*
* This BUG was difficult to find. The bug was found after 6 hours of
* extensive debugging with several debug tools as Rational Test Suite,
* SoftICe , VC++ DEBUG, GLOWCODE, etc. I Found that in some rarely bizarre
* cases (when a client rapidly disconnect & reconnect, etc..) we get an
* access violation , etc. First of all we had one ReleaseClientContext to many
* in OnWrite() which caused access violation. Second when I remove it, I found
* that sometimes the client specific data (e.g. ClientContext) does not removed/relesed
* from memory, even if the client is disconnected. The reason in not
* intuitive and do not ask me how I figured it out. The problem occurs
* when an send is not ordered (see http://www.codeproject.com/internet/iocp_server_client.asp,
* section "3.6.2 The package reordering problem" for more information ) and
* we call the function GetNextSendBuffer(pContext,pOverlapBuff); (above) in Onwrite(..),
* to get the correct buffer to process. At exactly this point the remote client disconnects
* and this leads to the bug. Now I got tired of explaining this hassling stuff, so lets
* go to the business the fix is below..
这段解释和我的情况有点相同,不知和你的情况怎样?
精锐掷矛手 2010-01-19
  • 打赏
  • 举报
回复
这问题让人崩溃,我也遇到了这问题,出错时调用call stack看看。或者用BoundsChecker检查
tudoumayi 2010-01-19
  • 打赏
  • 举报
回复
学习
qd123bluesky 2010-01-14
  • 打赏
  • 举报
回复
帮顶
myaname 2010-01-14
  • 打赏
  • 举报
回复
enum ExpressionItemType
{
enumInvalid = 0, // 0:无效值
enumOperator = 1, // 1:operator 运算符项
enumIntParam = 2, // 2:intParam 参数项, 其值为int
enumSzParam = 3, // 3:szParam 参数项, 其值为字符串
//enumFunction = 9 // 9:function 参数项,
};


//Expression= " (%sUserType@ == %s1@) && (%sMSISDN@ > %s138@) && KDJ || %sabc@ "

struct/class ExpressionItem
{
int iItemType; // 1:operator, 2:intParam, 3:szParam, ... 9:function;

// 1:operator
int iOperType; // 标识运算符 (>, >=, <=, <, ==, =, ||, &&, !)
int iOperPriority; // 1, 2, 3, 11, 112, 113, 1113; <--每深入一层括号,优先级前面加1。

// 2:intParam (或运算过程中的 中间值)
int iParam;

// 3:szParam (或中间值)
char szParam[48]; // 表达式的字符串项: "MSISDN@",
};
myaname 2010-01-14
  • 打赏
  • 举报
回复
给自己看的,不麻烦大家了.
//---- 运算符标识名 ----- --------- 优先级 --------------- --- 说明 ---
const int Add = 10; const int ADDPriority = 4; // +
const int Subtract = 9; const int SubtractPriority = 4; // -
const int Less = 8; const int LessPriority = 3; // <
const int LessEqual = 7; const int LessEqualPriority = 3; // <=
const int Great = 6; const int GreatPriority = 3; // >
const int GreatEqual = 5; const int GreatEqualPriority = 3; // >=
const int EqualEqual = 4; const int EqualEqualPriority = 3; // ==
const int And = 3; const int AndPriority = 2; // &&
const int OR = 2; const int ORPriority = 2; // ||
const int Equal = 1; const int EqualPriority = 1; // =
//---------------------------------------------------------------------------


//---------------------------------------------------------------------------
// 运算符标识名 优先级 运算符
//---------------------------------------------------------------------------
const int Add = 10; const int ADDPriority = 4; // +
const int Subtract = 9; const int SubtractPriority = 4; // -
//---------------------------------------------------------------------------
const int Less = 8; const int LessPriority = 3; // <
const int LessEqual = 7; const int LessEqualPriority = 3; // <=
const int Great = 6; const int GreatPriority = 3; // >
const int GreatEqual = 5; const int GreatEqualPriority = 3; // >=
const int EqualEqual = 4; const int EqualEqualPriority = 3; // ==
//---------------------------------------------------------------------------
const int And = 3; const int AndPriority = 2; // &&
const int OR = 2; const int ORPriority = 2; // ||
//---------------------------------------------------------------------------
const int Equal = 1; const int EqualPriority = 1; // =
//---------------------------------------------------------------------------
myaname 2010-01-14
  • 打赏
  • 举报
回复
特殊情况,给自己看的, 不好意思

//---- 运算符标识名 ----- --------- 优先级 --------------- --- 说明 ---
const int Add = 10; const int ADDPriority = 4; // +
const int Subtract = 9; const int SubtractPriority = 4; // -
const int Less = 8; const int LessPriority = 3; // <
const int LessEqual = 7; const int LessEqualPriority = 3; // <=
const int Great = 6; const int GreatPriority = 3; // >
const int GreatEqual = 5; const int GreatEqualPriority = 3; // >=
const int EqualEqual = 4; const int EqualEqualPriority = 3; // ==
const int And = 3; const int AndPriority = 2; // &&
const int OR = 2; const int ORPriority = 2; // ||
const int Equal = 1; const int EqualPriority = 1; // =
//---------------------------------------------------------------------------
jm77341991 2010-01-14
  • 打赏
  • 举报
回复
这个问题是内存频繁分配出现的,你需要一个内存管理模块单独管理内存。
我之前也出现这个情况。
jasonM2008 2009-12-07
  • 打赏
  • 举报
回复
谢谢各位热心的回复!如果解决了这些问题,我会吧解决的心得体会写到我博客上,共其他新手参考!!!!
cnzdgs 2009-12-06
  • 打赏
  • 举报
回复
从错误信息来看,是使用了空指针。比较可能的原因有:
1、内存被释放后指针仍被使用;
2、内存共享冲突(异步操作或多线程);
3、内存越界覆盖了其它数据。
yinshisike 2009-12-06
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 yinshisike 的回复:]
    while(1)
    {
    //写到这里
    DWORD dwTrans = 0;
    DWORD dwKey = 0;
    PER_HANDLE_DATA *pHandleData = NULL;
    PER_IO_DATA *pIoData = NULL;
    BOOL bRet = FALSE;

        bRet = GetQueuedCompletionStatus(hIOCP, &dwTrans, &dwKey, (LPOVERLAPPED*)&pIoData, INFINITE);

  // 你这下面都释放掉了,你也不复位,不死才怪了.

  }

[/Quote]

---------------以上都是胡说八道,不可全信-----------------
yinshisike 2009-12-06
  • 打赏
  • 举报
回复

while(1)
{
//写到这里
DWORD dwTrans = 0;
DWORD dwKey = 0;
PER_HANDLE_DATA *pHandleData = NULL;
PER_IO_DATA *pIoData = NULL;
BOOL bRet = FALSE;

bRet = GetQueuedCompletionStatus(hIOCP, &dwTrans, &dwKey, (LPOVERLAPPED*)&pIoData, INFINITE);

// 你这下面都释放掉了,你也不复位,不死才怪了.

}
Pro_X 2009-12-06
  • 打赏
  • 举报
回复
写UDP就没有必要用IOCP了~
木头菇 2009-12-06
  • 打赏
  • 举报
回复
一般IOCP内存错误可能是内存分不出来了,调试方法的话,使用windbg,崩溃时可以把dump信息贴上来
jourbin 2009-12-06
  • 打赏
  • 举报
回复
还有其他地方,自己检查一下吧,最好在while循环里加判断pIoData,pHandleData是否为空
其他地方(比如内存分配,socket创建是否成功等等)也检查一下
jourbin 2009-12-06
  • 打赏
  • 举报
回复
if(pIoData == NULL) //关闭套接字引起
{
ATLTRACE("---关闭套接字引起---\r\n");
CAutoLock(&(pThis->m_ListIoInUsecs), "Receivethread");
pThis->FreeIoData(pIoData, pHandleData);
continue;
}
jourbin 2009-12-06
  • 打赏
  • 举报
回复
有什么好看的呢,从错误信息就可以知道,一定是使用了非法指针或句柄(句柄其实也是指针)
whs1980 2009-12-05
  • 打赏
  • 举报
回复
buf.buf = pIoData->szBuf;//这一块内存是unpaged的
buf.len = MAX_BUF;
是不是等待接收的套接字太多,而真正接收的数据很少,使得大量unpaged的内存被使用,导致的问题。
楼主看看这一块内存是否被释放了。
1。只发起连接,但客户端不发送数据,直至处理异常,看看是否也会出现同样的问题,验证我上面说的情况是否属实。
2。监控内存变化,是否只增不减。
swq1982 2009-12-04
  • 打赏
  • 举报
回复
楼主可以利用任务管理器里面看看资源的占用情况,在多线程编程中,有时资源占用大的时候,系统本身调度不过来就可能莫名其妙地出现系统的动态库报错的。这样可以先确定是不是系统的资源不足的问题。
有个重要的问题要提醒楼主的是在多线程编程中,若使用的系统windows平台,那么一个进程能开辟的最大内存在2G左右,而Linux中好像是没有这个限制的。楼主的程序应该是单进程多线程的,所以也必须考虑内存限制。
以上仅是我编程中一些经验希望对你有用的!
加载更多回复(11)

18,363

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧