Exception
Code:
System.Net.Sockets.SocketException (0x80004005): An operation was attempted on s omething that is not a socket at System.Net.Sockets.Socket.Select(IList checkRead, IList checkWrite, IList checkError, Int32 microSeconds) at ClassicConquer.Necessaries.ServerSockets.SocketPoll.CheckUp() in d:\Source\ServerSockets\SocketPoll.cs:line 55
Code:
public static class SocketPoll
{
const int SOCKET_PROCESS_INTERVAL = 20, FD_SETSIZE = 2048;
public readonly static SafeCollections.SafeList<SecuritySocket> ConnectionPoll = new SafeCollections.SafeList<SecuritySocket>();
private static ServerSocket[] Sockets;
public static void Create(string group, params ServerSocket[] _Sockets)
{
Sockets = _Sockets;
var ThreadItem = new ThreadGroup.ThreadItem(SOCKET_PROCESS_INTERVAL, group, CheckUp);
ThreadItem.Open();
}
public static void CheckUp()
{
try
{
List<Socket> RecSockets = new List<Socket>();
/// List<Socket> SendSockets = new List<Socket>();
// List<Socket> ErrorSockets = new List<Socket>();
if (ConnectionPoll.Count > 0 || Sockets.Length > 0)
{
System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
timer.Start();
foreach (var socket in Sockets)
{
if (socket == null || socket.IsAlive == false)
continue;
RecSockets.Add(socket.GetConnection);
}
foreach (var socket in ConnectionPoll.GetValues())
{
if (socket.Alive)
{
RecSockets.Add(socket.Connection);
}
}
// IntPtr[] readmask = null;
try
{
Socket.Select(RecSockets, null, null, 0);
// int test = WindowsAPI.ws2_32.MySocketSelect(FD_SETSIZE, RecSockets, 100, out readmask);
}
catch (Exception e)
{
MyConsole.WriteLine(e.ToString());
MyConsole.SaveException(e);
}
foreach (var socket in ConnectionPoll.GetValues())
{
try
{
// if (readmask != null && WindowsAPI.ws2_32.FD_ISSET(readmask, socket.Connection.Handle))
if (RecSockets.Contains(socket.Connection))
socket.ReceiveBuffer();
socket.HandlerBuffer();
while (SecuritySocket.TrySend(socket)) ;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
foreach (var socket in Sockets)
{
try
{
if (socket == null)
continue;
//if (readmask != null && WindowsAPI.ws2_32.FD_ISSET(readmask, socket.GetConnection.Handle))
if (RecSockets.Contains(socket.GetConnection))
socket.Accept();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
timer.Stop();
if (timer.ElapsedMilliseconds > 100)
{
//Console.WriteLine("stamp -> " + timer.ElapsedMilliseconds);
}
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}






