Changeset 433

Show
Ignore:
Timestamp:
07/17/07 12:54:08 (1 year ago)
Author:
blackhedd
Message:

implemented EventMachine#stop_server

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • version_0/ext/cmain.cpp

    r414 r433  
    169169                throw std::runtime_error ("not initialized"); 
    170170        ConnectionDescriptor::CloseConnection (binding, (after_writing ? true : false)); 
     171} 
     172 
     173/******************** 
     174evma_stop_tcp_server 
     175********************/ 
     176 
     177extern "C" void evma_stop_tcp_server (const char *binding) 
     178{ 
     179        if (!EventMachine) 
     180                throw std::runtime_error ("not initialized"); 
     181        AcceptorDescriptor::StopAcceptor (binding); 
    171182} 
    172183 
  • version_0/ext/ed.cpp

    r407 r433  
    778778} 
    779779 
     780/**************************************** 
     781STATIC: AcceptorDescriptor::StopAcceptor 
     782****************************************/ 
     783 
     784void AcceptorDescriptor::StopAcceptor (const char *binding) 
     785{ 
     786        // TODO: This is something of a hack, or at least it's a static method of the wrong class. 
     787        AcceptorDescriptor *ad = dynamic_cast <AcceptorDescriptor*> (Bindable_t::GetObject (binding)); 
     788        if (ad) 
     789                ad->ScheduleClose (false); 
     790        else 
     791                throw std::runtime_error ("failed to close nonexistent acceptor"); 
     792} 
     793 
    780794 
    781795/************************ 
  • version_0/ext/ed.h

    r407 r433  
    256256                virtual bool SelectForRead() {return true;} 
    257257                virtual bool SelectForWrite() {return false;} 
     258 
     259                static void StopAcceptor (const char *binding); 
    258260}; 
    259261 
  • version_0/ext/eventmachine.h

    r414 r433  
    4040        const char *evma_connect_to_server (const char *server, int port); 
    4141        const char *evma_connect_to_unix_server (const char *server); 
     42        void evma_stop_tcp_server (const char *signature); 
    4243        const char *evma_create_tcp_server (const char *address, int port); 
    4344        const char *evma_create_unix_domain_server (const char *filename); 
  • version_0/ext/rubymain.cpp

    r414 r433  
    9191                rb_raise (rb_eRuntimeError, "no acceptor"); 
    9292        return rb_str_new2 (f); 
     93} 
     94 
     95/************* 
     96t_stop_server 
     97*************/ 
     98 
     99static VALUE t_stop_server (VALUE self, VALUE signature) 
     100{ 
     101        evma_stop_tcp_server (StringValuePtr (signature)); 
     102        return Qnil; 
    93103} 
    94104 
     
    421431        rb_define_module_function (EmModule, "add_oneshot_timer", (VALUE(*)(...))t_add_oneshot_timer, 1); 
    422432        rb_define_module_function (EmModule, "start_tcp_server", (VALUE(*)(...))t_start_server, 2); 
     433        rb_define_module_function (EmModule, "stop_tcp_server", (VALUE(*)(...))t_stop_server, 1); 
    423434        rb_define_module_function (EmModule, "start_unix_server", (VALUE(*)(...))t_start_unix_server, 1); 
    424435        rb_define_module_function (EmModule, "start_tls", (VALUE(*)(...))t_start_tls, 1); 
  • version_0/lib/eventmachine.rb

    r417 r433  
    475475    s = start_tcp_server server, port 
    476476    @acceptors[s] = [klass,block] 
     477    s 
    477478  end 
    478479 
     480 
     481  # Stop a TCP server socket that was started with EventMachine#start_server. 
     482  #-- 
     483  # Requested by Kirk Haines. TODO, this isn't OOP enough. We ought somehow 
     484  # to have #start_server return an object that has a close or a stop method on it. 
     485  # 
     486  def EventMachine::stop_server signature 
     487          EventMachine::stop_tcp_server signature 
     488  end 
    479489 
    480490  def EventMachine::start_unix_domain_server filename, handler=nil, &block 
  • version_0/Rakefile

    r412 r433  
    263263end 
    264264 
     265desc "Test Servers" 
     266task :test_servers do |t| 
     267  run_tests t, :extension, "test_servers*.rb" 
     268end 
     269 
    265270 
    266271desc "Build everything"