Click here to Skip to main content
15,901,205 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionprefix vs postfix Pin
swjam1-Jan-07 2:45
swjam1-Jan-07 2:45 
AnswerRe: prefix vs postfix Pin
Nemanja Trifunovic1-Jan-07 5:22
Nemanja Trifunovic1-Jan-07 5:22 
QuestionIOCP And WSANOBUFS Error Pin
Polity4h1-Jan-07 2:32
Polity4h1-Jan-07 2:32 
QuestionRe: IOCP And WSANOBUFS Error Pin
Mark Salsbery1-Jan-07 8:52
Mark Salsbery1-Jan-07 8:52 
AnswerRe: IOCP And WSANOBUFS Error Pin
Polity4h1-Jan-07 11:01
Polity4h1-Jan-07 11:01 
GeneralRe: IOCP And WSANOBUFS Error Pin
Mark Salsbery1-Jan-07 15:14
Mark Salsbery1-Jan-07 15:14 
GeneralRe: IOCP And WSANOBUFS Error Pin
Polity4h2-Jan-07 0:27
Polity4h2-Jan-07 0:27 
GeneralRe: IOCP And WSANOBUFS Error Pin
Polity4h2-Jan-07 6:25
Polity4h2-Jan-07 6:25 
If the socket is not "connected" (for UDP that just means all datagrams will be ignored except
from the "connected" address) then the socket's recv buffer gets filled with every UDP datagram it
sees on the network. You need to pull them out fast enough to keep enough buffer space for
receives.

