#include <TLI_Acceptor.h>
Inheritance diagram for ACE_TLI_Acceptor:


Public Types | |
| typedef ACE_INET_Addr | PEER_ADDR |
| typedef ACE_TLI_Stream | PEER_STREAM |
Public Methods | |
| ACE_TLI_Acceptor (void) | |
| Default constructor. More... | |
| ACE_TLI_Acceptor (const ACE_Addr &remote_sap, int reuse_addr=0, int oflag=O_RDWR, struct t_info *info=0, int backlog=ACE_DEFAULT_BACKLOG, const char device[]=ACE_TLI_TCP_DEVICE) | |
| Initiate a passive mode socket. More... | |
| ACE_HANDLE | open (const ACE_Addr &remote_sap, int reuse_addr=0, int oflag=O_RDWR, struct t_info *info=0, int backlog=ACE_DEFAULT_BACKLOG, const char device[]=ACE_TLI_TCP_DEVICE) |
| Initiate a passive mode socket. More... | |
| int | close (void) |
| Close down the acceptor and release resources. More... | |
| int | accept (ACE_TLI_Stream &new_tli_sap, ACE_Addr *remote_addr=0, ACE_Time_Value *timeout=0, int restart=1, int reset_new_handle=0, int rwflag=1, netbuf *udata=0, netbuf *opt=0) |
| void | dump (void) const |
| Dump the state of an object. More... | |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. More... | |
Private Methods | |
| int | handle_async_event (int restart, int rwflag) |
| Handle TLI accept insanity... More... | |
Private Attributes | |
| const char * | device_ |
| Network "device" we are using. More... | |
| int | backlog_ |
| Number of connections to queue. More... | |
| int | rwflag_ |
| Are we using "tirdwr" mod? More... | |
| ACE_TLI_Request_Queue * | queue_ |
| Used for queueing up pending requests. More... | |
| t_discon * | disp_ |
| Used for handling disconnects. More... | |
Friends | |
| class | ACE_Request_Queue |
This class implements the algorithm described in Steve Rago's book on System V UNIX network programming. It basically makes TLI look like the C++ SOCK_SAP socket wrappers with respect to establishing passive-mode listener endpoints.
Definition at line 42 of file TLI_Acceptor.h.
|
|
Definition at line 87 of file TLI_Acceptor.h. |
|
|
Definition at line 88 of file TLI_Acceptor.h. |
|
|
Default constructor.
Definition at line 106 of file TLI_Acceptor.cpp. References ACE_TRACE.
|
|
||||||||||||||||||||||||||||
|
Initiate a passive mode socket.
Definition at line 386 of file TLI_Acceptor.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, and open.
00392 {
00393 ACE_TRACE ("ACE_TLI_Acceptor::ACE_TLI_Acceptor");
00394 if (this->open (remote_sap,
00395 reuse_addr,
00396 oflag,
00397 info,
00398 back,
00399 dev) == ACE_INVALID_HANDLE)
00400 ACE_ERROR ((LM_ERROR,
00401 ACE_LIB_TEXT ("%p\n"),
00402 ACE_LIB_TEXT ("ACE_TLI_Acceptor::ACE_TLI_Acceptor")));
00403 }
|
|
||||||||||||||||||||||||||||||||||||
|
Accept a new data transfer connection. A <timeout> of 0 means block forever, a <timeout> of {0, 0} means poll. <restart> == 1 means "restart if interrupted." Definition at line 453 of file TLI_Acceptor.cpp. References ACE_TRACE, ACE_TLI_Request_Queue::alloc, ACE_TLI_Request::callp_, ACE_TLI_Request_Queue::dequeue, device_, EWOULDBLOCK, ACE_TLI_Request_Queue::free, ACE_IPC_SAP::get_handle, ACE_TLI_Request::handle_, handle_async_event, ACE::handle_timed_accept, ACE_TLI_Request_Queue::is_empty, ACE_OS_String::memcpy, open_new_endpoint, queue_, ACE_Addr::set_addr, ACE_IPC_SAP::set_handle, ACE_TLI_Stream::set_rwflag, ACE_OS_TLI::t_accept, ACE_OS_TLI::t_close, and ACE_OS_TLI::t_listen.
00461 {
00462 ACE_TRACE ("ACE_TLI_Acceptor::accept");
00463 ACE_UNUSED_ARG (reset_new_handle);
00464
00465 ACE_TLI_Request *req = 0;
00466 int res = 0;
00467 if (timeout != 0
00468 && ACE::handle_timed_accept (this->get_handle (),
00469 timeout,
00470 restart) == -1)
00471 return -1;
00472 else if (this->queue_->is_empty ())
00473 {
00474 req = this->queue_->alloc ();
00475
00476 do
00477 res = ACE_OS::t_listen (this->get_handle (),
00478 req->callp_);
00479 while (res == -1
00480 && restart
00481 && errno == EINTR);
00482
00483 if (res != -1)
00484 {
00485 req->handle_ = open_new_endpoint (this->get_handle (),
00486 this->device_,
00487 req->callp_,
00488 rwf
00489 #if defined (ACE_WIN32)
00490 , remote_addr
00491 #endif /* ACE_WIN32 */
00492 );
00493 if (req->handle_ == ACE_INVALID_HANDLE)
00494 res = -1;
00495 else
00496 res = 0;
00497 }
00498 }
00499 else
00500 res = this->queue_->dequeue (req);
00501
00502 if (udata != 0)
00503 ACE_OS::memcpy ((void *) &req->callp_->udata,
00504 (void *) udata,
00505 sizeof *udata);
00506 if (opt != 0)
00507 ACE_OS::memcpy ((void *) &req->callp_->opt,
00508 (void *) opt,
00509 sizeof *opt);
00510
00511 while (res != -1)
00512 {
00513 res = ACE_OS::t_accept (this->get_handle (),
00514 req->handle_,
00515 req->callp_);
00516 if (res != -1)
00517 break; // Got one!
00518 else if (t_errno == TLOOK)
00519 res = this->handle_async_event (restart, rwf);
00520 else if (restart && t_errno == TSYSERR && errno == EINTR)
00521 res = 0;
00522 }
00523
00524 if (res == -1)
00525 {
00526 if (errno != EWOULDBLOCK)
00527 {
00528 new_tli_sap.set_handle (ACE_INVALID_HANDLE);
00529 if (req->handle_ != ACE_INVALID_HANDLE)
00530 ACE_OS::t_close (req->handle_);
00531 }
00532 }
00533 else
00534 {
00535 new_tli_sap.set_handle (req->handle_);
00536
00537 if (remote_addr != 0)
00538 remote_addr->set_addr ((void *) req->callp_->addr.buf,
00539 req->callp_->addr.len);
00540 }
00541
00542 req->handle_ = ACE_INVALID_HANDLE;
00543 this->queue_->free (req);
00544 new_tli_sap.set_rwflag (rwf);
00545 return new_tli_sap.get_handle () == ACE_INVALID_HANDLE ? -1 : 0;
00546 }
|
|
|
Close down the acceptor and release resources.
Reimplemented from ACE_TLI. Definition at line 406 of file TLI_Acceptor.cpp. References ACE_MALLOC_T, ACE_TRACE, ACE_TLI::close, ACE_TLI_Request_Queue::close, device_, disp_, ACE_OS_Memory::free, queue_, and ACE_OS_TLI::t_free. Referenced by open.
00407 {
00408 ACE_TRACE ("ACE_TLI_Acceptor::close");
00409 if (this->device_ != 0)
00410 {
00411 if (this->queue_ != 0)
00412 {
00413 this->queue_->close ();
00414 delete this->queue_;
00415 }
00416
00417 ACE_OS::t_free ((char *) this->disp_, T_DIS);
00418 ACE_OS::free (ACE_MALLOC_T (this->device_));
00419 this->disp_ = 0;
00420 this->device_ = 0;
00421 return this->ACE_TLI::close ();
00422 }
00423 return 0;
00424 }
|
|
|
Dump the state of an object.
Reimplemented from ACE_TLI. Definition at line 101 of file TLI_Acceptor.cpp. References ACE_TRACE.
00102 {
00103 ACE_TRACE ("ACE_TLI_Acceptor::dump");
00104 }
|
|
||||||||||||
|
Handle TLI accept insanity...
Definition at line 430 of file TLI_Acceptor.cpp. References ACE_TRACE, ACE_TLI_Request_Queue::enqueue, ACE_TLI::look, queue_, ACE_TLI::rcvdis, and ACE_TLI_Request_Queue::remove. Referenced by accept.
00431 {
00432 ACE_TRACE ("ACE_TLI_Acceptor::handle_async_event");
00433 int event = this->look ();
00434
00435 switch (event)
00436 {
00437 case T_DISCONNECT:
00438 this->rcvdis (this->disp_);
00439 this->queue_->remove (this->disp_->sequence);
00440 break;
00441 case T_LISTEN:
00442 this->queue_->enqueue (this->device_,
00443 restart,
00444 rwf);
00445 break;
00446 default:
00447 return -1;
00448 }
00449 return 0;
00450 }
|
|
||||||||||||||||||||||||||||
|
Initiate a passive mode socket.
Definition at line 306 of file TLI_Acceptor.cpp. References ACE_ALLOCATOR_RETURN, ACE_NEW_RETURN, ACE_TRACE, close, disp_, ACE_Addr::get_addr, ACE_IPC_SAP::get_handle, ACE_Addr::get_size, ACE_TLI::open, ACE_Addr::sap_any, ACE_TLI::set_option, ACE_OS_String::strdup, t_alloc, ACE_OS_TLI::t_bind, and t_bind. Referenced by ACE_TLI_Acceptor.
00312 {
00313 ACE_TRACE ("ACE_TLI_Acceptor::open");
00314 ACE_HANDLE res = 0;
00315 int one = 1;
00316
00317 this->disp_ = 0;
00318
00319 ACE_ALLOCATOR_RETURN (this->device_,
00320 ACE_OS::strdup (dev),
00321 ACE_INVALID_HANDLE);
00322 if (this->ACE_TLI::open (dev,
00323 oflag,
00324 info) == ACE_INVALID_HANDLE)
00325 res = ACE_INVALID_HANDLE;
00326 #if !defined (ACE_HAS_FORE_ATM_XTI)
00327 // Reusing the address causes problems with FORE's API. The issue
00328 // may be that t_optmgmt isn't fully supported by FORE. t_errno is
00329 // TBADOPT after the t_optmgmt call so maybe options are configured
00330 // differently for XTI than for TLI (at least for FORE's
00331 // implementation - XTI is supposed to be a superset of TLI).
00332 else if (reuse_addr
00333 && this->set_option (SOL_SOCKET,
00334 SO_REUSEADDR,
00335 &one,
00336 sizeof one) == -1)
00337 res = ACE_INVALID_HANDLE;
00338 #endif /* ACE_HAS_FORE_ATM_XTI */
00339 else if ((this->disp_ =
00340 (struct t_discon *) ACE_OS::t_alloc (this->get_handle (),
00341 T_DIS,
00342 T_ALL)) == 0)
00343 res = ACE_INVALID_HANDLE;
00344 else
00345 {
00346 struct t_bind req;
00347
00348 #if defined (ACE_HAS_FORE_ATM_XTI)
00349 // Not sure why but FORE's t_bind call won't work if t_bind.qlen
00350 // != 1 Adjust the backlog accordingly.
00351 this->backlog_ = 1;
00352 req.qlen = 1;
00353 #else
00354 this->backlog_ = qlen;
00355 req.qlen = qlen;
00356 #endif /* ACE_HAS_FORE_ATM_XTI */
00357 req.addr.maxlen = remote_sap.get_size ();
00358
00359 if (remote_sap == ACE_Addr::sap_any)
00360 // Note that if addr.len == 0 then ACE_TLI selects the port
00361 // number.
00362 req.addr.len = 0;
00363 else
00364 {
00365 req.addr.buf = (char *) remote_sap.get_addr ();
00366 req.addr.len = remote_sap.get_size ();
00367 }
00368
00369 res = (ACE_HANDLE) ACE_OS::t_bind (this->get_handle (),
00370 &req,
00371 0);
00372 if (res != ACE_INVALID_HANDLE)
00373 {
00374 ACE_NEW_RETURN (this->queue_,
00375 ACE_TLI_Request_Queue,
00376 ACE_INVALID_HANDLE);
00377 res = this->queue_->open (this->get_handle (),
00378 this->backlog_);
00379 }
00380 }
00381 if (res == ACE_INVALID_HANDLE)
00382 this->close ();
00383 return this->get_handle ();
00384 }
|
|
|
Definition at line 45 of file TLI_Acceptor.h. |
|
|
Declare the dynamic allocation hooks.
Reimplemented from ACE_TLI. Definition at line 94 of file TLI_Acceptor.h. |
|
|
Number of connections to queue.
Definition at line 101 of file TLI_Acceptor.h. |
|
|
Network "device" we are using.
Definition at line 98 of file TLI_Acceptor.h. |
|
|
Used for handling disconnects.
Definition at line 113 of file TLI_Acceptor.h. |
|
|
Used for queueing up pending requests.
Definition at line 110 of file TLI_Acceptor.h. Referenced by accept, close, and handle_async_event. |
|
|
Are we using "tirdwr" mod?
Definition at line 104 of file TLI_Acceptor.h. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002