Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ACE/ace/Asynch_IO.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ class ACE_Export ACE_Asynch_Read_Stream : public ACE_Asynch_Operation
/// class.
friend class ACE_POSIX_Asynch_Read_Stream_Result;
friend class ACE_WIN32_Asynch_Read_Stream_Result;
friend class ACE_Uring_Asynch_Read_Stream_Result;

public:
/// The number of bytes which were requested at the start of the
Expand Down Expand Up @@ -534,6 +535,7 @@ class ACE_Export ACE_Asynch_Write_Stream : public ACE_Asynch_Operation
/// class.
friend class ACE_POSIX_Asynch_Write_Stream_Result;
friend class ACE_WIN32_Asynch_Write_Stream_Result;
friend class ACE_Uring_Asynch_Write_Stream_Result;

public:
/// The number of bytes which were requested at the start of the
Expand Down Expand Up @@ -688,6 +690,7 @@ class ACE_Export ACE_Asynch_Read_File : public ACE_Asynch_Read_Stream
/// class.
friend class ACE_POSIX_Asynch_Read_File_Result;
friend class ACE_WIN32_Asynch_Read_File_Result;
friend class ACE_Uring_Asynch_Read_File_Result;

public:
/// Get the implementation class.
Expand Down Expand Up @@ -822,6 +825,7 @@ class ACE_Export ACE_Asynch_Write_File : public ACE_Asynch_Write_Stream
/// class.
friend class ACE_POSIX_Asynch_Write_File_Result;
friend class ACE_WIN32_Asynch_Write_File_Result;
friend class ACE_Uring_Asynch_Write_File_Result;

public:
/// Get the implementation class.
Expand Down Expand Up @@ -952,6 +956,7 @@ class ACE_Export ACE_Asynch_Accept : public ACE_Asynch_Operation
/// class.
friend class ACE_POSIX_Asynch_Accept_Result;
friend class ACE_WIN32_Asynch_Accept_Result;
friend class ACE_Uring_Asynch_Accept_Result;

public:
/// The number of bytes which were requested at the start of the
Expand Down Expand Up @@ -1056,6 +1061,7 @@ class ACE_Export ACE_Asynch_Connect : public ACE_Asynch_Operation
/// class.
friend class ACE_POSIX_Asynch_Connect_Result;
friend class ACE_WIN32_Asynch_Connect_Result;
friend class ACE_Uring_Asynch_Connect_Result;

public:

Expand Down Expand Up @@ -1180,6 +1186,7 @@ class ACE_Export ACE_Asynch_Transmit_File : public ACE_Asynch_Operation
/// class.
friend class ACE_POSIX_Asynch_Transmit_File_Result;
friend class ACE_WIN32_Asynch_Transmit_File_Result;
friend class ACE_Uring_Asynch_Transmit_File_Result;

public:
/// Socket used for transmitting the file.
Expand Down Expand Up @@ -1390,6 +1397,7 @@ class ACE_Export ACE_Asynch_Read_Dgram : public ACE_Asynch_Operation
/// class.
friend class ACE_POSIX_Asynch_Read_Dgram_Result;
friend class ACE_WIN32_Asynch_Read_Dgram_Result;
friend class ACE_Uring_Asynch_Read_Dgram_Result;

public:
/// The number of bytes which were requested at the start of the
Expand Down Expand Up @@ -1523,6 +1531,7 @@ class ACE_Export ACE_Asynch_Write_Dgram : public ACE_Asynch_Operation
/// class.
friend class ACE_POSIX_Asynch_Write_Dgram_Result;
friend class ACE_WIN32_Asynch_Write_Dgram_Result;
friend class ACE_Uring_Asynch_Write_Dgram_Result;

public:
/// The number of bytes which were requested at the start of the
Expand Down
71 changes: 67 additions & 4 deletions ACE/ace/POSIX_Asynch_IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ ACE_POSIX_Asynch_Result::post_completion (ACE_Proactor_Impl *proactor_impl)
// Get to the platform specific implementation.
ACE_POSIX_Proactor *posix_proactor = dynamic_cast<ACE_POSIX_Proactor *> (proactor_impl);

// Some runtimes have trouble with the direct cast from the abstract
// proactor interface to the POSIX base for callback-based proactors,
// even though the narrower AIOCB path is still valid.
if (posix_proactor == 0)
{
ACE_POSIX_AIOCB_Proactor *aiocb_proactor =
dynamic_cast<ACE_POSIX_AIOCB_Proactor *> (proactor_impl);
if (aiocb_proactor != 0)
posix_proactor = aiocb_proactor;
}

if (posix_proactor == 0)
ACELIB_ERROR_RETURN ((LM_ERROR, "Dynamic cast to POSIX Proactor failed\n"), -1);

