Re: Excessive Delays in CAsyncSocket::Send()?
"Scott McPhillips [MVP]" wrote:
"Stephen Myers" <StephenMyers@discussions.microsoft.com> wrote in message
news:BADD3E3C-26F3-4679-B3EF-572170CB8E88@microsoft.com...
I've got an CDialog based application using a TCP connection. I'm using
VS
2003 .NET. The application works as I expected using a software emulation
program on the same machine (via lookpack) or when connecting to the
emulator
on another XP machine. So far so good.
When I connect with the target machine (some embedded Linux derivation),
CASyncSocket::Send() blocks for geometrically increasing times.
TRACE Output
Send in 0
Send in 250
Send in 578
Send in 1125
Send in 2329
Send in 4734
Send in 9547
Send in 0
...
I then run the application using Linux/Wine and everything is happy!
I'm setting the send buffer to zero to immediately send any message to the
target. (Volume of messages is low.)
int opt=0; // Force no buffering on send
if(!m_TCPClient->SetSockOpt(SO_SNDBUF, &opt, sizeof(opt))){
TRACE("SetSockOpt(m_TCPClient) failed with %d\n",::GetLastError());
}
SOCKADDR_IN server;
memset(&server,0,sizeof(server));
server.sin_family = AF_INET;
server.sin_addr.S_un.S_addr = pSock->sin_addr.S_un.S_addr;
server.sin_port = htons(LSP::LSP_PORT);
if(!m_TCPClient->Connect((SOCKADDR*)&server,sizeof(server))){
TRACE("TCPClient Connect failed w/%d\n",::GetLastError());
}
My send code is also fairly simple. I maintain a queue of messages and
only
send after any previous message has been cleared.
(Everything is done in a single thread.)
What does this mean? The way you determine "has been cleared" might be the
issue here, since you say this delays the sending.
I agree that this a likely place for problems. Basically, as a message is
sent, it's ID is saved. The ID is returned as part of the server's response.
Until that happens no new sends are initiated. I have used TRACE liberally,
to verify that things work like I expected them to.
DWORD dwNow = GetTickCount();
if(SOCKET_ERROR == m_TCPClient->Send(pPkt,pPkt->size())){
TRACE("m_TCPClient.Send() failed with %d\n",::GetLastError());
}
TRACE("Send in %d\n",GetTickCount()-dwNow);
I've experimented with TCP_NODELAY and differing values to SO_SNDBUF with
unsatisfactory results.
I doubt that attempting to set the buffer to zero has any effect at all.
The socket is free to ignore your request. Try to get it working without
any socket options, at least until everything is functioning.
That's where I am now. I'm wondering if my real problem isn't due to
sending before both sides of the connection have stablized. I do wait for
OnSend after OnConnect before I start sending. Without the SO_SNDBUF 0, the
first response takes several seconds.
Any ideas on what's going on? The geomectrically increasing times should
mean something (just not to me).
No idea. Send should return quickly.
--
Scott McPhillips [VC++ MVP]