Forum > Networking and Web Programming
Interaction between fcl-net ssockets TInetServer & Debugger (Lazarus+Linux)
(1/1)
Curt Carpenter:
I'm using the fcl-net ssockets unit to implement inter-process communications among Lazarus+Linux programs. There appears to be an interaction between the TInetServer class and the debugger if I attempt to use the non-blocking mode and the OnIdle function.
If I compile my program with this FormCreate procedure and debugging enabled
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.FormCreate(Sender: TObject);begin HubServer := TINetServer.Create(HubPort); //HubPort = 4001 HubServer.OnConnect:=@OnConnect; HubServer.Listen; HubServer.OnIdle:=@OnIdle; HubServer.SetNonBlocking;end;
and run my the program, I get an error "ESocketError "Accept would block on socket: 13." If I run the program without debugging information, the program executes as expected. This isn't a problem for me since I don't really need OnIdle, but I thought I'd mention it here should anyone else encounter the issue.
Warfley:
The problem is simply that Lazarus will always raise an exception even if it is cought. Take the following code:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type EGotoReplacement = class(Exception); procedure GotoReplacementExample;begin try while true do begin // Do something if ExitCondition then raise EGotoReplacement; end; except on E: GotoReplacement do; end; // Do something after the loopend;If you run this code normally, the try-except works pretty much exactly like a goto:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure GotoExample;label EndOfLoop;begin while true do begin // Do something if ExitCondition then goto EndOfLoop; end;EndOfLoop: // Do something after the loopend;
But if you run it in Lazarus, Lazarus will instead pop up a window telling you that an EndOfLoop exception was raised.
This means exceptions that are part of the control flow of the program, can get really annoying really fast.
The ssockets library is built in a way that when there is no data available, instead of just returning some empty value, instead an exception is raised. This exception is then caught again to handle the non availability (e.g. by doing a sleep/idle loop). So it's a deviation from expected control flow i.e. an Exception, but it is handled so it is not an error, and therefore does not need to notify the user.
BUT: Lazarus does not know if it needs to notify the user or not, so it always notifies you.
How to solve this: Two options 1. don't make the listen socket non blocking. Just have it running in it's own thread. As there will always ever only be one listening socket, thats not an issue.
Option 2: Click the checkbox that says "Ignore exceptions of this type" then Lazarus will skip all non blocking exceptions and not pop up anymore
PS: The example above might seem stupid and a convoluted use of exceptions, but I have actually used this once in Java, as Java does not have a goto statement and I needed a goto statement
Curt Carpenter:
Thanks. Good to know.
Navigation
[0] Message Index