TCPSocket.flush lockup

I just squashed a bug that had eluded me for several days - code that had been working fine for years started locking up the application, apparently randomly and intermittantly, w/o firing an app.unhandledexception. It’s running on OS 10.8 using Xojo 2015v3. It was a pain to track down because the IDE would lock up, so it was difficult to track down. It turned out the code was locking up at TPCsocket.flush, in code talking to a Keithley voltmeter. Removing that flush stopped the hangups. Is this a bug in Xojo? Why would this crash the IDE? Does it require a response from the receiving end?

TCPSocket.Flush is basically implemented like this:

Sub Flush(theSocket As TCPSocket)
  #Pragma BackgroundTasks False

  While True
    theSocket.Poll
    If theSocket.LastErrorCode <> 0 Then
      Exit While
    End If
    If theSocket.BytesLeftToSend <= 0 Then
      Exit While
    End If
  Wend
End Sub

The flush method isn’t yielding time back to the debugger support code that checks to see if new commands have come in from the IDE.

Possibly! I’ve not seen this locally to go about tracking it down.

You should add a check thus:

if  (theSocket.isConnected=False)  then exit while

Otherwise an app will loop in flush if the remote end drops the connection. This could easily happen if, for example, the computer sleeps while the app is running and then wakes up later. I’ve had this issue and will have to wrap flush with the test above.

I’ve had some issues using tcpsocket.Flush too. Removed the lines and it worked again. (MacOS) by reading this i suspect a bug not sure though.

[quote=303934:@Joe Ranieri]TCPSocket.Flush is basically implemented like this:

Sub Flush(theSocket As TCPSocket)
  #Pragma BackgroundTasks False

  While True
    theSocket.Poll
    If theSocket.LastErrorCode <> 0 Then
      Exit While
    End If
    If theSocket.BytesLeftToSend <= 0 Then
      Exit While
    End If
  Wend
End Sub

[/quote]

Are you saying that this is effectively what it is (with the above being pseudo-code), or actually what it is?

See, the doc for socket.flush says that the purpose of calling it is to force out any data now in the send buffer immediately. That’s why I call it. There’s nothing in the above (as far as I know) that forces data out. Unless that is what socket.poll does - but the documentation for that is content-free so I can’t tell.

I would appreciate some elucidation.

All flush does is to wait till everything is done.

When you call write, the data is copied to the OS send buffer and than the method returns. Data is send automatically in background. Poll just checks status on this and calls events and updates properties.

[quote=354748:@Christian Schmitz]All flush does is to wait till everything is done.

When you call write, the data is copied to the OS send buffer and than the method returns. Data is send automatically in background. Poll just checks status on this and calls events and updates properties.[/quote]
Thank you. That’s useful information.