#include <Acceptor.h>
Inheritance diagram for ASSA::Acceptor< SERVICE_HANDLER, PEER_ACCEPTOR >:
Public Member Functions | |
Acceptor (Reactor *r_) | |
Default constructor. | |
virtual | ~Acceptor () |
Do-nothing destructor. | |
virtual int | open (const Address &local_addr_) |
Initialize listener endpoint and Acceptor with Reactor. | |
virtual int | close (void) |
Close PEER_ACCEPTOR stream. | |
int | handle_read (int fd) |
Callback invoked by Reactor when new connection requests is detected. | |
virtual int | handle_close (int fd) |
Callback invoked by Reactor if PEER_ACCEPTOR stream went bad, or Reactor has been commanded to stop event processing. | |
Protected Member Functions | |
virtual SERVICE_HANDLER * | makeServiceHandler (PEER_ACCEPTOR *sock_) |
Defines creation strategy for ServiceHandler. | |
virtual int | acceptServiceHandler (PEER_ACCEPTOR *&new_socket_) |
Default strategy is to accept new connection. | |
virtual int | activateServiceHandler (PEER_ACCEPTOR *new_socket_) |
Defines the concurrency strategy. | |
Protected Attributes | |
PEER_ACCEPTOR | m_listenSocket |
Underlying communication stream. | |
Private Attributes | |
Reactor * | m_reactor |
Reactor to use. |
Definition at line 43 of file Acceptor.h.
|
Default constructor.
Definition at line 144 of file Acceptor.h. References trace.
|
|
Do-nothing destructor. Underlying PEER_ACCEPTOR stream will be closed during its own destruction sequence. Definition at line 153 of file Acceptor.h. References trace. 00154 { 00155 trace("Acceptor::~Acceptor"); 00156 }
|
|
Default strategy is to accept new connection. Derived class can change this strategy by overloading this method.
Definition at line 198 of file Acceptor.h. References ASSA::Acceptor< SERVICE_HANDLER, PEER_ACCEPTOR >::m_listenSocket, and trace. Referenced by ASSA::Acceptor< SERVICE_HANDLER, PEER_ACCEPTOR >::handle_read(). 00199 { 00200 trace("Acceptor::acceptServiceHandler"); 00201 00202 new_socket_ = m_listenSocket.accept (); 00203 return new_socket_ ? 0 : -1; 00204 }
|
|
Defines the concurrency strategy. Default is to create SERVICE_HANDLERin current process(thread), call its open() methid and let Reactor handle its I/O events. Derived class changes this strategy by overloading this class.
Definition at line 208 of file Acceptor.h. References ASSA::Acceptor< SERVICE_HANDLER, PEER_ACCEPTOR >::makeServiceHandler(), SH, and trace. Referenced by ASSA::Acceptor< SERVICE_HANDLER, PEER_ACCEPTOR >::handle_read(). 00209 { 00210 trace("Acceptor::activateServiceHandler"); 00211 00212 if (!new_socket_) { 00213 return -1; 00214 } 00215 SH* sh = makeServiceHandler (new_socket_); 00216 sh->open (); 00217 return 0; 00218 }
|
|
Close PEER_ACCEPTOR stream.
Definition at line 161 of file Acceptor.h. References ASSA::Acceptor< SERVICE_HANDLER, PEER_ACCEPTOR >::m_listenSocket, and trace. 00162 { 00163 trace("Acceptor::close"); 00164 m_listenSocket.close (); 00165 return 0; 00166 }
|
|
Callback invoked by Reactor if PEER_ACCEPTOR stream went bad, or Reactor has been commanded to stop event processing. This method should always return -1, if stream cannot be repared. Derived class can change this strategy by overloading this method. If called object is other then Reactor, an explicit call to Reactor::removeHandler (this->id()) is required. By default behavior, Acceptor will destroy itself.
Reimplemented from ASSA::EventHandler. Definition at line 171 of file Acceptor.h. References DL, ASSA::EventHandler::get_id(), ASSA::REACT, and trace. 00172 { 00173 trace("Acceptor::handle_close"); 00174 00175 // Reactor::get_instance ()->removeHandler (this->id()); 00176 00177 // NOT IMPLEMENTED: This spot requires validation 00178 // whether Acceptor is created on the heap or in 00179 // automatic memory. 00180 DL ((REACT,"Deleted acceptor \"%s\"\n", get_id ().c_str ())); 00181 delete this; 00182 return -1; 00183 }
|
|
Callback invoked by Reactor when new connection requests is detected. Default strategy is to accept ALL awaiting incoming connections at once. Derived class can change this strategy by overloading this method.
Reimplemented from ASSA::EventHandler. Definition at line 250 of file Acceptor.h. References ASSA::Acceptor< SERVICE_HANDLER, PEER_ACCEPTOR >::acceptServiceHandler(), ASSA::Acceptor< SERVICE_HANDLER, PEER_ACCEPTOR >::activateServiceHandler(), ASSA::Acceptor< SERVICE_HANDLER, PEER_ACCEPTOR >::m_listenSocket, PA, ASSA::FdSet::reset(), ASSA::FdSet::setFd(), and trace. 00251 { 00252 trace("Acceptor<>::handle_read"); 00253 00254 FdSet mask; 00255 timeval poll = {0, 0}; 00256 PA* new_socket = 0; 00257 00258 int fd = m_listenSocket.getHandler (); 00259 00260 if (fd != fd_) { 00261 return -1; 00262 } 00263 00264 do { 00265 if ( acceptServiceHandler (new_socket) == -1 ) { 00266 return -1; 00267 } 00268 if ( !activateServiceHandler (new_socket) == -1 ) { 00269 return -1; 00270 } 00271 mask.reset (); 00272 mask.setFd (fd); 00273 } 00274 while ((::select (fd+1, &mask, NULL, NULL, &poll) == 1)); 00275 00276 return 0; 00277 }
|
|
Defines creation strategy for ServiceHandler.
Definition at line 188 of file Acceptor.h. References trace. Referenced by ASSA::Acceptor< SERVICE_HANDLER, PEER_ACCEPTOR >::activateServiceHandler(). 00189 { 00190 trace("Acceptor<>::makeServiceHandler"); 00191 00192 return new SERVICE_HANDLER (sock_); 00193 }
|
|
Initialize listener endpoint and Acceptor with Reactor. Derive classes can change this strategy by overloading this method.
Definition at line 222 of file Acceptor.h. References ASSA::Address::getAddress(), ASSA::Acceptor< SERVICE_HANDLER, PEER_ACCEPTOR >::m_listenSocket, and trace. 00223 { 00224 trace("Acceptor::open"); 00225 00226 if ( !m_listenSocket.open (local_addr_.getAddress ()->sa_family) ) { 00227 return -1; 00228 } 00229 00230 if ( !m_listenSocket.bind (local_addr_) ) { 00231 return -1; 00232 } 00233 00234 m_reactor->registerIOHandler ( 00235 this, m_listenSocket.getHandler (), READ_EVENT); 00236 00237 DL((TRACE,"Opened acceptor for fd=%d\n", 00238 m_listenSocket.getHandler ())); 00239 00240 return 0; 00241 }
|
|
Underlying communication stream.
Definition at line 123 of file Acceptor.h. Referenced by ASSA::Acceptor< SERVICE_HANDLER, PEER_ACCEPTOR >::acceptServiceHandler(), ASSA::Acceptor< SERVICE_HANDLER, PEER_ACCEPTOR >::close(), ASSA::Acceptor< SERVICE_HANDLER, PEER_ACCEPTOR >::handle_read(), and ASSA::Acceptor< SERVICE_HANDLER, PEER_ACCEPTOR >::open(). |
|
Reactor to use.
Definition at line 129 of file Acceptor.h. |