Expand Down Expand Up @@ -1356,6 +1367,7 @@ ACE_POSIX_Asynch_Connect::connect_i (ACE_POSIX_Asynch_Connect_Result *result,
result->set_bytes_transferred (0);

ACE_HANDLE handle = result->connect_handle ();
bool created_handle = false;

if (handle == ACE_INVALID_HANDLE)
{
Expand All @@ -1366,6 +1378,7 @@ ACE_POSIX_Asynch_Connect::connect_i (ACE_POSIX_Asynch_Connect_Result *result,
0);
// save it
result->connect_handle (handle);
created_handle = (handle != ACE_INVALID_HANDLE);
if (handle == ACE_INVALID_HANDLE)
{
result->set_error (errno);
Expand All @@ -1386,6 +1399,11 @@ ACE_POSIX_Asynch_Connect::connect_i (ACE_POSIX_Asynch_Connect_Result *result,
(const char*) &one,
sizeof one) == -1 )
{
if (created_handle)
{
ACE_OS::closesocket (handle);
result->connect_handle (ACE_INVALID_HANDLE);
}
result->set_error (errno);
ACELIB_ERROR_RETURN
((LM_ERROR,
Expand All @@ -1402,6 +1420,11 @@ ACE_POSIX_Asynch_Connect::connect_i (ACE_POSIX_Asynch_Connect_Result *result,

if (ACE_OS::bind (handle, laddr, size) == -1)
{
if (created_handle)
{
ACE_OS::closesocket (handle);
result->connect_handle (ACE_INVALID_HANDLE);
}
result->set_error (errno);
ACELIB_ERROR_RETURN
((LM_ERROR,
Expand All @@ -1414,6 +1437,11 @@ ACE_POSIX_Asynch_Connect::connect_i (ACE_POSIX_Asynch_Connect_Result *result,
// set non blocking mode
if (ACE::set_flags (handle, ACE_NONBLOCK) != 0)
{
if (created_handle)
{
ACE_OS::closesocket (handle);
result->connect_handle (ACE_INVALID_HANDLE);
}
result->set_error (errno);
ACELIB_ERROR_RETURN
((LM_ERROR,
Expand All @@ -1436,6 +1464,11 @@ ACE_POSIX_Asynch_Connect::connect_i (ACE_POSIX_Asynch_Connect_Result *result,
if (errno == EINTR)
continue;

if (created_handle)
{
ACE_OS::closesocket (handle);
result->connect_handle (ACE_INVALID_HANDLE);
}
result->set_error (errno);
}

Expand Down Expand Up @@ -1829,6 +1862,9 @@ ACE_POSIX_Asynch_Transmit_Handler::~ACE_POSIX_Asynch_Transmit_Handler (void)
int
ACE_POSIX_Asynch_Transmit_Handler::transmit (void)
{
ACE_Asynch_Transmit_File::Header_And_Trailer *header_and_trailer =
this->result_->header_and_trailer ();

// No proactor is given for the <open>'s. Because we are using the
// concrete implementations of the Asynch_Operations, and we have
// already given them the specific proactor, so they wont need the
Expand All @@ -1852,9 +1888,15 @@ ACE_POSIX_Asynch_Transmit_Handler::transmit (void)
"ACE_Asynch_Transmit_Handler:write_stream open failed\n"),
-1);

// A plain file transmit may omit header/trailer altogether.
if (header_and_trailer == 0
|| header_and_trailer->header () == 0
|| header_and_trailer->header_bytes () == 0)
return this->initiate_read_file ();

// Transmit the header.
if (this->ws_.write (*this->result_->header_and_trailer ()->header (),
this->result_->header_and_trailer ()->header_bytes (),
if (this->ws_.write (*header_and_trailer->header (),
header_and_trailer->header_bytes (),
reinterpret_cast<void *> (&this->header_act_),
0) == -1)
ACELIB_ERROR_RETURN ((LM_ERROR,
Expand Down Expand Up @@ -2007,12 +2049,33 @@ ACE_POSIX_Asynch_Transmit_Handler::handle_read_file (const ACE_Asynch_Read_File:
int
ACE_POSIX_Asynch_Transmit_Handler::initiate_read_file (void)
{
ACE_Asynch_Transmit_File::Header_And_Trailer *header_and_trailer =
this->result_->header_and_trailer ();

// Is there something to read.
if (this->file_offset_ >= this->file_size_)
{
if (header_and_trailer == 0
|| header_and_trailer->trailer () == 0
|| header_and_trailer->trailer_bytes () == 0)
{
ACE_SEH_TRY
{
this->result_->complete (this->bytes_transferred_,
1,
0,
0);
}
ACE_SEH_FINALLY
{
delete this;
}
return 0;
}

// File is sent. Send the trailer.
if (this->ws_.write (*this->result_->header_and_trailer ()->trailer (),
this->result_->header_and_trailer ()->trailer_bytes (),
if (this->ws_.write (*header_and_trailer->trailer (),
header_and_trailer->trailer_bytes (),
(void *)&this->trailer_act_,
this->result_->priority (),
this->result_->signal_number ()) == -1)
Expand Down
Loading
Loading