Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replacing use of ::select in favor of ::poll #1044

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 45 additions & 3 deletions ACE/ace/SSL/SSL_SOCK_Acceptor.cpp
Expand Up @@ -10,6 +10,11 @@
#include "ace/Countdown_Time.h"
#include "ace/Truncate.h"


#if defined (ACE_HAS_POLL)
# include "ace/OS_NS_poll.h"
#endif /* ACE_HAS_POLL */

#if !defined (__ACE_INLINE__)
#include "SSL_SOCK_Acceptor.inl"
#endif /* __ACE_INLINE__ */
Expand Down Expand Up @@ -65,10 +70,16 @@ ACE_SSL_SOCK_Acceptor::ssl_accept (ACE_SSL_SOCK_Stream &new_stream,
int status;
do
{
#if defined (ACE_HAS_POLL)
struct pollfd fds;
ACE_OS::memset(&fds, 0, sizeof(fds));
fds.revents = 0;
#else
// These handle sets are used to set up for whatever SSL_accept
// says it wants next. They're reset on each pass around the loop.
ACE_Handle_Set rd_handle;
ACE_Handle_Set wr_handle;
#endif /* ACE_HAS_POLL */

status = ::SSL_accept (ssl);
switch (::SSL_get_error (ssl, status))
Expand All @@ -78,12 +89,22 @@ ACE_SSL_SOCK_Acceptor::ssl_accept (ACE_SSL_SOCK_Stream &new_stream,
break; // Done

case SSL_ERROR_WANT_WRITE:
#if defined (ACE_HAS_POLL)
fds.fd = handle;
fds.events = POLLOUT;
#else
wr_handle.set_bit (handle);
#endif /* ACE_HAS_POLL */
status = 1; // Wait for more activity
break;

case SSL_ERROR_WANT_READ:
#if defined (ACE_HAS_POLL)
fds.fd = handle;
fds.events = POLLIN;
#else
rd_handle.set_bit (handle);
#endif /* ACE_HAS_POLL */
status = 1; // Wait for more activity
break;

Expand Down Expand Up @@ -111,11 +132,27 @@ ACE_SSL_SOCK_Acceptor::ssl_accept (ACE_SSL_SOCK_Stream &new_stream,
// Use that to decide what to do.
status = 1; // Wait for more activity
if (SSL_want_write (ssl))
wr_handle.set_bit (handle);
{
#if defined (ACE_HAS_POLL)
fds.fd = handle;
fds.events = POLLOUT;
#else
wr_handle.set_bit (handle);
#endif /* ACE_HAS_POLL */
}
else if (SSL_want_read (ssl))
rd_handle.set_bit (handle);
{
#if defined (ACE_HAS_POLL)
fds.fd = handle;
fds.events = POLLIN;
#else
rd_handle.set_bit (handle);
#endif /* ACE_HAS_POLL */
}
else
status = -1; // Doesn't want anything - bail out
{
status = -1; // Doesn't want anything - bail out
}
}
else
status = -1;
Expand All @@ -129,13 +166,18 @@ ACE_SSL_SOCK_Acceptor::ssl_accept (ACE_SSL_SOCK_Stream &new_stream,

if (status == 1)
{
#if defined (ACE_HAS_POLL)
ACE_ASSERT(fds.fd != 0);
status = ACE_OS::poll(&fds, 1, timeout);
#else
// Must have at least one handle to wait for at this point.
ACE_ASSERT (rd_handle.num_set() == 1 || wr_handle.num_set () == 1);
status = ACE::select (int (handle) + 1,
&rd_handle,
&wr_handle,
0,
timeout);
#endif /* ACE_HAS_POLL */

(void) countdown.update ();

Expand Down
35 changes: 35 additions & 0 deletions ACE/ace/SSL/SSL_SOCK_Connector.cpp
Expand Up @@ -10,6 +10,10 @@

#include <openssl/err.h>

#if defined (ACE_HAS_POLL)
# include "ace/OS_NS_poll.h"
#endif /* ACE_HAS_POLL */

#if !defined (__ACE_INLINE__)
#include "SSL_SOCK_Connector.inl"
#endif /* __ACE_INLINE__ */
Expand Down Expand Up @@ -71,10 +75,16 @@ ACE_SSL_SOCK_Connector::ssl_connect (ACE_SSL_SOCK_Stream &new_stream,

do
{
#if defined (ACE_HAS_POLL)
struct pollfd fds;
ACE_OS::memset(&fds, 0, sizeof(fds));
fds.revents = 0;
#else
// These handle sets are used to set up for whatever SSL_connect
// says it wants next. They're reset on each pass around the loop.
ACE_Handle_Set rd_handle;
ACE_Handle_Set wr_handle;
#endif /* ACE_HAS_POLL */

status = ::SSL_connect (ssl);
switch (::SSL_get_error (ssl, status))
Expand All @@ -86,12 +96,22 @@ ACE_SSL_SOCK_Connector::ssl_connect (ACE_SSL_SOCK_Stream &new_stream,
break; // Done

case SSL_ERROR_WANT_WRITE:
#if defined (ACE_HAS_POLL)
fds.fd = handle;
fds.events = POLLOUT;
#else
wr_handle.set_bit (handle);
#endif /* ACE_HAS_POLL */
status = 1; // Wait for more activity
break;

case SSL_ERROR_WANT_READ:
#if defined (ACE_HAS_POLL)
fds.fd = handle;
fds.events = POLLIN;
#else
rd_handle.set_bit (handle);
#endif /* ACE_HAS_POLL */
status = 1; // Wait for more activity
break;

Expand Down Expand Up @@ -120,11 +140,21 @@ ACE_SSL_SOCK_Connector::ssl_connect (ACE_SSL_SOCK_Stream &new_stream,
status = 1; // Wait for more activity
if (SSL_want_write (ssl))
{
#if defined (ACE_HAS_POLL)
fds.fd = handle;
fds.events = POLLOUT;
#else
wr_handle.set_bit (handle);
#endif /* ACE_HAS_POLL */
}
else if (SSL_want_read (ssl))
{
#if defined (ACE_HAS_POLL)
fds.fd = handle;
fds.events = POLLIN;
#else
rd_handle.set_bit (handle);
#endif /* ACE_HAS_POLL */
}
else
{
Expand All @@ -146,6 +176,10 @@ ACE_SSL_SOCK_Connector::ssl_connect (ACE_SSL_SOCK_Stream &new_stream,

if (status == 1)
{
#if defined (ACE_HAS_POLL)
ACE_ASSERT(fds.fd != 0);
status = ACE_OS::poll(&fds, 1, timeout);
#else
// Must have at least one handle to wait for at this point.
ACE_ASSERT (rd_handle.num_set () == 1 || wr_handle.num_set () == 1);

Expand All @@ -155,6 +189,7 @@ ACE_SSL_SOCK_Connector::ssl_connect (ACE_SSL_SOCK_Stream &new_stream,
&wr_handle,
0,
(timeout == 0 ? 0 : &t));
#endif /* ACE_HAS_POLL */

(void) countdown.update ();

Expand Down