Race condition fix

This commit is contained in:
Aragas 2016-09-12 19:10:55 +03:00
parent 01978a2399
commit 5690a27219
4 changed files with 20 additions and 4 deletions

View File

@ -604,7 +604,7 @@ Namespace GameJolt
request.ContentType = "application/x-www-form-urlencoded"
request.ServicePoint.Expect100Continue = False
Dim writer As StreamWriter = New StreamWriter(request.GetRequestStream())
Dim writer As StreamWriterLock = New StreamWriterLock(request.GetRequestStream())
writer.Write(post)
writer.Close()
Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)

View File

@ -14,7 +14,7 @@ Namespace Servers
Private _stream As NetworkStream
Private _streamReader As StreamReader
Private _streamWriter As StreamWriter
Private _streamWriter As StreamWriterLock
Private _receiveThread As Threading.Thread
@ -69,7 +69,7 @@ Namespace Servers
'Send GameData package first:
Me._stream = Me._client.GetStream()
Me._streamReader = New StreamReader(Me._stream)
Me._streamWriter = New StreamWriter(Me._stream)
Me._streamWriter = New StreamWriterLock(Me._stream)
Core.ServersManager.PlayerManager.Reset()
Dim initialPlayerData As String = Core.ServersManager.PlayerManager.CreatePlayerDataPackage().ToString()

View File

@ -0,0 +1,16 @@
Imports System.IO
Public Class StreamWriterLock
Inherits StreamWriter
Private _lock As New Object()
Public Sub New(stream As Stream)
MyBase.New(stream)
End Sub
Public Overrides Sub Write(value As Char)
SyncLock _lock
MyBase.Write(value)
End SyncLock
End Sub
End Class

View File

@ -460,7 +460,7 @@ Public Class JoinServerScreen
Dim Stream As NetworkStream = client.GetStream()
Dim streamr As StreamReader = New StreamReader(Stream)
Dim streamw As StreamWriter = New StreamWriter(Stream)
Dim streamw As StreamWriterLock = New StreamWriterLock(Stream)
streamw.WriteLine(New Servers.Package(Servers.Package.PackageTypes.ServerDataRequest, -1, Servers.Package.ProtocolTypes.TCP, "r").ToString())
streamw.Flush()