Re: [UDT] about "UDT::select"
Brought to you by:
lilyco
From: Yunhong Gu <yu...@la...> - 2006-04-07 15:22:59
|
in udt project properties, C/C++ -> Code Generation, select Runtime Library to "Multi-threaded Debug DLL (/MDd)" Or, you can check out the most recent code from sourceforge CVS. Thanks Yunhong On Fri, 7 Apr 2006, XU, Lizhen wrote: > Hello! > > I've been using UDT on Windows-XP recently. I found it easy to use. But when > I use the function "UDT::select" in my program(on MS visual > studio.net2003), I got a run-time error : > ***************************************** > Debug Assertion Failed! > Program: e:\try.cpp > File: dbgheap.c > Line: 1132 > > Expression: _CrtIsValidHeapPointer(pUserData) > ****************************************** > > We cannot find where the problem is. Could you please kindly take the bother > to have a look at this and help to find out the reason? Look forward to your > help! Thanks a million. > > Best, > > Leslie > > The source code file is as follows: > > //////////////////////////////////////////////////////////////////// > #include <iostream> > #include <udt.h> > > > using namespace std; > > using namespace UDT; > > int main() > { > > UDTSOCKET serv2 = UDT::socket(AF_INET, SOCK_STREAM, 0); > sockaddr_in my_addr2; > my_addr2.sin_family = AF_INET; > my_addr2.sin_port = htons(22222); > my_addr2.sin_addr.s_addr = INADDR_ANY; > > cout<<"server open: "<<serv2<<endl; > if (UDT::ERROR == UDT::bind(serv2, (sockaddr*)&my_addr2, sizeof(my_addr2))) > { > cout << "bind: " << UDT::getlasterror().getErrorMessage(); > return 0; > } > UDT::listen(serv2, 10); > > int namelen; > sockaddr_in their_addr; > > UDTSOCKET recver = UDT::accept(serv2, (sockaddr*)&their_addr, &namelen); > if(UDT::ERROR != recver) > cout<<"new client coming..."<< recver <<endl; > > timeval tv; > UDSET tempfds; > > tv.tv_sec = 2; > tv.tv_usec = 0; > > UD_ZERO(&tempfds); > UD_SET(recver, &tempfds); > > if( UD_ISSET(recver, &tempfds)) > cout<<"yes!"<<endl; > bool done = false; > int i = 0; > > Sleep(5000); > while(!done) > { > int res = UDT::select(0, &tempfds, NULL, NULL, &tv); > > if(res == 0 && res != (UDT::ERROR)) > { > cout<<++i<<": "<<"time out!"<<endl; > tv.tv_sec = 2; > tv.tv_usec = 0; > UD_ZERO(&tempfds); > UD_SET(recver, &tempfds); > continue; > } > else if( UD_ISSET(recver, &tempfds) ) > { > cout<<"good!"<<endl; > done = true; > } > else > { > cout<<"what's up?"<<endl; > break; > } > > } > UDT::close(serv2); > return 0; > } > > /////////////////////////////////////////////////////////////////////// > |