Created
January 10, 2012 09:43
-
-
Save clausjoergensen/1588116 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int startTickCount = Environment.TickCount; | |
int timeout = 10000; | |
var dataSent = false; | |
var socket = tcpClient.Client; | |
while (dataSent == false) | |
{ | |
if (Environment.TickCount > startTickCount + timeout) | |
{ | |
throw new Exception("Timeout."); | |
} | |
try | |
{ | |
socket.Send(data, 0, data.Length, SocketFlags.None); | |
dataSent = true; | |
} | |
catch (SocketException e) | |
{ | |
if (e.SocketErrorCode == SocketError.WouldBlock || | |
e.SocketErrorCode == SocketError.IOPending || | |
e.SocketErrorCode == SocketError.NoBufferSpaceAvailable) | |
{ | |
Thread.Sleep(30); | |
} | |
else | |
{ | |
throw e; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment