-
-
Save bvanderveen/1002827 to your computer and use it in GitHub Desktop.
BeginSend Socket Test Mon
This file contains hidden or 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
/* | |
I have a piece of .NET code that uses Asynchronous sockets that I want to cross | |
compile and run on Mono, however, when I attempt to run it, the AsyncCallback for | |
the BeginSend never gets called. I've boiled down the problem to a very simple | |
example. The example does not ever hit the callback, I have tried the following | |
configurations: | |
OS: Ubuntu 10.10 (Maverick Meerkat) | |
Mono 2.8.2 using Nathan Bridgewater's install shell script | |
Mono 2.10.2 using Nathan Bridgewater's updated shell script | |
Both using MonoDevelop F5 and compiling in MonoDevelop but running in the console | |
The behavior of the mono versions is slightly different: | |
- Using 2.8: The console hangs, never invokes the callback and never exits | |
- Using 2.10: The console exits but does not invoke the callback | |
In both cases, the Socket error code reports Success. | |
Note: This is a client, not a server. | |
*/ | |
using System; | |
using System.Net.Sockets; | |
namespace BeginSendSocketTest | |
{ | |
class MainClass | |
{ | |
static ManualResetEvent wh; | |
public static void Main (string[] args) | |
{ | |
wh = new ManualResetEvent(false); | |
var packet = new byte[4]; | |
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); | |
socket.Connect("localhost",11211); | |
SocketError errorCode; | |
socket.BeginSend(packet,0,packet.Length,SocketFlags.None,out errorCode,OnDataSent,socket); | |
Console.WriteLine("status: " + errorCode.ToString()); | |
wh.WaitOne(); | |
wh.Dispose(); | |
} | |
public static void OnDataSent(IAsyncResult result) | |
{ | |
try | |
{ | |
Console.WriteLine("Callback has been invoked."); | |
var socket = (Socket)result.AsyncState; | |
var sent = socket.EndSend(result); | |
Console.WriteLine(sent + "bytes sent"); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine("Exception from EndSend"); | |
} | |
wh.Set(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just wanted to try to unify flow behavior across versions…