Browse Source

Added ShutdownSocket().

Brucey 4 years ago
parent
commit
c1435fc0f3
1 changed files with 26 additions and 1 deletions
  1. 26 1
      socket.mod/socket.bmx

+ 26 - 1
socket.mod/socket.bmx

@@ -6,12 +6,14 @@ bbdoc: Networking/Sockets
 End Rem
 End Rem
 Module BRL.Socket
 Module BRL.Socket
 
 
-ModuleInfo "Version: 1.04"
+ModuleInfo "Version: 1.05"
 ModuleInfo "Author: Mark Sibly and Bruce A Henderson"
 ModuleInfo "Author: Mark Sibly and Bruce A Henderson"
 ModuleInfo "License: zlib/libpng"
 ModuleInfo "License: zlib/libpng"
 ModuleInfo "Copyright: Blitz Research Ltd"
 ModuleInfo "Copyright: Blitz Research Ltd"
 ModuleInfo "Modserver: BRL"
 ModuleInfo "Modserver: BRL"
 
 
+ModuleInfo "History: 1.05"
+ModuleInfo "History: Added ShutdownSocket()."
 ModuleInfo "History: 1.04"
 ModuleInfo "History: 1.04"
 ModuleInfo "History: Fixed for Android."
 ModuleInfo "History: Fixed for Android."
 ModuleInfo "History: 1.03"
 ModuleInfo "History: 1.03"
@@ -182,6 +184,13 @@ Type TSocket
 		Return _remotePort
 		Return _remotePort
 	End Method
 	End Method
 	
 	
+	Method Shutdown(how:Int)
+		If _socket < 0 Then
+			Return
+		End If
+		shutdown_(_socket, how)
+	End Method
+	
 	Method UpdateLocalName:Int()
 	Method UpdateLocalName:Int()
 		If bmx_stdc_getsockname(_socket, _localPort, _localIp) < 0 Then
 		If bmx_stdc_getsockname(_socket, _localPort, _localIp) < 0 Then
 			Return False
 			Return False
@@ -441,4 +450,20 @@ Function AddrInfo:TAddrInfo[](host:String, service:String, hints:TAddrInfo)
 	Return getaddrinfo_hints(host, service, hints.infoPtr)
 	Return getaddrinfo_hints(host, service, hints.infoPtr)
 End Function
 End Function
 
 
+Rem
+bbdoc: Disables sends or receives on a socket.
+about: Typically, #ShutdownSocket should be called before #CloseSocket to assure that all data is sent
+and received on a connected socket before it is closed.
 
 
+@how is one of the following options :
+
+| Value      | Meaning                                   |
+|------------|-------------------------------------------|
+| SD_RECEIVE | Shutdown receive operations               |
+| SD_SEND    | Shutdown send operations                  |
+| SD_BOTH    | Shutdown both send and receive operations |
+
+End Rem
+Function ShutdownSocket( socket:TSocket, how:Int=SD_SEND )
+	socket.Shutdown(how)
+End Function