#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 Member Functions | |
| ACE_TLI_Acceptor (void) | |
| Default constructor. | |
| 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. | |
| 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. | |
| int | close (void) |
| Close down the acceptor and release resources. | |
| 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. | |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. | |
Private Member Functions | |
| int | handle_async_event (int restart, int rwflag) |
| Handle TLI accept insanity... | |
Private Attributes | |
| const char * | device_ |
| Network "device" we are using. | |
| int | backlog_ |
| Number of connections to queue. | |
| int | rwflag_ |
| Are we using "tirdwr" mod? | |
| ACE_TLI_Request_Queue * | queue_ |
| Used for queueing up pending requests. | |
| t_discon * | disp_ |
| Used for handling disconnects. | |
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 45 of file TLI_Acceptor.h.
|
|
Definition at line 90 of file TLI_Acceptor.h. |
|
|
Definition at line 91 of file TLI_Acceptor.h. |
|
|
Default constructor.
Definition at line 113 of file TLI_Acceptor.cpp. References ACE_TRACE.
|
|
||||||||||||||||||||||||||||
|
Initiate a passive mode socket.
Definition at line 389 of file TLI_Acceptor.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, LM_ERROR, and open().
00395 {
00396 ACE_TRACE ("ACE_TLI_Acceptor::ACE_TLI_Acceptor");
00397 if (this->open (remote_sap,
00398 reuse_addr,
00399 oflag,
00400 info,
00401 back,
00402 dev) == ACE_INVALID_HANDLE)
00403 ACE_ERROR ((LM_ERROR,
00404 ACE_LIB_TEXT ("%p\n"),
00405 ACE_LIB_TEXT ("ACE_TLI_Acceptor::ACE_TLI_Acceptor")));
00406 }
|
|
||||||||||||||||||||||||||||||||||||
|
Accept a new data transfer connection. A of 0 means block forever, a of {0, 0} means poll. == 1 means "restart if interrupted." Definition at line 456 of file TLI_Acceptor.cpp. References ACE_TRACE, ACE_TLI_Request_Queue::alloc(), ACE_TLI_Request::callp_, ACE_TLI_Request_Queue::dequeue(), 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::memcpy(), open_new_endpoint(), ACE_Addr::set_addr(), ACE_IPC_SAP::set_handle(), ACE_TLI_Stream::set_rwflag(), ACE_OS::t_accept(), ACE_OS::t_close(), and ACE_OS::t_listen().
00464 {
00465 ACE_TRACE ("ACE_TLI_Acceptor::accept");
00466 ACE_UNUSED_ARG (reset_new_handle);
00467
00468 ACE_TLI_Request *req = 0;
00469 int res = 0;
00470 if (timeout != 0
00471 && ACE::handle_timed_accept (this->get_handle (),
00472 timeout,
00473 restart) == -1)
00474 return -1;
00475 else if (this->queue_->is_empty ())
00476 {
00477 req = this->queue_->alloc ();
00478
00479 do
00480 res = ACE_OS::t_listen (this->get_handle (),
00481 req->callp_);
00482 while (res == -1
00483 && restart
00484 && errno == EINTR);
00485
00486 if (res != -1)
00487 {
00488 req->handle_ = open_new_endpoint (this->get_handle (),
00489 this->device_,
00490 req->callp_,
00491 rwf
00492 #if defined (ACE_WIN32)
00493 , remote_addr
00494 #endif /* ACE_WIN32 */
00495 );
00496 if (req->handle_ == ACE_INVALID_HANDLE)
00497 res = -1;
00498 else
00499 res = 0;
00500 }
00501 }
00502 else
00503 res = this->queue_->dequeue (req);
00504
00505 if (udata != 0)
00506 ACE_OS::memcpy ((void *) &req->callp_->udata,
00507 (void *) udata,
00508 sizeof *udata);
00509 if (opt != 0)
00510 ACE_OS::memcpy ((void *) &req->callp_->opt,
00511 (void *) opt,
00512 sizeof *opt);
00513
00514 while (res != -1)
00515 {
00516 res = ACE_OS::t_accept (this->get_handle (),
00517 req->handle_,
00518 req->callp_);
00519 if (res != -1)
00520 break; // Got one!
00521 else if (t_errno == TLOOK)
00522 res = this->handle_async_event (restart, rwf);
00523 else if (restart && t_errno == TSYSERR && errno == EINTR)
00524 res = 0;
00525 }
00526
00527 if (res == -1)
00528 {
00529 if (errno != EWOULDBLOCK)
00530 {
00531 new_tli_sap.set_handle (ACE_INVALID_HANDLE);
00532 if (req->handle_ != ACE_INVALID_HANDLE)
00533 ACE_OS::t_close (req->handle_);
00534 }
00535 }
00536 else
00537 {
00538 new_tli_sap.set_handle (req->handle_);
00539
00540 if (remote_addr != 0)
00541 remote_addr->set_addr ((void *) req->callp_->addr.buf,
00542 req->callp_->addr.len);
00543 }
00544
00545 req->handle_ = ACE_INVALID_HANDLE;
00546 this->queue_->free (req);
00547 new_tli_sap.set_rwflag (rwf);
00548 return new_tli_sap.get_handle () == ACE_INVALID_HANDLE ? -1 : 0;
00549 }
|
|
|
Close down the acceptor and release resources.
Reimplemented from ACE_TLI. Definition at line 409 of file TLI_Acceptor.cpp. References ACE_MALLOC_T, ACE_TRACE, ACE_TLI::close(), ACE_TLI_Request_Queue::close(), disp_, ACE_OS::free(), and ACE_OS::t_free(). Referenced by open().
00410 {
00411 ACE_TRACE ("ACE_TLI_Acceptor::close");
00412 if (this->device_ != 0)
00413 {
00414 if (this->queue_ != 0)
00415 {
00416 this->queue_->close ();
00417 delete this->queue_;
00418 }
00419
00420 ACE_OS::t_free ((char *) this->disp_, T_DIS);
00421 ACE_OS::free (ACE_MALLOC_T (this->device_));
00422 this->disp_ = 0;
00423 this->device_ = 0;
00424 return this->ACE_TLI::close ();
00425 }
00426 return 0;
00427 }
|
|
|
Dump the state of an object.
Reimplemented from ACE_TLI. Definition at line 106 of file TLI_Acceptor.cpp. References ACE_TRACE.
00107 {
00108 #if defined (ACE_HAS_DUMP)
00109 ACE_TRACE ("ACE_TLI_Acceptor::dump");
00110 #endif /* ACE_HAS_DUMP */
00111 }
|
|
||||||||||||
|
Handle TLI accept insanity...
Definition at line 433 of file TLI_Acceptor.cpp. References ACE_TRACE, ACE_TLI_Request_Queue::enqueue(), ACE_TLI::look(), ACE_TLI::rcvdis(), and ACE_TLI_Request_Queue::remove(). Referenced by accept().
00434 {
00435 ACE_TRACE ("ACE_TLI_Acceptor::handle_async_event");
00436 int event = this->look ();
00437
00438 switch (event)
00439 {
00440 case T_DISCONNECT:
00441 this->rcvdis (this->disp_);
00442 this->queue_->remove (this->disp_->sequence);
00443 break;
00444 case T_LISTEN:
00445 this->queue_->enqueue (this->device_,
00446 restart,
00447 rwf);
00448 break;
00449 default:
00450 return -1;
00451 }
00452 return 0;
00453 }
|
|
||||||||||||||||||||||||||||
|
Initiate a passive mode socket.
Definition at line 309 of file TLI_Acceptor.cpp. References ACE_ALLOCATOR_RETURN, ACE_NEW_RETURN, ACE_TRACE, backlog_, close(), disp_, ACE_Addr::get_addr(), ACE_IPC_SAP::get_handle(), ACE_Addr::get_size(), ACE_TLI_Request_Queue::open(), ACE_TLI::open(), ACE_TLI::set_option(), ACE_OS::t_alloc(), ACE_OS::t_bind(), and t_bind(). Referenced by ACE_TLI_Acceptor().
00315 {
00316 ACE_TRACE ("ACE_TLI_Acceptor::open");
00317 ACE_HANDLE res = 0;
00318 int one = 1;
00319
00320 this->disp_ = 0;
00321
00322 ACE_ALLOCATOR_RETURN (this->device_,
00323 ACE_OS::strdup (dev),
00324 ACE_INVALID_HANDLE);
00325 if (this->ACE_TLI::open (dev,
00326 oflag,
00327 info) == ACE_INVALID_HANDLE)
00328 res = ACE_INVALID_HANDLE;
00329 #if !defined (ACE_HAS_FORE_ATM_XTI)
00330 // Reusing the address causes problems with FORE's API. The issue
00331 // may be that t_optmgmt isn't fully supported by FORE. t_errno is
00332 // TBADOPT after the t_optmgmt call so maybe options are configured
00333 // differently for XTI than for TLI (at least for FORE's
00334 // implementation - XTI is supposed to be a superset of TLI).
00335 else if (reuse_addr
00336 && this->set_option (SOL_SOCKET,
00337 SO_REUSEADDR,
00338 &one,
00339 sizeof one) == -1)
00340 res = ACE_INVALID_HANDLE;
00341 #endif /* ACE_HAS_FORE_ATM_XTI */
00342 else if ((this->disp_ =
00343 (struct t_discon *) ACE_OS::t_alloc (this->get_handle (),
00344 T_DIS,
00345 T_ALL)) == 0)
00346 res = ACE_INVALID_HANDLE;
00347 else
00348 {
00349 struct t_bind req;
00350
00351 #if defined (ACE_HAS_FORE_ATM_XTI)
00352 // Not sure why but FORE's t_bind call won't work if t_bind.qlen
00353 // != 1 Adjust the backlog accordingly.
00354 this->backlog_ = 1;
00355 req.qlen = 1;
00356 #else
00357 this->backlog_ = qlen;
00358 req.qlen = qlen;
00359 #endif /* ACE_HAS_FORE_ATM_XTI */
00360 req.addr.maxlen = remote_sap.get_size ();
00361
00362 if (remote_sap == ACE_Addr::sap_any)
00363 // Note that if addr.len == 0 then ACE_TLI selects the port
00364 // number.
00365 req.addr.len = 0;
00366 else
00367 {
00368 req.addr.buf = (char *) remote_sap.get_addr ();
00369 req.addr.len = remote_sap.get_size ();
00370 }
00371
00372 res = (ACE_HANDLE) ACE_OS::t_bind (this->get_handle (),
00373 &req,
00374 0);
00375 if (res != ACE_INVALID_HANDLE)
00376 {
00377 ACE_NEW_RETURN (this->queue_,
00378 ACE_TLI_Request_Queue,
00379 ACE_INVALID_HANDLE);
00380 res = this->queue_->open (this->get_handle (),
00381 this->backlog_);
00382 }
00383 }
00384 if (res == ACE_INVALID_HANDLE)
00385 this->close ();
00386 return this->get_handle ();
00387 }
|
|
|
Definition at line 48 of file TLI_Acceptor.h. |
|
|
Declare the dynamic allocation hooks.
Reimplemented from ACE_TLI. Definition at line 97 of file TLI_Acceptor.h. |
|
|
Number of connections to queue.
Definition at line 104 of file TLI_Acceptor.h. Referenced by open(). |
|
|
Network "device" we are using.
Definition at line 101 of file TLI_Acceptor.h. |
|
|
Used for handling disconnects.
Definition at line 116 of file TLI_Acceptor.h. |
|
|
Used for queueing up pending requests.
Definition at line 113 of file TLI_Acceptor.h. |
|
|
Are we using "tirdwr" mod?
Definition at line 107 of file TLI_Acceptor.h. |
1.3.6