public bool Connect(IPAddress address, int port)
{
Print("Begin connecting to {0}:{1}", address, port);
try
{
m_socket.Connect(new IPEndPoint(address, port));
}
catch (SocketException)
{
// ignore blocking connect exception. shouldn't there be some other way to do this...
//Console.WriteLine("exc cont");
}
m_writeCS.Enter();
m_writingThread = MicroThread.CurrentThread;
m_writingThread.Wait();
m_writingThread = null;
m_writeCS.Exit();
//Console.WriteLine("STATE {0}", m_waitState);
if ((m_selectStatus & MicroSocketSelectStatus.Error) != 0)
{
Console.WriteLine("Connect failed");
return false;
}
else if ((m_selectStatus & MicroSocketSelectStatus.Write) != 0)
{
//Console.WriteLine("Connected!");
return true;
}
else
{
throw new Exception("illegal state");
}
}