I'm creating a high preformance server which uses udp to query at least 100 servers continiously.
The application is made in VS2005 using I/O Completion ports.
In the beginning, everything goes well, but after a few dozen query's. It seems to be slowed down terrible.
Explaining better: I got a timeout thread because UDP is connectionless and i dont want to keep destroying and recreating the sockets. Everytime a socket is noticed as timeout, it will set another internal unique value ( to check whether an incoming packet really belongs to that active server ) and does a new query.
The first minute there is no timeout. After that 9 / 10 query's fail.
The code to send and recieve:
Expand|Select|Wrap|Line Numbers
- template <typename T>
- ESocketStatus CASyncUdpSocket<T>::Send(const char* p_ptData, size_t p_dwLength){
- m_objWsaBuffer.len = p_dwLength;
- m_objWsaBuffer.buf = const_cast<char*>(p_ptData); //We can assume that the data wont be touched
- DWORD dwResult = WSASendTo(get_Socket(),
- &m_objWsaBuffer,
- 1,
- &m_dwLastSend,
- NULL,
- reinterpret_cast<const sockaddr*>(&m_objConnectedAddress),
- sizeof(m_objConnectedAddress),
- get_Overlapped(),
- NULL );
- if (dwResult == SOCKET_ERROR){
- if (WSAGetLastError() != WSA_IO_PENDING){
- __report << "Error sending: " << WSAGetLastError() << "\n";
- return e_Failed;
- }
- }
- return e_Succeeded;
- }
- template <typename T>
- ESocketStatus CASyncUdpSocket<T>::Recieve(char* p_pStrBuffer, size_t p_dwLength){
- m_objWsaBuffer.len = p_dwLength;
- m_objWsaBuffer.buf = p_pStrBuffer;
- m_iFromLength = sizeof(sockaddr_in);
- m_dwLastRecieved = 0;
- m_dwFlags = 0;
- DWORD dwResult = WSARecvFrom(get_Socket(),
- &m_objWsaBuffer,
- 1,
- &m_dwLastRecieved,
- &m_dwFlags,
- reinterpret_cast<sockaddr*>(&m_objConnectedAddress),
- &m_iFromLength,
- get_Overlapped(),
- NULL );
- if (dwResult == SOCKET_ERROR){
- if (WSAGetLastError() != WSA_IO_PENDING){
- __report << "Recieve failed: " << WSAGetLastError();
- return e_Failed;
- }
- }
- return e_Succeeded;
- }
Interresting: It seems that every send goes well out of my socket, however after that minute, most recieves fail. only a few succeeds ( noticed with ethereal packet tracer )