#include <SSL_Asynch_Stream.h>
Inheritance diagram for ACE_SSL_Asynch_Stream:


Public Types | |
| enum | Stream_Type { ST_CLIENT = 0x0001, ST_SERVER = 0x0002 } |
Public Member Functions | |
| ACE_SSL_Asynch_Stream (Stream_Type s_type=ST_SERVER, ACE_SSL_Context *context=0) | |
| Constructor. | |
| virtual | ~ACE_SSL_Asynch_Stream (void) |
| Destructor. | |
| int | cancel (void) |
| int | close (void) |
| int | open (ACE_Handler &handler, ACE_HANDLE handle=ACE_INVALID_HANDLE, const void *completion_key=0, ACE_Proactor *proactor=0) |
| int | read (ACE_Message_Block &message_block, size_t num_bytes_to_read, const void *act=0, int priority=0, int signal_number=ACE_SIGRTMIN) |
| int | write (ACE_Message_Block &message_block, size_t bytes_to_write, const void *act=0, int priority=0, int signal_number=ACE_SIGRTMIN) |
Protected Types | |
| enum | Stream_Flag { SF_STREAM_OPEN = 0x0001, SF_REQ_SHUTDOWN = 0x0002, SF_SHUTDOWN_DONE = 0x0004, SF_CLOSE_NTF_SENT = 0x0008, SF_DELETE_ENABLE = 0x0010 } |
| Stream state/flags. More... | |
| enum | BIO_Flag { BF_EOS = 0x01, BF_AIO = 0x02 } |
Protected Member Functions | |
| virtual ACE_Asynch_Operation_Impl * | implementation (void) const |
| virtual void | handle_write_stream (const ACE_Asynch_Write_Stream::Result &result) |
| virtual from ACE_Handler | |
| virtual void | handle_read_stream (const ACE_Asynch_Read_Stream::Result &result) |
| virtual void | handle_wakeup (void) |
| void | print_error (int err_ssl, const ACE_TCHAR *pText) |
| int | pending_BIO_count (void) |
| int | notify_read (int bytes_transferred, int error) |
| int | notify_write (int bytes_transferred, int error) |
| int | notify_close (void) |
SSL State Machine | |
| int | do_SSL_state_machine (void) |
| int | do_SSL_handshake (void) |
| int | do_SSL_read (void) |
| int | do_SSL_write (void) |
| int | do_SSL_shutdown (void) |
BIO Helpers | |
| int | ssl_bio_read (char *buf, size_t len, int &errval) |
| int | ssl_bio_write (const char *buf, size_t len, int &errval) |
Protected Attributes | |
| Stream_Type | type_ |
| Stream Type ST_CLIENT/ST_SERVER. | |
| ACE_HANDLE | handle_ |
| The real file/socket handle. | |
| ACE_Proactor * | proactor_ |
| The proactor. | |
| ACE_Handler * | ext_handler_ |
| External,i.e user handler. | |
| ACE_SSL_Asynch_Read_Stream_Result * | ext_read_result_ |
| External, i.e. read result faked for user. | |
| ACE_SSL_Asynch_Write_Stream_Result * | ext_write_result_ |
| External, i.e. write result faked for user. | |
| int | flags_ |
| SSL * | ssl_ |
| The SSL session. | |
| BIO * | bio_ |
| The BIO implementation. | |
| ACE_SYNCH_MUTEX | mutex_ |
| Mutex to protect work. | |
Internal stream, buffer and info for BIO read | |
| ACE_Asynch_Read_Stream | bio_istream_ |
| ACE_Message_Block | bio_inp_msg_ |
| int | bio_inp_errno_ |
| int | bio_inp_flag_ |
Internal stream, buffer and info for BIO write | |
| ACE_Asynch_Write_Stream | bio_ostream_ |
| ACE_Message_Block | bio_out_msg_ |
| int | bio_out_errno_ |
| int | bio_out_flag_ |
Private Member Functions | |
| ACE_SSL_Asynch_Stream (ACE_SSL_Asynch_Stream const &) | |
| ACE_SSL_Asynch_Stream & | operator= (ACE_SSL_Asynch_Stream const &) |
Friends | |
| struct | ACE_SSL_Asynch_Stream_Accessor |
Once open() is called, multiple asynchronous read and write operations can be started using this class. The handler object (derived from ACE_Handler) specified in open() will receive completion events for the operations initiated via this class.
Definition at line 144 of file SSL_Asynch_Stream.h.
|
|
The real streams which work under the ssl connection. BIO performs I/O via this streams Definition at line 385 of file SSL_Asynch_Stream.h.
|
|
|
Stream state/flags.
Definition at line 361 of file SSL_Asynch_Stream.h.
00362 {
00363 /// istream_ open OK
00364 SF_STREAM_OPEN = 0x0001,
00365 /// request to SSL shutdown
00366 SF_REQ_SHUTDOWN = 0x0002,
00367 /// SSL shutdown finished
00368 SF_SHUTDOWN_DONE = 0x0004,
00369 /// Close notification sent
00370 SF_CLOSE_NTF_SENT = 0x0008,
00371 /// Stream can be safely destroyed
00372 SF_DELETE_ENABLE = 0x0010
00373 };
|
|
|
Definition at line 162 of file SSL_Asynch_Stream.h.
|
|
||||||||||||
|
Constructor.
Definition at line 91 of file SSL_Asynch_Stream.cpp. References ACE_ERROR, ACE_TEXT, ACE_TRACE, ACE_SSL_Context::context(), ACE_SSL_Context::instance(), LM_ERROR, and ssl_.
00094 : type_ (s_type), 00095 handle_ (ACE_INVALID_HANDLE), 00096 proactor_ (0), 00097 ext_handler_ (0), 00098 ext_read_result_ (0), 00099 ext_write_result_(0), 00100 flags_ (0), 00101 ssl_ (0), 00102 bio_ (0), 00103 bio_istream_ (), 00104 bio_inp_msg_ (), 00105 bio_inp_errno_(0), 00106 bio_inp_flag_ (0), 00107 bio_ostream_ (), 00108 bio_out_msg_ (), 00109 bio_out_errno_(0), 00110 bio_out_flag_ (0), 00111 mutex_ () 00112 { 00113 ACE_TRACE ("ACE_SSL_Asynch_Stream::ACE_SSL_Asynch_Stream"); 00114 // was honestly copied from ACE_SSL_SOCK_Stream :) 00115 00116 ACE_SSL_Context * ctx = 00117 (context == 0 ? ACE_SSL_Context::instance () : context); 00118 00119 this->ssl_ = ::SSL_new (ctx->context ()); 00120 00121 if (this->ssl_ == 0) 00122 ACE_ERROR 00123 ((LM_ERROR, 00124 ACE_TEXT ("(%P|%t) ACE_SSL_Asynch_Stream %p\n"), 00125 ACE_TEXT ("- cannot allocate new SSL structure") 00126 )); 00127 00128 } |
|
|
Destructor.
Definition at line 130 of file SSL_Asynch_Stream.cpp. References ACE_DEBUG, ACE_TEXT, ACE_TRACE, LM_DEBUG, SF_DELETE_ENABLE, SF_STREAM_OPEN, and ssl_.
00131 {
00132 ACE_TRACE ("ACE_SSL_Asynch_Stream::~ACE_SSL_Asynch_Stream");
00133
00134
00135 // It is safe to delete stream if all notifications are received,
00136 // i.e., state is SF_DELETE_ENABLE or if proactor event loop is
00137 // done.
00138 if (this->flags_ & SF_STREAM_OPEN) // open
00139 if ((this->flags_ & SF_DELETE_ENABLE) == 0) // but ..
00140 ACE_DEBUG ((LM_DEBUG,
00141 ACE_TEXT("ACE_SSL_Asynch_Stream::DTOR-")
00142 ACE_TEXT("possible access violation ")
00143 ACE_TEXT("if proactor still handles events\n")));
00144
00145 ::SSL_free (this->ssl_);
00146
00147 // Was honestly copied from ACE_SSL_SOCK_Stream :)
00148
00149 // @@ Question: should we reference count the Context object or
00150 // leave that to the application developer? We do not reference
00151 // count reactors (for example) and following some simple rules
00152 // seems to work fine!
00153 }
|
|
|
|
|
|
Reimplemented from ACE_Asynch_Operation. Definition at line 187 of file SSL_Asynch_Stream.cpp. References ACE_GUARD_RETURN, ACE_SYNCH_MUTEX, bio_istream_, bio_ostream_, ACE_Asynch_Operation::cancel(), ERR_CANCELED, notify_read(), notify_write(), and SF_STREAM_OPEN.
00188 {
00189 ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->mutex_, -1));
00190
00191 if ((flags_ & SF_STREAM_OPEN) == 0) // not open
00192 return 1; // AIO_ALLDONE
00193
00194 // attempt to cancel internal, i.e. user's read/write
00195 int rc_r_int = bio_istream_.cancel();
00196 int rc_w_int = bio_ostream_.cancel();
00197
00198 // attempt to cancel external, i.e. bio_ssl read/write
00199 int rc_r_ext = notify_read (0, ERR_CANCELED);
00200 int rc_w_ext = notify_write (0, ERR_CANCELED);
00201
00202 if (rc_r_int < 0 || rc_w_int < 0
00203 && rc_r_ext < 0 || rc_w_ext < 0)
00204 return -1; // at least one error
00205
00206 if (rc_r_int == 1 && rc_w_int == 1
00207 && rc_r_ext == 1 && rc_w_ext == 1)
00208 return 1; // AIO_ALLDONE
00209
00210 if (rc_r_int == 2 || rc_w_int == 2
00211 && rc_r_ext == 2 || rc_w_ext == 2)
00212 return 2; // AIO_NOT_CANCELED , at least one not canceled
00213
00214 return 0; // AIO_CANCELED, at least will be one notification
00215 }
|
|
|
Definition at line 165 of file SSL_Asynch_Stream.cpp. References ACE_GUARD_RETURN, ACE_SYNCH_MUTEX, do_SSL_state_machine(), SF_DELETE_ENABLE, SF_REQ_SHUTDOWN, and SF_STREAM_OPEN.
00166 {
00167 ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->mutex_, -1));
00168
00169 if ((flags_ & SF_STREAM_OPEN) == 0) // not open
00170 flags_ |= SF_DELETE_ENABLE;
00171
00172 if (flags_ & SF_DELETE_ENABLE)
00173 return 0;
00174
00175 flags_ |= SF_REQ_SHUTDOWN;
00176
00177 this->do_SSL_state_machine ();
00178
00179 return -1;
00180 }
|
|
|
Definition at line 482 of file SSL_Asynch_Stream.cpp. References ACE_ERROR_RETURN, ACE_TEXT, LM_ERROR, print_error(), SF_REQ_SHUTDOWN, ssl_, ST_CLIENT, and ST_SERVER. Referenced by do_SSL_state_machine().
00483 {
00484 if (SSL_is_init_finished (this->ssl_))
00485 return 1;
00486
00487 if (this->flags_ & SF_REQ_SHUTDOWN)
00488 return -1;
00489
00490 int retval = -1;
00491
00492 switch (this->type_)
00493 {
00494 case ST_CLIENT:
00495 retval = ::SSL_connect (this->ssl_);
00496 break;
00497
00498 case ST_SERVER:
00499 retval = ::SSL_accept (this->ssl_);
00500 break;
00501
00502 default:
00503 ACE_ERROR_RETURN
00504 ((LM_ERROR,
00505 ACE_TEXT ("(%P|%t) ACE_SSL_Asynch_Stream %p\n"),
00506 ACE_TEXT ("- invalid stream type")),
00507 -1);
00508 }
00509
00510 int status = ::SSL_get_error (this->ssl_, retval);
00511
00512 switch (status)
00513 {
00514 case SSL_ERROR_NONE:
00515 break;
00516
00517 case SSL_ERROR_WANT_READ:
00518 case SSL_ERROR_WANT_WRITE:
00519 case SSL_ERROR_WANT_CONNECT:
00520 //case SSL_ERROR_WANT_ACCEPT:
00521 case SSL_ERROR_WANT_X509_LOOKUP:
00522 return 0;
00523
00524 case SSL_ERROR_ZERO_RETURN:
00525 case SSL_ERROR_SYSCALL:
00526 default:
00527 this->print_error (status,
00528 ACE_TEXT ("Handshake error"));
00529 return -1;
00530 }
00531
00532 return 1;
00533 }
|
|
|
Definition at line 539 of file SSL_Asynch_Stream.cpp. References ACE_TEXT, ACE_WIN32_Asynch_Read_Stream_Result::bytes_to_read(), ERR_CANCELED, ext_read_result_, ACE_WIN32_Asynch_Read_Stream_Result::message_block(), notify_read(), print_error(), SF_REQ_SHUTDOWN, ssl_, and ACE_Message_Block::wr_ptr(). Referenced by do_SSL_state_machine().
00540 {
00541 if (this->ext_read_result_ == 0) // nothing to do
00542 return 0;
00543
00544 if (this->flags_ & SF_REQ_SHUTDOWN)
00545 {
00546 this->notify_read (0, ERR_CANCELED);
00547 return -1;
00548 }
00549
00550 ACE_Message_Block & mb = this->ext_read_result_->message_block ();
00551 size_t bytes_req = this->ext_read_result_->bytes_to_read ();
00552
00553 const int bytes_trn = ::SSL_read (this->ssl_,
00554 mb.wr_ptr (),
00555 bytes_req);
00556
00557 int status = ::SSL_get_error (this->ssl_, bytes_trn);
00558
00559 switch (status)
00560 {
00561 case SSL_ERROR_NONE:
00562 this->notify_read (bytes_trn, 0);
00563 return 1;
00564
00565 case SSL_ERROR_WANT_READ:
00566 case SSL_ERROR_WANT_WRITE:
00567 return 0;
00568
00569 case SSL_ERROR_ZERO_RETURN:
00570 this->notify_read (0, 0);
00571 return 1;
00572
00573 case SSL_ERROR_SYSCALL:
00574 if (bytes_trn == 0)
00575 {
00576 this->notify_read (0, 0);
00577 return 1;
00578 }
00579 // If not an EOF, then fall through to "default" case.
00580
00581 default:
00582 break;
00583 }
00584
00585 this->notify_read (0, EFAULT);
00586 this->print_error (status,
00587 ACE_TEXT ("SSL_read error"));
00588
00589 return -1;
00590 }
|
|
|
Definition at line 431 of file SSL_Asynch_Stream.cpp. References ACE_TEXT, ERR_CANCELED, notify_read(), notify_write(), print_error(), SF_REQ_SHUTDOWN, SF_SHUTDOWN_DONE, and ssl_. Referenced by do_SSL_state_machine().
00432 {
00433 if (this->flags_ & SF_SHUTDOWN_DONE) // already done
00434 return 1;
00435
00436 this->flags_ |= SF_REQ_SHUTDOWN;
00437
00438 // if we have any uncompleted user requests
00439 // than cancel its
00440 this->notify_read (0, ERR_CANCELED);
00441 this->notify_write (0, ERR_CANCELED);
00442
00443 int retval = ::SSL_shutdown (this->ssl_);
00444
00445 int status = ::SSL_get_error (this->ssl_, retval);
00446
00447 switch (status)
00448 {
00449 case SSL_ERROR_NONE:
00450 case SSL_ERROR_ZERO_RETURN:
00451 case SSL_ERROR_SYSCALL:
00452 retval = 1;
00453 break;
00454
00455 case SSL_ERROR_WANT_READ:
00456 case SSL_ERROR_WANT_WRITE:
00457 case SSL_ERROR_WANT_CONNECT:
00458 // case SSL_ERROR_WANT_ACCEPT:
00459 case SSL_ERROR_WANT_X509_LOOKUP:
00460 return 0;
00461
00462 default:
00463 this->print_error (status,
00464 ACE_TEXT ("Shutdown error"));
00465 retval = -1;
00466 break;
00467 }
00468
00469 this->flags_ |= SF_SHUTDOWN_DONE;
00470
00471 return retval;
00472 }
|
|
|
Definition at line 397 of file SSL_Asynch_Stream.cpp. References do_SSL_handshake(), do_SSL_read(), do_SSL_shutdown(), do_SSL_write(), notify_close(), and SF_REQ_SHUTDOWN. Referenced by close(), handle_read_stream(), handle_write_stream(), open(), read(), and write().
00398 {
00399 // this protected member should be called
00400 // with locked mutex_
00401
00402 int retval = this->do_SSL_handshake ();
00403
00404 if (retval == 0) // handshake in progress ?
00405 return 0;
00406
00407 if (retval < 0)
00408 this->flags_ |= SF_REQ_SHUTDOWN;
00409
00410 this->do_SSL_read (); // execute user read request
00411 this->do_SSL_write (); // execute user write request
00412
00413 if ((this->flags_ & SF_REQ_SHUTDOWN) == 0) // Do we have any errors
00414 return 0;
00415
00416 this->do_SSL_shutdown ();
00417
00418 this->notify_close ();
00419
00420 return 0;
00421 }
|
|
|
Definition at line 596 of file SSL_Asynch_Stream.cpp. References ACE_TEXT, ACE_WIN32_Asynch_Write_Stream_Result::bytes_to_write(), ERR_CANCELED, ext_write_result_, ACE_WIN32_Asynch_Write_Stream_Result::message_block(), notify_write(), print_error(), ACE_Message_Block::rd_ptr(), SF_REQ_SHUTDOWN, and ssl_. Referenced by do_SSL_state_machine().
00597 {
00598 if (this->ext_write_result_ == 0) // nothing to do
00599 return 0;
00600
00601 if (this->flags_ & SF_REQ_SHUTDOWN)
00602 {
00603 this->notify_write (0, ERR_CANCELED);
00604 return -1;
00605 }
00606
00607 ACE_Message_Block & mb = this->ext_write_result_->message_block ();
00608 size_t bytes_req = this->ext_write_result_->bytes_to_write ();
00609
00610 const int bytes_trn = ::SSL_write (this->ssl_,
00611 mb.rd_ptr (),
00612 bytes_req);
00613
00614 int status = ::SSL_get_error (this->ssl_, bytes_trn);
00615
00616 switch (status)
00617 {
00618 case SSL_ERROR_NONE:
00619 this->notify_write (bytes_trn, 0);
00620 return 1;
00621
00622 case SSL_ERROR_WANT_READ:
00623 case SSL_ERROR_WANT_WRITE:
00624 return 0;
00625
00626 case SSL_ERROR_ZERO_RETURN:
00627 this->notify_write (bytes_trn, 0);
00628 return 1;
00629
00630 case SSL_ERROR_SYSCALL:
00631 default:
00632 break;
00633 }
00634
00635 this->notify_write(0, EFAULT);
00636 this->print_error (status,
00637 ACE_TEXT ("SSL_write error"));
00638
00639 return -1;
00640 }
|
|
|
This method is called when BIO read request is completed. It processes the IO completion and calls do_SSL_state_machine(). Reimplemented from ACE_Handler. Definition at line 984 of file SSL_Asynch_Stream.cpp. References ACE_GUARD, ACE_SYNCH_MUTEX, BF_AIO, BF_EOS, bio_inp_errno_, bio_inp_flag_, ACE_Asynch_Result::bytes_transferred(), do_SSL_state_machine(), and ACE_Asynch_Result::error().
00986 {
00987 ACE_MT (ACE_GUARD (ACE_SYNCH_MUTEX, ace_mon, this->mutex_));
00988
00989 this->bio_inp_flag_ &= ~BF_AIO;
00990
00991 size_t bytes_trn = result.bytes_transferred ();
00992 u_long errval = result.error ();
00993
00994 if (errval != 0) // error ?
00995 this->bio_inp_errno_ = errval; // save error code
00996 else if (bytes_trn == 0) // end of stream ?
00997 this->bio_inp_flag_ |= BF_EOS; // set flag EOS
00998
00999 this->do_SSL_state_machine ();
01000
01001 return;
01002 }
|
|
|
This method is called when all SSL sessions are closed and no more pending AIOs exist. It also calls users handle_wakeup(). Reimplemented from ACE_Handler. Definition at line 1005 of file SSL_Asynch_Stream.cpp. References ACE_GUARD, ACE_SYNCH_MUTEX, ext_handler_, ACE_Handler::handle_wakeup(), and SF_DELETE_ENABLE.
01006 {
01007 ACE_Handler * user_handler = 0;
01008
01009 {
01010 ACE_MT (ACE_GUARD (ACE_SYNCH_MUTEX, ace_mon, this->mutex_));
01011
01012 this->flags_ |= SF_DELETE_ENABLE;
01013
01014 user_handler = this->ext_handler_;
01015 }
01016
01017 if (user_handler != 0)
01018 user_handler->handle_wakeup();
01019 }
|
|
|
virtual from ACE_Handler This method is called when BIO write request is completed. It processes the IO completion and calls do_SSL_state_machine(). Reimplemented from ACE_Handler. Definition at line 939 of file SSL_Asynch_Stream.cpp. References ACE_ERROR, ACE_GUARD, ACE_SIGRTMIN, ACE_SYNCH_MUTEX, ACE_TEXT, BF_AIO, bio_ostream_, bio_out_errno_, bio_out_flag_, ACE_Asynch_Write_Stream::Result::bytes_to_write(), ACE_Asynch_Result::bytes_transferred(), do_SSL_state_machine(), ACE_Asynch_Result::error(), LM_ERROR, ACE_Asynch_Write_Stream::Result::message_block(), and ACE_Asynch_Write_Stream::write().
00941 {
00942 ACE_MT (ACE_GUARD (ACE_SYNCH_MUTEX, ace_mon, this->mutex_));
00943
00944 this->bio_out_flag_ &= ~BF_AIO;
00945
00946 ACE_Message_Block & mb = result.message_block ();
00947
00948 size_t bytes_req = result.bytes_to_write ();
00949 size_t bytes_trn = result.bytes_transferred ();
00950 u_long errval = result.error ();
00951 size_t len = bytes_req - bytes_trn;
00952
00953 if (errval != 0) // error ?
00954 this->bio_out_errno_ = errval; // save error code
00955 else if (len > 0) // TCP/IP overloaded ?
00956 { // continue, rd_ptr at right place
00957 if (this->bio_ostream_.write (
00958 mb, // message block
00959 len, // priority
00960 0, // act
00961 0, // priority
00962 ACE_SIGRTMIN // default signal
00963 ) == 0)
00964 {
00965 this->bio_out_flag_ |= BF_AIO;
00966 return;
00967 }
00968
00969 ACE_ERROR
00970 ((LM_ERROR,
00971 ACE_TEXT ("(%P|%t) ACE_SSL_Asynch_Stream %p\n"),
00972 ACE_TEXT ("attempt write failed")
00973 ));
00974
00975 this->bio_out_errno_ = EINVAL;
00976 }
00977
00978 this->do_SSL_state_machine ();
00979
00980 return;
00981 }
|
|
|
Virtual from ACE_Asynch_Operation. Since this class is essentially an implementation class, simply return 0. Implements ACE_Asynch_Operation. Definition at line 279 of file SSL_Asynch_Stream.h.
00279 { return 0; }
|
|
|
This method is called to notify ourself that SSL session is shutdown and that there is no more I/O activity now and in the future. Definition at line 651 of file SSL_Asynch_Stream.cpp. References ACE_NEW_RETURN, pending_BIO_count(), ACE_WIN32_Asynch_Result::post_completion(), SF_CLOSE_NTF_SENT, and SF_SHUTDOWN_DONE. Referenced by do_SSL_state_machine().
00652 {
00653 if (this->flags_ & SF_CLOSE_NTF_SENT) // already sent
00654 return 1;
00655
00656 if ((this->flags_ & SF_SHUTDOWN_DONE) == 0) // only after shutdown
00657 return 2; // too early , we will do later
00658
00659 if (this->pending_BIO_count () != 0) // wait for all internal IO
00660 return 2; // too early , we will do later
00661
00662 // create result for future notification
00663 ACE_SSL_Asynch_Result * close_result = 0;
00664
00665 ACE_NEW_RETURN (close_result,
00666 ACE_SSL_Asynch_Result (*this),
00667 2);
00668 //@@ Not exception safe!
00669
00670 int retval =
00671 close_result->post_completion (this->proactor_->implementation ());
00672
00673 if (retval == 0)
00674 {
00675 this->flags_ |= SF_CLOSE_NTF_SENT;
00676 return 0;
00677 }
00678
00679 delete close_result;
00680 return 2;
00681 }
|
|
||||||||||||
|
This method is called to notify user handler when user's read in done. Definition at line 692 of file SSL_Asynch_Stream.cpp. References ext_read_result_, ACE_Proactor::implementation(), ACE_WIN32_Asynch_Read_Stream_Result::post_completion(), ACE_WIN32_Asynch_Result::set_bytes_transferred(), and ACE_WIN32_Asynch_Result::set_error(). Referenced by cancel(), do_SSL_read(), and do_SSL_shutdown().
00694 {
00695 if (ext_read_result_ == 0) //nothing to notify
00696 return 1;
00697
00698 this->ext_read_result_->set_bytes_transferred (bytes_transferred);
00699 this->ext_read_result_->set_error (error);
00700
00701 int retval =
00702 this->ext_read_result_->post_completion (proactor_->implementation ());
00703
00704 if (retval == 0)
00705 {
00706 this->ext_read_result_ = 0;
00707 return 0; // success
00708 }
00709
00710 return 2; // unable to notify
00711 }
|
|
||||||||||||
|
This method is called to notify user handler when user's write in done. Definition at line 722 of file SSL_Asynch_Stream.cpp. References ext_write_result_, ACE_WIN32_Asynch_Write_Stream_Result::post_completion(), ACE_WIN32_Asynch_Result::set_bytes_transferred(), and ACE_WIN32_Asynch_Result::set_error(). Referenced by cancel(), do_SSL_shutdown(), and do_SSL_write().
00724 {
00725 if (this->ext_write_result_ == 0) //nothing to notify
00726 return 1;
00727
00728 this->ext_write_result_->set_bytes_transferred (bytes_transferred);
00729 this->ext_write_result_->set_error (error);
00730
00731 int retval =
00732 this->ext_write_result_->post_completion (
00733 this->proactor_->implementation ());
00734
00735 if (retval == 0)
00736 {
00737 this->ext_write_result_ = 0;
00738 return 0; // success
00739 }
00740
00741 return 2; // unable to notify
00742 }
|
|
||||||||||||||||||||
|
Initializes the factory with information which will be used with each asynchronous call.
Reimplemented from ACE_Asynch_Operation. Definition at line 222 of file SSL_Asynch_Stream.cpp. References ACE_ERROR_RETURN, ACE_GUARD_RETURN, ACE_SSL_make_BIO(), ACE_SYNCH_MUTEX, ACE_TEXT, bio_, bio_istream_, bio_ostream_, do_SSL_state_machine(), ext_handler_, ACE_Asynch_Operation::get_proactor(), LM_ERROR, ACE_Asynch_Write_Stream::open(), ACE_Asynch_Read_Stream::open(), SF_STREAM_OPEN, ssl_, ST_CLIENT, and ST_SERVER.
00226 {
00227 ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->mutex_, -1));
00228
00229 if (this->flags_ & SF_STREAM_OPEN)
00230 ACE_ERROR_RETURN
00231 ((LM_ERROR,
00232 ACE_TEXT ("(%P|%t) ACE_SSL_Asynch_Stream::open() %p\n"),
00233 ACE_TEXT ("- already opened")),
00234 -1);
00235
00236 if (this->ssl_ == 0)
00237 ACE_ERROR_RETURN
00238 ((LM_ERROR,
00239 ACE_TEXT ("(%P|%t) ACE_SSL_Asynch_Stream::open() %p\n"),
00240 ACE_TEXT ("- SSL structure is absent")),
00241 -1);
00242
00243 if (handle == ACE_INVALID_HANDLE)
00244 ACE_ERROR_RETURN
00245 ((LM_ERROR,
00246 ACE_TEXT ("(%P|%t) ACE_SSL_Asynch_Stream::open() %p\n"),
00247 ACE_TEXT ("- invalid handle")),
00248 -1);
00249
00250
00251 // Get a proactor for/from the user.
00252 this->proactor_ = this->get_proactor (proactor, handler);
00253 this->ext_handler_ = & handler;
00254 this->handle_ = handle;
00255
00256 // Open internal input stream
00257 if (this->bio_istream_.open (*this, // real callbacks to this
00258 handle,
00259 completion_key,
00260 this->proactor_) != 0)
00261 return -1;
00262
00263 // Open internal output stream
00264 if (this->bio_ostream_.open (*this, // real callbacks to this
00265 handle,
00266 completion_key,
00267 this->proactor_) != 0)
00268 return -1;
00269
00270 this->bio_ = ACE_SSL_make_BIO (this);
00271
00272 if (this->bio_ == 0)
00273 ACE_ERROR_RETURN
00274 ((LM_ERROR,
00275 ACE_TEXT ("(%P|%t) ACE_SSL_Asynch_Stream::open() %p\n"),
00276 ACE_TEXT ("- cannot allocate new BIO structure")),
00277 -1);
00278
00279 ::SSL_set_bio (this->ssl_ , this->bio_ , this->bio_);
00280
00281 switch (this->type_)
00282 {
00283 case ST_CLIENT:
00284 ::SSL_set_connect_state (this->ssl_);
00285 break;
00286
00287 case ST_SERVER:
00288 ::SSL_set_accept_state (this->ssl_);
00289 break;
00290
00291 default:
00292 ACE_ERROR_RETURN
00293 ((LM_ERROR,
00294 ACE_TEXT ("(%P|%t) ACE_SSL_Asynch_Stream::open() %p\n"),
00295 ACE_TEXT ("- invalid stream type")),
00296 -1);
00297 }
00298
00299 this->flags_ |= SF_STREAM_OPEN;
00300
00301 this->do_SSL_state_machine ();
00302
00303 return 0;
00304 }
|
|
|
|
|
|
Definition at line 1022 of file SSL_Asynch_Stream.cpp. References BF_AIO, bio_inp_flag_, and bio_out_flag_. Referenced by notify_close().
01023 {
01024 int ret = 0;
01025
01026 if (this->bio_inp_flag_ & BF_AIO)
01027 ++ret;
01028
01029 if (this->bio_out_flag_ & BF_AIO)
01030 ++ret;
01031
01032 return ret;
01033 }
|
|
||||||||||||
|
Definition at line 748 of file SSL_Asynch_Stream.cpp. References ACE_DEBUG, and LM_DEBUG. Referenced by do_SSL_handshake(), do_SSL_read(), do_SSL_shutdown(), and do_SSL_write().
00750 {
00751 ACE_DEBUG ((LM_DEBUG,
00752 "SSL-error:%d %s\n" ,
00753 err_ssl,
00754 pText));
00755
00756 #if OPENSSL_VERSION_NUMBER >= 0x0090601fL
00757 // OpenSSL < 0.9.6a doesn't have ERR_error_string_n() function.
00758 unsigned long lerr = 0;
00759 char buf[1024];
00760
00761 while ((lerr = ERR_get_error()) != 0)
00762 {
00763 ERR_error_string_n (lerr, buf, sizeof buf);
00764
00765 ACE_DEBUG ((LM_DEBUG, "%s\n", buf));
00766 }
00767 #endif /* OPENSSL_VERSION_NUMBER */
00768 }
|
|
||||||||||||||||||||||||
|
Initiates an asynchronous read. If the operation is successfully initiated, the handle_read_stream() method will be called on the ACE_Handler object passed to open() when the operation completes. Data is read into the specified ACE_Message_Block beginning at its write pointer; the block's write pointer is updated to reflect any added data when the operation completes.
Definition at line 312 of file SSL_Asynch_Stream.cpp. References ACE_GUARD_RETURN, ACE_NEW_RETURN, ACE_SYNCH_MUTEX, do_SSL_state_machine(), ext_read_result_, SF_REQ_SHUTDOWN, and SF_STREAM_OPEN.
00317 {
00318 ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->mutex_, -1));
00319
00320 if ((this->flags_ & SF_STREAM_OPEN) == 0) // not open
00321 return -1;
00322
00323 if (this->flags_ & SF_REQ_SHUTDOWN)
00324 return -1;
00325
00326 // only one read operation is allowed now
00327 // later it will be possible to make a queue
00328
00329 if (this->ext_read_result_ != 0)
00330 return -1;
00331
00332 // create result for future notification
00333 ACE_NEW_RETURN (this->ext_read_result_,
00334 ACE_SSL_Asynch_Read_Stream_Result (
00335 *this->ext_handler_,
00336 this->handle_,
00337 message_block,
00338 bytes_to_read,
00339 act,
00340 this->proactor_->get_handle(),
00341 priority,
00342 signal_number),
00343 -1);
00344
00345 this->do_SSL_state_machine (); // ignore return code
00346
00347 return 0;
00348 }
|
|
||||||||||||||||
|
Definition at line 776 of file SSL_Asynch_Stream.cpp. References ACE_ERROR, ACE_SIGRTMIN, ACE_TEXT, ACE_Message_Block::base(), BF_AIO, BF_EOS, bio_inp_errno_, bio_inp_flag_, bio_inp_msg_, bio_istream_, EINPROGRESS, ACE_Message_Block::length(), LM_ERROR, ACE_OS::memcpy(), ACE_Message_Block::rd_ptr(), ACE_Asynch_Read_Stream::read(), ACE_Message_Block::size(), and ACE_Message_Block::wr_ptr(). Referenced by ACE_SSL_Asynch_Stream_Accessor::read().
00779 {
00780 // We do not have to acquire mutex
00781 // as we called already with locked mutex
00782 // from do_SSL_state_machine()
00783
00784 errval = 0;
00785
00786 size_t cur_len = this->bio_inp_msg_.length ();
00787
00788 if (cur_len > 0) // there are more data buffered
00789 {
00790 const char * rd_ptr = this->bio_inp_msg_.rd_ptr ();
00791
00792 if (cur_len > len)
00793 cur_len = len;
00794
00795 ACE_OS::memcpy (buf, rd_ptr, cur_len);
00796
00797 this->bio_inp_msg_.rd_ptr (cur_len); // go ahead
00798
00799 return cur_len;
00800 }
00801
00802 if (this->bio_inp_errno_ != 0) // if was error - it is permanent !
00803 {
00804 errval = this->bio_inp_errno_;
00805 return -1;
00806 }
00807
00808 if (this->bio_inp_flag_ & BF_EOS) // End of stream
00809 return 0;
00810
00811 errval = EINPROGRESS; // SSL will try later
00812
00813 if (this->bio_inp_flag_ & BF_AIO) // we are busy
00814 return -1;
00815
00816 if (this->bio_inp_msg_.size (len) != 0)
00817 {
00818 ACE_ERROR
00819 ((LM_ERROR,
00820 ACE_TEXT ("%N:%l ((%P|%t) ACE_SSL_Asynch_Stream %p\n"),
00821 ACE_TEXT ("error in ACE_Message_Block::size() ")
00822 ));
00823
00824 errval = EINVAL;
00825 return -1;
00826 }
00827
00828 char * base = this->bio_inp_msg_.base ();
00829
00830 this->bio_inp_msg_.rd_ptr (base);
00831 this->bio_inp_msg_.wr_ptr (base);
00832
00833 if (this->bio_istream_.read (
00834 bio_inp_msg_, // message block
00835 len, // priority
00836 0, // act
00837 0, // priority
00838 ACE_SIGRTMIN // default signal
00839 ) == -1)
00840 {
00841 ACE_ERROR
00842 ((LM_ERROR,
00843 ACE_TEXT ("%N:%l (%P|%t) ACE_SSL_Asynch_Stream %p\n"),
00844 ACE_TEXT ("attempt read failed")
00845 ));
00846
00847 errval = EINVAL; // may be leave EINPROGRESS ??
00848 return -1; // to try later
00849 }
00850
00851 this->bio_inp_flag_ |= BF_AIO; // AIO is active
00852
00853 return -1;
00854 }
|
|
||||||||||||||||
|
Definition at line 858 of file SSL_Asynch_Stream.cpp. References ACE_ERROR, ACE_SIGRTMIN, ACE_TEXT, ACE_Message_Block::base(), BF_AIO, bio_ostream_, bio_out_errno_, bio_out_flag_, bio_out_msg_, ACE_Message_Block::copy(), EINPROGRESS, LM_ERROR, ACE_Message_Block::rd_ptr(), ACE_Message_Block::size(), ACE_Message_Block::wr_ptr(), and ACE_Asynch_Write_Stream::write(). Referenced by ACE_SSL_Asynch_Stream_Accessor::write().
00861 {
00862 // We do not have to acquire mutex
00863 // as we called already with locked mutex
00864 // from do_SSL_state_machine
00865
00866 errval = 0;
00867
00868 if (this->bio_out_flag_ & BF_AIO) // sorry, we are busy
00869 {
00870 errval = EINPROGRESS; // try later
00871 return -1;
00872 }
00873
00874 if (this->bio_out_errno_ != 0) // no recovery
00875 {
00876 errval = this->bio_out_errno_;
00877 return -1;
00878 }
00879
00880 if (this->bio_out_msg_.size (len) != 0)
00881 {
00882 ACE_ERROR
00883 ((LM_ERROR,
00884 ACE_TEXT ("%N:%l ((%P|%t) ACE_SSL_Asynch_Stream %p\n"),
00885 ACE_TEXT ("error in ACE_Message_Block::size() ")
00886 ));
00887
00888 errval = EINVAL;
00889 return -1;
00890 }
00891
00892 char * base = this->bio_out_msg_.base ();
00893
00894 this->bio_out_msg_.rd_ptr (base);
00895 this->bio_out_msg_.wr_ptr (base);
00896
00897 if (this->bio_out_msg_.copy (buf, len) == -1)
00898 {
00899 ACE_ERROR
00900 ((LM_ERROR,
00901 ACE_TEXT ("%N:%l ((%P|%t) ACE_SSL_Asynch_Stream %p\n"),
00902 ACE_TEXT ("error in ACE_Message_Block::copy() ")
00903 ));
00904
00905 errval = EINVAL;
00906 return -1;
00907 }
00908
00909
00910 if (this->bio_ostream_.write (
00911 this->bio_out_msg_, // message block
00912 len, // priority
00913 0, // act
00914 0, // priority
00915 ACE_SIGRTMIN // default signal
00916 ) == -1)
00917 {
00918 ACE_ERROR
00919 ((LM_ERROR,
00920 ACE_TEXT ("%N:%l ((%P|%t) ACE_SSL_Asynch_Stream %p\n"),
00921 ACE_TEXT ("attempt write failed")
00922 ));
00923
00924 errval = EINVAL; // may be leave EINPROGRESS ??
00925 return -1; // to try later
00926 }
00927
00928 this->bio_out_flag_ |= BF_AIO; // AIO is active
00929 errval = 0; // Ok, go ahead
00930
00931 return len;
00932 }
|
|
||||||||||||||||||||||||
|
Initiates an asynchronous write. If the operation is successfully initiated, the handle_write_stream() method will be called on the ACE_Handler object passed to open() when the operation completes. Data is taken from the specified ACE_Message_Block beginning at its read pointer; the block's read pointer is updated to reflect any data successfully sent when the operation completes.
Definition at line 355 of file SSL_Asynch_Stream.cpp. References ACE_GUARD_RETURN, ACE_NEW_RETURN, ACE_SYNCH_MUTEX, do_SSL_state_machine(), ext_write_result_, SF_REQ_SHUTDOWN, and SF_STREAM_OPEN.
00360 {
00361 ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->mutex_, -1));
00362
00363 if ((this->flags_ & SF_STREAM_OPEN) == 0) // not open
00364 return -1;
00365
00366 if (this->flags_ & SF_REQ_SHUTDOWN)
00367 return -1;
00368
00369 // only one read operation is allowed now
00370 // later it will be possible to make a queue
00371
00372 if (this->ext_write_result_ != 0)
00373 return -1;
00374
00375 // create result for future notification
00376 ACE_NEW_RETURN (this->ext_write_result_,
00377 ACE_SSL_Asynch_Write_Stream_Result (
00378 *this->ext_handler_,
00379 this->handle_,
00380 message_block,
00381 bytes_to_write,
00382 act,
00383 this->proactor_->get_handle(),
00384 priority,
00385 signal_number),
00386 -1);
00387
00388 this->do_SSL_state_machine ();
00389
00390 return 0;
00391 }
|
|
|
Definition at line 160 of file SSL_Asynch_Stream.h. |
|
|
The BIO implementation.
Definition at line 381 of file SSL_Asynch_Stream.h. Referenced by open(). |
|
|
Definition at line 399 of file SSL_Asynch_Stream.h. Referenced by handle_read_stream(), and ssl_bio_read(). |
|
|
Definition at line 400 of file SSL_Asynch_Stream.h. Referenced by handle_read_stream(), pending_BIO_count(), and ssl_bio_read(). |
|
|
Definition at line 398 of file SSL_Asynch_Stream.h. Referenced by ssl_bio_read(). |
|
|
Definition at line 397 of file SSL_Asynch_Stream.h. Referenced by cancel(), open(), and ssl_bio_read(). |
|
|
Definition at line 407 of file SSL_Asynch_Stream.h. Referenced by cancel(), handle_write_stream(), open(), and ssl_bio_write(). |
|
|
Definition at line 409 of file SSL_Asynch_Stream.h. Referenced by handle_write_stream(), and ssl_bio_write(). |
|
|
Definition at line 410 of file SSL_Asynch_Stream.h. Referenced by handle_write_stream(), pending_BIO_count(), and ssl_bio_write(). |
|
|
Definition at line 408 of file SSL_Asynch_Stream.h. Referenced by ssl_bio_write(). |
|
|
External,i.e user handler.
Definition at line 352 of file SSL_Asynch_Stream.h. Referenced by handle_wakeup(), and open(). |
|
|
External, i.e. read result faked for user.
Definition at line 355 of file SSL_Asynch_Stream.h. Referenced by do_SSL_read(), notify_read(), and read(). |
|
|
External, i.e. write result faked for user.
Definition at line 358 of file SSL_Asynch_Stream.h. Referenced by do_SSL_write(), notify_write(), and write(). |
|
|
Definition at line 375 of file SSL_Asynch_Stream.h. |
|
|
The real file/socket handle.
Reimplemented from ACE_Handler. Definition at line 346 of file SSL_Asynch_Stream.h. |
|
|
Mutex to protect work.
Definition at line 414 of file SSL_Asynch_Stream.h. |
|
|
The proactor.
Reimplemented from ACE_Handler. Definition at line 349 of file SSL_Asynch_Stream.h. |
|
|
The SSL session.
Definition at line 378 of file SSL_Asynch_Stream.h. Referenced by ACE_SSL_Asynch_Stream(), do_SSL_handshake(), do_SSL_read(), do_SSL_shutdown(), do_SSL_write(), open(), and ~ACE_SSL_Asynch_Stream(). |
|
|
Stream Type ST_CLIENT/ST_SERVER.
Definition at line 343 of file SSL_Asynch_Stream.h. |
1.3.6