Page 1 of 1

Network TCP/IP CheckReceiveLength (All OS)

Posted: Sun Apr 23, 2023 1:51 pm
by mk-soft

Code: Select all

;-TOP by mk-soft, v1.01.2, 23.04.2023

; Only TCP/IP
; Len = CheckReceiveLength(ConnectionID(Client))

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux
    #FIONREAD = $0000541B
  CompilerCase #PB_OS_MacOS
    #FIONREAD = $4004667F
CompilerEndSelect

Procedure CheckReceiveLength(Socket)
  Protected length, result
  
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows
      result = ioctlsocket_(Socket, #FIONREAD, @length)
      
    CompilerCase #PB_OS_Linux
      result = ioctl_(Socket, #FIONREAD, @length)
      
    CompilerCase #PB_OS_MacOS
      result = ioctl_(Socket, #FIONREAD, @length)
      
  CompilerEndSelect
  
  If result <> 0
    ProcedureReturn -1; socket error
  EndIf
  
  ProcedureReturn length
EndProcedure