protected override void serveClient(Protocol.BaseProcessor processor) { Thread t = new Thread(threadproc); t.Start(processor); //client_threads.Add(t); }
virtual public void Serve() { while (true) { ITransport transport = transportFactory.Accept(); Protocol.BaseProcessor processor = processorFactory.Create(transport); serveClient(processor); } }
public override void Serve() { TcpListener listener = ((SocketTransportFactory)transportFactory).listener; IPEndPoint ep = (IPEndPoint)listener.LocalEndpoint; System.Console.Out.Write("AGNOS\n{0}\n{1}\n", ep.Address, ep.Port); System.Console.Out.Flush(); // XXX: i can't seem to find a way to actually close the underlying // filedesc, so we have to use readline() instead of read() // because read() will block indefinitely System.Console.Out.Close(); ITransport transport = transportFactory.Accept(); transportFactory.Close(); Protocol.BaseProcessor processor = processorFactory.Create(transport); handleClient(processor); }
/// <summary> /// the basic client handler -- calls processor.process in a loop, /// until the client disconnects /// </summary> /// <param name="processor"> /// the processor instance that represents the client /// </param> protected static void handleClient(Protocol.BaseProcessor processor) { try { while (true) { processor.process(); } } catch (EndOfStreamException) { // finish on EOF } catch (IOException) { // usually a "connection reset by peer" -- just clean up nicely, // the connection is dead anyway } finally { processor.Close(); } }
/// <summary> /// implement this method to serve the client in whatever which way /// is appropriate (blocking, threaded, forking, threadpool, ...) /// </summary> /// <param name="processor"> /// the processor instance that represents the client /// </param> protected abstract void serveClient(Protocol.BaseProcessor processor);
protected override void serveClient(Protocol.BaseProcessor processor) { throw new InvalidOperationException("should never be called"); }
protected override void serveClient(Protocol.BaseProcessor processor) { handleClient(processor); }