I tried some solutions but i cant seem to get them working. Its probably my lack of experiance but well,
The fundamental code:
<br />
				while (1){ <br />
					BOOL bIORet = GetQueuedCompletionStatus ( // Get a completed IO request<br />
						   pThis->m_hIOCompiltionPort,<br />
						   &dwIoSize,<br />
						   reinterpret_cast<LPDWORD>(pThis),<br />
						   &ptrOverlapped, INFINITE);<br />
					if (!bIORet){<br />
						TRACE("Winsock error code: %i\n", GetLastError());<br />
						Gameye::Library::Thread::CMPThread::Sleep(0);<br />
					}<br />
					else{<br />
						ptrSession = static_cast<CVirtualSession*>(ptrOverlapped->Pointer);<br />
						CAbstractServerClass* ptrGameClass = (*pThis->m_ptrGameManager)[ptrSession->getNDServer()->GameID];<br />
						if (ptrGameClass == NULL){<br />
							TRACE("Game is unknown, probably removed\n");<br />
						}<br />
						else{<br />
							objToolset.Session = ptrSession;<br />
							switch(ptrSession->getTask()){<br />
								case RequestSend: //Request to send a packet<br />
									if (WSASendTo(sSocket, <br />
										ptrSession->getWSABuffer(),<br />
										1,<br />
										reinterpret_cast<LPDWORD>(&ptrSession->getWSABuffer()->len),<br />
										0,reinterpret_cast<sockaddr*>(ptrSession->getAddress()),<br />
										sizeof(sockaddr_in),<br />
										ptrSession->getOverlapped(), NULL) == -1)<br />
									{<br />
										int iErrorCode = WSAGetLastError();<br />
										if (iErrorCode != 997){ //997 =  Data is already recieved<br />
											TRACE("Sending failed because: %i\n", WSAGetLastError());<br />
											break;<br />
										}<br />
									}<br />
									ptrSession->setStatus(AfterSend);<br />
									break;<br />
								case RequestRecieve: //Request to recieve a packet<br />
									if (WSARecvFrom(sSocket, <br />
										ptrSession->getWSABuffer(),<br />
										1,<br />
										reinterpret_cast<LPDWORD>(&ptrSession->getWSABuffer()->len),<br />
										&iTemp,reinterpret_cast<sockaddr*>(ptrSession->getAddress()),<br />
										&iSockAddrSize,<br />
										ptrSession->getOverlapped(), NULL) == -1)<br />
									{<br />
										int iErrorCode = WSAGetLastError();<br />
										if (iErrorCode != 997){ //997 =  Data is already recieved<br />
											TRACE("Recieving failed because: %i\n", WSAGetLastError());<br />
											ptrSession->setStatus(AfterRecieve);<br />
										}<br />
									}<br />
									ptrSession->setStatus(AfterRecieve);<br />
									break;			<br />
								case AfterSend: //Call sending event<br />
									ptrSession->incSendBytes(dwIoSize);<br />
									ptrGameClass->RetrieveServerInfo(ptrSession->getNDServer(), &objToolset);<br />
									break;<br />
								case AfterRecieve: //Call receiving event<br />
									ptrSession->incRecvBytes(dwIoSize);<br />
									if (ptrGameClass->UnpackServerInfo(ptrSession->getNDServer(), &objToolset) == 0){//Session is finished!<br />
										ptrSession->Finish();<br />
									}<br />
									break;<br />
								case Finishing:<br />
									pThis->m_objSql.AddGame(ptrSession->getNDServer());<br />
									break;<br />
								default:<br />
									break; //Who knows?<br />
							}<br />
						}<br />
					}


Most calls should be clear. the events i call are simpel functions, they should return in a inch of a sec, next to that, i can have 10 workerthreads running and still i get the same error. some sessions come out alive but most of them just gives the known error on recieve. You also see that after every send, a call to WSARecvFrom is been made. its not directly but again with the inch of a second.

Also, with 10 sessions, 2/3 sessions returns the error on recieve the rest just works fine. with 400 sessions, a few return with the error and a few dont. that indicates that the recieve buffer aint full right?
GeneralRe: IOCP And WSANOBUFS Error Pin
Mark Salsbery2-Jan-07 7:07
Mark Salsbery2-Jan-07 7:07 
GeneralRe: IOCP And WSANOBUFS Error Pin
Polity4h2-Jan-07 7:17
Polity4h2-Jan-07 7:17 
Questionconsole app in VS2003 Pin
swjam1-Jan-07 2:01
swjam1-Jan-07 2:01 
AnswerRe: console app in VS2003 Pin
Jonathan [Darka]1-Jan-07 2:16
professionalJonathan [Darka]1-Jan-07 2:16 
GeneralRe: console app in VS2003 Pin
swjam1-Jan-07 2:22
swjam1-Jan-07 2:22 
AnswerRe: console app in VS2003 Pin
Michael Dunn1-Jan-07 10:00
sitebuilderMichael Dunn1-Jan-07 10:00 
GeneralRe: console app in VS2003 Pin
swjam1-Jan-07 15:18
swjam1-Jan-07 15:18 
Questiondouble casting Pin
Hadi Dayvary1-Jan-07 1:43
professionalHadi Dayvary1-Jan-07 1:43 
AnswerRe: double casting Pin
Gary R. Wheeler1-Jan-07 4:33
Gary R. Wheeler1-Jan-07 4:33 
Question"friend" class question Pin
eli150219791-Jan-07 1:04
eli150219791-Jan-07 1:04 
AnswerRe: "friend" class question Pin
Polity4h1-Jan-07 4:10
Polity4h1-Jan-07 4:10 
QuestionData Exchange Pin
Shouvik Das1-Jan-07 0:16
Shouvik Das1-Jan-07 0:16 
AnswerRe: Data Exchange Pin
PJ Arends1-Jan-07 7:48
professionalPJ Arends1-Jan-07 7:48 
GeneralRe: Data Exchange Pin
Shouvik Das1-Jan-07 16:42
Shouvik Das1-Jan-07 16:42 
GeneralRe: Data Exchange Pin
Cristian Amarie2-Jan-07 3:58
Cristian Amarie2-Jan-07 3:58 
GeneralRe: Data Exchange Pin
Shouvik Das2-Jan-07 17:49
Shouvik Das2-Jan-07 17:49 
GeneralRe: Data Exchange Pin
Cristian Amarie2-Jan-07 20:42
Cristian Amarie2-Jan-07 20:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.