GetLastNetworkError()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Bitblazer
Enthusiast
Enthusiast
Posts: 736
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

GetLastNetworkError()

Post by Bitblazer »

A simple way to get the specific reason why the previous network operation failed. Just returning -1 doesnt really help to find the real reason why something failed. That's crucial to fix the problem.

Basically an official way of doing this for all three supported operating systems. This is my solution based on research, debugging and unix manual pages, for windows a call to WSAGetLastError should do the same.

Linux solution based on remi's info

Code: Select all

ImportC ""
  errno_location() As "__errno_location"
EndImport
Procedure.s GetLastSocketError()
  Define ErrorMessage$
  Define ErrorNumber.i
  
  ; for linux
  
  ErrorNumber = PeekL(errno_location()) 
  ErrorMessage$ = PeekS(strerror_(ErrorNumber), -1, #PB_Ascii)
  
  ProcedureReturn ErrorMessage$
EndProcedure