🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #4733

what happens if i don't use WaitForData !

#4733
From: Niyazi Unugur
Date: Wed, 22 Dec 2004 22:01
27 lines
2481 bytes
i've read many suggestions on the usage of WaitForData (TWinSocketStream) before reading from thread blocking
sockets.

i am developing a realtime system which accepts connections from terminals over GPRS.

On my lab tests, terminals are part of LAN (not over GPRS) and connects to server simultaneously. For each connection, my
server application creates new thead and accepts the connection (by using TServerClientThread). I test 60 - 80 concurrent connections.
Each terminal sends files, receive configuraiton files, do time sync etc. During the tests my server application do not log any exceptions.

The problem arises on the field test when the communication is over GPRS (latency, timeouts, unexpectedly terminating connections, etc). My server 
application starts to give unexpected access violations, abnormal program terminations in not more than 2 minutes of up time.

I was shocked !

I enable code-guard, use debug libraries and all my internal debug messages. In my log files i saw strange access violations at some part of my codes and on some parts of VCL codes (system.pas, getmem.inc).

At the end of the third day ! I was discover to use WaitForData in my base socket read function and check disconnections (when WaitForData returns ture, and socket read returns zero byte). 

Result is unbelivable, It worked !!!

My question is why i got such unexpected exceptions when not using WaitForData?
Does socket read function overwrite some memory locations, if i use it without WaitForData?

Thanks in advance,

Niyazi Unugur
Technical Details
Message-ID: <41c9eeca$2@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeeder.wxs.nl!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,e6235b3209a12c50,start
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Niyazi Unugur" <unugurn@hotmail.com>
Sender: "Niyazi Unugur" <unugurn@hotmail.com>
Reply-To: "Niyazi Unugur" <unugurn@hotmail.com>
Subject: what happens if i don't use WaitForData !
Newsgroups: borland.public.cppbuilder.internet.socket
X-User-Info: 213.161.130.174     
NNTP-Posting-Host: 207.105.83.66
Message-ID: <41c9eeca$2@newsgroups.borland.com>
Date: 22 Dec 2004 14:01:46 -0800
X-Trace: newsgroups.borland.com 1103752906 207.105.83.66 (22 Dec 2004 14:01:46 -0800)
Lines: 28
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeeder.wxs.nl!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail