 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Martin Guest
|
Posted: Mon Mar 27, 2006 6:03 pm Post subject: Inactivity timeouts in sockets? |
|
|
I've got an app that maintains several different
socket connections to multiple computers. Most of
the connections work fine, but one has been giving
lots of problems lately.
The ones that work have data flowing fairly
consistently, say a minimum of 3-5 packets in a 5
minute period, but can be much more than that.
The connection that gives me the problem is one
that has periods where nothing is sent/receive for
more than 20 minutes. The socket is still
connected (no disconnect events or errors), but
later on we find that the other side tried to send
something that wasn't received by our app. What's
more, closing and reopening the socket doesn't
appear to reestablish data passage, even though we
get the connect event. It typically takes an app
restart and/or reboot to get data passing
(customer doesn't know difference).
Are there lower level timeouts that are occuring
that I'm not aware of? Should there be a "keep
alive" transmission every so often? Is something
else happening here?
Tech info:
BCB5 using borland's TServerSocket & TClientSocket
in asynchronous mode. The failing connection is a
server socket running on XP pro.
I don't know if it makes any difference but more
info is better than none. This particular
computer/app is maintaining connections to 6
computers simultaneously and there are two
connections to one of them (server socket and
client socket). The server socket that is failing
is the one to the system that has two connections.
Thanks,
Marty |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Mon Mar 27, 2006 7:03 pm Post subject: Re: Inactivity timeouts in sockets? |
|
|
"Martin" <dev (AT) no (DOT) comppromed.spam.com> wrote in message
news:44281b29$1 (AT) newsgroups (DOT) borland.com...
| Quote: | The connection that gives me the problem is one that has periods
where nothing is sent/receive for more than 20 minutes.
|
Sockets themselves do not have any problems with idle periods. They don't
care at all whether data is being transmitted frequently or not. So any
problems you are having are likely caused by problems in your own code that
is managing the sockets.
| Quote: | The socket is still connected (no disconnect events or errors), but
later on we find that the other side tried to send something that wasn't
received by our app.
|
What does your actual code look like? Since you are using non-blocking
sockets, my first guess would be that you are not completely clearing the
socket's inbound buffer when data arrives, thus the socket eventually begins
losing notifications when new data arrives. When data arrives, you have to
read ALL of it at that moment, into your own buffer. You should not leave
data unread in the socket in between events.
Gambit |
|
| Back to top |
|
 |
Martin Guest
|
Posted: Mon Mar 27, 2006 10:03 pm Post subject: Re: Inactivity timeouts in sockets? |
|
|
Remy Lebeau (TeamB) wrote:
| Quote: | "Martin" <dev (AT) no (DOT) comppromed.spam.com> wrote in message
news:44281b29$1 (AT) newsgroups (DOT) borland.com...
The connection that gives me the problem is one that has periods
where nothing is sent/receive for more than 20 minutes.
Sockets themselves do not have any problems with idle periods. They don't
care at all whether data is being transmitted frequently or not. So any
problems you are having are likely caused by problems in your own code that
is managing the sockets.
The socket is still connected (no disconnect events or errors), but
later on we find that the other side tried to send something that wasn't
received by our app.
What does your actual code look like? Since you are using non-blocking
sockets, my first guess would be that you are not completely clearing the
socket's inbound buffer when data arrives, thus the socket eventually begins
losing notifications when new data arrives. When data arrives, you have to
read ALL of it at that moment, into your own buffer. You should not leave
data unread in the socket in between events.
Gambit
|
I don't think I'm leaving anything in the input
buffer. Here's the OnRead event:
void __fastcall socketClass::onRead( TObject
*Sender, TCustomWinSocket *Socket)
{
char buf[ 4096];
for (;
{
int numBytes = Socket->ReceiveBuf( buf,
sizeof( buf));
if (numBytes <= 0)
break;
if (cfg.comDiag > 1)
audit( HERE, "%s %s:onRead - Recving
%d bytes\n",
currentTime(), this->sktId,
numBytes);
this->inBuf->writeData( buf, numBytes);
}
} /* socketClass::onRead() */
inBuf is a ring buffer class that we wrote years
ago. It stores the data until the app has a chance
to get around to it (within 0.5 sec.). It's
possible that the ring buffer is messing with me
but it's been in use longer than the underlying
socket stuff. I'm double checking tonight to see
if we're getting the audit info from the read
event. Unfortunately, this problem only happens
overnight.
Marty |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Mar 28, 2006 12:03 am Post subject: Re: Inactivity timeouts in sockets? |
|
|
"Martin" <dev (AT) no (DOT) comppromed.spam.com> wrote in message
news:44285053$1 (AT) newsgroups (DOT) borland.com...
| Quote: | I don't think I'm leaving anything in the input
buffer. Here's the OnRead event:
|
You should be calling ReceiveLength() before calling ReceiveBuf()
void __fastcall socketClass::onRead(TObject *Sender, TCustomWinSocket
*Socket)
{
char buf[ 4096];
int numBytes;
do
{
numBytes = Socket->ReceiveLength();
if( numBytes > 0 )
numBytes = Socket->ReceiveBuf(buf, min(sizeof(buf),
numBytes));
if( numBytes < 1 )
break;
if( cfg.comDiag > 1 )
audit( HERE, "%s %s:onRead - Recving %d bytes\n",
currentTime(), this->sktId, numBytes);
inBuf->writeData(buf, numBytes);
}
while( true );
}
| Quote: | inBuf is a ring buffer class that we wrote years ago. It stores the
data until the app has a chance to get around to it (within 0.5 sec.).
It's possible that the ring buffer is messing with me but it's been in
use longer than the underlying socket stuff.
|
Are you sure that you are not filling the buffer beyond its capacity,
overriding the surrounding memory?
Did you verify that the sending application is actually sending its data
without errors?
Also, non-blocking sockets rely on the message queue, so are you blocking
the queue at any time from processing new messages?
Are there are firewalls or routers in between your application and the
sending application, which might be blocking the data?
Gambit |
|
| Back to top |
|
 |
Martin Guest
|
Posted: Tue Mar 28, 2006 8:03 pm Post subject: Re: Inactivity timeouts in sockets? |
|
|
Remy Lebeau (TeamB) wrote:
| Quote: | "Martin" <dev (AT) no (DOT) comppromed.spam.com> wrote in message
news:44285053$1 (AT) newsgroups (DOT) borland.com...
I don't think I'm leaving anything in the input
buffer. Here's the OnRead event:
You should be calling ReceiveLength() before calling ReceiveBuf()
|
Why? I can see that it would limit the amount of
data read to the current incoming amount, but the
underlying socket in windows should take care of
any buffering stuff and the message queues.
| Quote: | Are you sure that you are not filling the buffer beyond its capacity,
overriding the surrounding memory?
|
No, it's not overwriting the surrounding memory.
And the buffer is much bigger than the incoming
packets.
| Quote: | Did you verify that the sending application is actually sending its data
without errors?
|
Yes. During the timeframe where it's not working,
they're sending and resending, but no response
from us.
| Quote: | Also, non-blocking sockets rely on the message queue, so are you blocking
the queue at any time from processing new messages?
|
No. The other sockets still work during this time.
As does the rest of the application.
| Quote: | Are there are firewalls or routers in between your application and the
sending application, which might be blocking the data?
|
No. Both apps are on a LAN (same subnet), and I
don't see how a "reboot" would clear a block from
any router they may have. There is not a firewall
running on our side.
When it happened last night, I did not get any of
the auditing statements from the read event. So
either no events happened or the underlying recv()
calls always returned 0.
Marty |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Wed Mar 29, 2006 2:03 am Post subject: Re: Inactivity timeouts in sockets? |
|
|
"Martin" <dev (AT) no (DOT) comppromed.spam.com> wrote in message
news:44298fd1$1 (AT) newsgroups (DOT) borland.com...
| Quote: | No, it's not overwriting the surrounding memory. And the buffer is
much bigger than the incoming packets.
|
That does not mean that the buffer is not filling up, if the application is
not removing data from the buffer faster than it arrives.
| Quote: | During the timeframe where it's not working, they're sending and
resending, but no response from us.
|
How are you verifying that, though? Did you try using a packet sniffer to
make sure that data is actually reaching your machine?
| Quote: | When it happened last night, I did not get any of
the auditing statements from the read event. So
either no events happened or the underlying recv()
calls always returned 0.
|
recv() returns 0 when the socket has been disconnected by the other party.
If there is no data available but the connection is still active, then
recv() will return SOCKET_ERROR and WSAGetLastError() returns
WSAEWOULDBLOCK.
You should be using ReceiveLength() before ReceiveBuf() to make sure that
there is any data available for reading before you attempt to actually read
it.
Gambit |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|