bool BindAcceptor(Variant node)
{
//1. Get the chain
var chain = ProtocolFactoryManager.ResolveProtocolChain(node[CONF_PROTOCOL]);
if (chain.Count == 0)
{
WARN("Invalid protocol chain: {0}",node[CONF_PROTOCOL]);
}
//2. Is it TCP or UDP based?
if (chain[0] == ProtocolTypes.PT_TCP)
{
//3. This is a tcp acceptor. Instantiate it and start accepting connections
var pAcceptor = new TCPAcceptor( node[CONF_IP], node[CONF_PORT], node, chain);
if (!pAcceptor.Bind())
{
FATAL("Unable to fire up acceptor from this config node:{0}",node.ToString());
return false;
}
acceptors.Add(pAcceptor);
return true;
}
else if (chain[0] == ProtocolTypes.PT_UDP)
{
//4. Ok, this is an UDP acceptor. Because of that, we can instantiate
//the full stack. Get the stack first
var pProtocol = ProtocolFactoryManager.CreateProtocolChain(chain, node);
if (pProtocol == null)
{
FATAL("Unable to instantiate protocol stack {0}", node[CONF_PROTOCOL]);
return false;
}
//5. Create the carrier and bind it
var pUDPCarrier = UDPCarrier.Create(node[CONF_IP], node[CONF_PORT], pProtocol);
if (pUDPCarrier == null)
{
FATAL("Unable to instantiate UDP carrier on {0}:{1}", node[CONF_IP],
node[CONF_PORT]);
pProtocol.EnqueueForDelete();
return false;
}
pUDPCarrier.Parameters = node;
acceptors.Add(pUDPCarrier);
return true;
}
else
{
FATAL("Invalid carrier type");
return false;
}
}