Using Windows thread variables influences the results of (WSA)GetLastError
Original Reporter info from Mantis: L505
-
Reporter name: Lars(L505)
Original Reporter info from Mantis: L505
- Reporter name: Lars(L505)
Description:
My friend Jorge built a webserver (so far for Windows) called LightWebserver.. I wanted to detect whether the server could connect to port 80 or not after a Bind call in synapse, so I checked LastError which is a synapse method that basically wraps WSAGetLastError winapi call. I found that LastError did not work inside a thread after calling the synapse Bind method. Yet on delphi it did. If I used Bind not utilizing any threads, the WSAGetLastError reported correctly with FPC. The correct error that should be reported is 10048 if apache is already running on port 80. After trying to debug synapse for two days, I found that it wasn't synapse.. AFAIK since delphi worked fine with the same code.. the difference was only compilers.
So then I built a simple sockets.pp and beginthread based test case (attached) rather than with synapse, for simplicity reasons. WSAGetLastError is not reporting any errors inside the thread.. but it should report error 10048 since port 80 is already taken by my apache server which is running.
If you comment out the thread code (instructions included in attached) it does report the correct error. Similar behavior with synapse LastError method. Any time I use synapse inside a thread, LastError simply doesn't work.. while in delphi the same code using synapse works fine. I have not included the synapse code since this attached demo is a much simpler test case.
Additional information:
Please forgive my ignorance on threads and the code included may be poor.