SelectionKey key = (SelectionKey)it.next();
// What kind of activity is it?
if ((key.readyOps() & SelectionKey.OP_READ) == SelectionKey.OP_READ)
{
SocketChannel ch = (SocketChannel)key.channel();
java.net.Socket ss = (java.net.Socket)ch.socket();
Socket s = (Socket)key.attachment();
if (s != null)
{
// System.out.println(s + ": OnRead");
s.OnRead();
if (s.LineProtocol())
{
s.ReadLine(); // eat ibuf to m_line, calls OnLine
}
}
}
if ((key.readyOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE)
{
SocketChannel ch = (SocketChannel)key.channel();
java.net.Socket ss = (java.net.Socket)ch.socket();
Socket s = (Socket)key.attachment();
if (s != null)
{
// System.out.println(s + ": OnWrite");
s.OnWrite();
}
}
if ((key.readyOps() & SelectionKey.OP_ACCEPT) == SelectionKey.OP_ACCEPT)
{
ServerSocketChannel ch = (ServerSocketChannel)key.channel();
java.net.ServerSocket ss = (java.net.ServerSocket)ch.socket();
Socket s = (Socket)key.attachment();
if (s != null)
{
// System.out.println(s + ": OnRead(ACCEPT)");
s.OnRead(); // ListenSocket.OnRead will call OnAccept on new Socket
}
}
if ((key.readyOps() & SelectionKey.OP_CONNECT) == SelectionKey.OP_CONNECT)
{
SocketChannel ch = (SocketChannel)key.channel();
java.net.Socket ss = (java.net.Socket)ch.socket();
Socket s = (Socket)key.attachment();
if (s != null)
{
// System.out.println(s + ": OnConnect");
ch.finishConnect();
s.SetConnecting(false);
s.GetKey().interestOps(SelectionKey.OP_READ);
s.OnConnect();
}
}