--- /dev/null
+# $Id$\r
+#\r
+# Author:: Francis Cianfrocca (gmail: blackhedd)\r
+# Homepage:: http://rubyeventmachine.com\r
+# Date:: 19 May 2006\r
+# \r
+# See EventMachine and EventMachine::Connection for documentation and\r
+# usage examples.\r
+#\r
+#----------------------------------------------------------------------------\r
+#\r
+# Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.\r
+# Gmail: blackhedd\r
+# \r
+# This program is free software; you can redistribute it and/or modify\r
+# it under the terms of either: 1) the GNU General Public License\r
+# as published by the Free Software Foundation; either version 2 of the\r
+# License, or (at your option) any later version; or 2) Ruby's License.\r
+# \r
+# See the file COPYING for complete licensing information.\r
+#\r
+#---------------------------------------------------------------------------\r
+#\r
+\r
+\r
+module Evma\r
+class ProtocolFactory < Protocol\r
+\r
+ #--\r
+ # default implementation raises an exception.\r
+ # we expect subclasses to override this.\r
+ # we can't do anything reasonable here because\r
+ def accept new_object\r
+ # don't bother calling Evma::Reactor.instance, since only Reactor can call accept\r
+ Evma::Container.store Evma::Protocol.new( new_object )\r
+ EventMachine.close_connection new_object, false\r
+ end\r
+\r
+\r
+end # class ProtocolFactory\r
+end # module Evma\r
+\r
+######################################\r
+\r
+module Evma\r
+class TcpSocket\r
+\r
+ def self.connect server, port, protocol_handler = Evma::Protocol\r
+ Evma::Reactor.instance # ensure initialization\r
+ sig = EventMachine.connect_server server, port\r
+ Evma::Container.store protocol_handler.new( sig )\r
+ end\r
+\r
+end\r
+end # module Evma\r
+\r
+######################################\r
+\r
+module Evma\r
+class TcpServerFactory < Evma::ProtocolFactory\r
+\r
+ def initialize server, port, protocol_handler = Evma::Protocol\r
+ Evma::Reactor.instance # ensure initialization\r
+ sig = EventMachine.start_tcp_server server, port\r
+ super sig\r
+ @protocol_handler = protocol_handler\r
+ Evma::Container.store self\r
+ end\r
+\r
+ def accept new_obj\r
+ # don't bother calling Evma::Reactor.instance, since only Reactor can call accept\r
+ Evma::Container.store @protocol_handler.new( new_obj )\r
+ end\r
+\r
+end\r
+end # module Evma\r
+\r