Send/ReceiveNetworkData(), ConnectionID()... crash prevention

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
tatanas
Enthusiast
Enthusiast
Posts: 260
Joined: Wed Nov 06, 2019 10:28 am
Location: France

Send/ReceiveNetworkData(), ConnectionID()... crash prevention

Post by tatanas »

Hi,

I'm curious about the behaviour of those network functions when the connection parameter is not valid anymore.
I'm working on a TCP client/server (=~ 250 simultaneous connected clients) and if a client disconnects when a working thread try to send data to it, crash happens. I have to check everytime the accessibility of the socket with a non PB native function.

If I compare with the win32 send_() function, this last one doesn't crash if the socket handle is obsolete.
Is there a technical reason why those functions crash with a "invalid memory access" ?

Could you enhance those functions so that they will accept an obsolete socket handle and return an new error value ?

Thanks for your time.
Last edited by tatanas on Mon Mar 31, 2025 11:43 am, edited 1 time in total.
Windows 10 Pro x64
PureBasic 6.20 x64
Quin
Addict
Addict
Posts: 1132
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Send/ReceiveNetworkData(), ConnectionID()... crash prevention

Post by Quin »

tatanas wrote: Fri Mar 28, 2025 4:24 pm Could you enhance those function so that they will accept an obsolete socket handle and return an new error value ?
+100
swhite
Enthusiast
Enthusiast
Posts: 796
Joined: Thu May 21, 2009 6:56 pm

Re: Send/ReceiveNetworkData(), ConnectionID()... crash prevention

Post by swhite »

I use the TCP sockets a lot and returning an error message rather than crashing would be much better and allow you to handle the situation cleanly. The alternative would be something like IsConnection() so that it could be used like Isdatabase() to determine if the connection is valid.

Simon
Simon White
dCipher Computing
Post Reply