summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog29
-rw-r--r--ace/Asynch_Acceptor.cpp33
-rw-r--r--ace/Asynch_Acceptor.h8
-rw-r--r--ace/Asynch_IO.cpp6
-rw-r--r--ace/Asynch_IO.h48
-rw-r--r--ace/Asynch_IO_Impl.h3
-rw-r--r--ace/POSIX_Asynch_IO.cpp15
-rw-r--r--ace/POSIX_Asynch_IO.h3
-rw-r--r--ace/WIN32_Asynch_IO.cpp18
-rw-r--r--ace/WIN32_Asynch_IO.h3
10 files changed, 125 insertions, 41 deletions
diff --git a/ChangeLog b/ChangeLog
index 610773c1794..b04f98b3186 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,32 @@
+Mon Feb 21 12:43:41 2005 Steve Huston <shuston@riverace.com>
+
+ * ace/Asynch_IO.{h cpp} (ACE_Asynch_Accept): Added an optional
+ addr_family parameter to ACE_Asych_Accept. Defaults to AF_INET
+ (IPv4) to maintain current functionality.
+ Doxygen-ized the comments for accept().
+
+ * ace/Asynch_IO_Impl.h (ACE_Asynch_Accept_Impl): Pass the new
+ addr_family arugment along to the implementation classes.
+
+ * ace/POSIX_Asynch_IO.{h cpp}:
+ * ace/WIN32_Asynch_IO.{h cpp} (ACE_WIN32_Asynch_Accept::accept): Use
+ the new addr_family parameter to open a new accept handle if needed.
+ It is up to the caller to make sure that addr_family matches the
+ family used when the listen socket was opened.
+ Also use the address family to scale the required size
+ of the address area in the specified message block.
+
+ * Asynch_Acceptor.{h cpp}: Added a new addr_family_ member to remember
+ the in-use address family from open(). Use this value to calculate
+ the space needed for addresses, as well as passing it to
+ ACE_Asynch_Accept::accept() to open the correct type of handle
+ when needed.
+ Marked the address_size() method deprecated. It assumes use of
+ IPv4 addresses and since it's static, it can't use the addr_family_
+ knowledge. Replaced all internal uses of this with the proper
+ adjustment based on the address family in use.
+ Close the listen_handle_ when this object is destroyed.
+
Mon Feb 21 15:42:12 UTC 2005 Johnny Willemsen <jwillemsen@remedy.nl>
* bin/tao_orb_tests.lst:
diff --git a/ace/Asynch_Acceptor.cpp b/ace/Asynch_Acceptor.cpp
index 24f4fa56bdf..e94b78cd4d0 100644
--- a/ace/Asynch_Acceptor.cpp
+++ b/ace/Asynch_Acceptor.cpp
@@ -40,8 +40,8 @@ ACE_Asynch_Acceptor<HANDLER>::~ACE_Asynch_Acceptor (void)
//this->asynch_accept_.close ();
// Close down the listen socket
- // if (this->listen_handle_ != ACE_INVALID_HANDLE)
- // ACE_OS::closesocket (this->listen_handle_);
+ if (this->listen_handle_ != ACE_INVALID_HANDLE)
+ ACE_OS::closesocket (this->listen_handle_);
}
template <class HANDLER> int
@@ -62,6 +62,7 @@ ACE_Asynch_Acceptor<HANDLER>::open (const ACE_INET_Addr &address,
this->bytes_to_read_ = bytes_to_read;
this->validate_new_connection_ = validate_new_connection;
this->reissue_accept_ = reissue_accept;
+ this->addr_family_ = address.get_type ();
// Create the listener socket
this->listen_handle_ = ACE_OS::socket (address.get_type (), SOCK_STREAM, 0);
@@ -110,8 +111,8 @@ ACE_Asynch_Acceptor<HANDLER>::open (const ACE_INET_Addr &address,
if (address == sa &&
ACE::bind_port (this->listen_handle_,
- INADDR_ANY,
- address.get_type()) == -1)
+ INADDR_ANY,
+ address.get_type()) == -1)
{
ACE_Errno_Guard g (errno);
ACE_ERROR ((LM_ERROR,
@@ -200,7 +201,14 @@ ACE_Asynch_Acceptor<HANDLER>::accept (size_t bytes_to_read, const void *act)
ACE_TRACE ("ACE_Asynch_Acceptor<>::accept");
ACE_Message_Block *message_block = 0;
- size_t space_needed = bytes_to_read + 2 * this->address_size ();
+ // The space_needed calculation is drive by needs of Windows. POSIX doesn't
+ // need to extra 16 bytes, but it doesn't hurt.
+ size_t space_needed = sizeof (sockaddr_in) + 16;
+#if defined (ACE_HAS_IPV6)
+ if (this->addr_family_ = PF_INET6)
+ space_needed = sizeof (sockaddr_in6) + 16;
+#endif /* ACE_HAS_IPV6 */
+ space_needed = (2 * space_needed) + bytes_to_read;
// Create a new message block big enough for the addresses and data
ACE_NEW_RETURN (message_block,
@@ -211,7 +219,10 @@ ACE_Asynch_Acceptor<HANDLER>::accept (size_t bytes_to_read, const void *act)
if (this->asynch_accept_.accept (*message_block,
bytes_to_read,
ACE_INVALID_HANDLE,
- act) == -1)
+ act,
+ 0,
+ ACE_SIGRTMIN,
+ this->addr_family_) == -1)
{
// Cleanup on error
message_block->release ();
@@ -381,11 +392,17 @@ ACE_Asynch_Acceptor<HANDLER>::parse_address (const
sockaddr *remote_addr = 0;
int local_size = 0;
int remote_size = 0;
+ // This matches setup in accept().
+ size_t addr_size = sizeof (sockaddr_in) + 16;
+#if defined (ACE_HAS_IPV6)
+ if (this->addr_family_ == PF_INET6)
+ addr_size = sizeof (sockaddr_in6) + 16;
+#endif /* ACE_HAS_IPV6 */
::GetAcceptExSockaddrs (message_block.rd_ptr (),
static_cast<DWORD> (this->bytes_to_read_),
- static_cast<DWORD> (this->address_size ()),
- static_cast<DWORD> (this->address_size ()),
+ static_cast<DWORD> (addr_size),
+ static_cast<DWORD> (addr_size),
&local_addr,
&local_size,
&remote_addr,
diff --git a/ace/Asynch_Acceptor.h b/ace/Asynch_Acceptor.h
index a9a09b5d08c..f92bff9a884 100644
--- a/ace/Asynch_Acceptor.h
+++ b/ace/Asynch_Acceptor.h
@@ -224,7 +224,9 @@ public:
/// Set bytes to be read with the <accept> call.
virtual void bytes_to_read (size_t new_value);
- /// This is required by the AcceptEx call.
+ /// @deprecated address_size() assumes IPv4 use, so is not always valid.
+ /// This method will be removed after ACE 5.5. Internal uses have been
+ /// changes to base needed sizes on the addr_family_ member.
static size_t address_size (void);
protected:
@@ -271,6 +273,10 @@ private:
/// Bytes to be read with the <accept> call.
size_t bytes_to_read_;
+
+ /// Address family used to open this object. Obtained from @a address passed
+ /// to @c open().
+ int addr_family_;
};
#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
diff --git a/ace/Asynch_IO.cpp b/ace/Asynch_IO.cpp
index 7b652ca0525..54d3f5d9855 100644
--- a/ace/Asynch_IO.cpp
+++ b/ace/Asynch_IO.cpp
@@ -589,14 +589,16 @@ ACE_Asynch_Accept::accept (ACE_Message_Block &message_block,
ACE_HANDLE accept_handle,
const void *act,
int priority,
- int signal_number)
+ int signal_number,
+ int addr_family)
{
return this->implementation_->accept (message_block,
bytes_to_read,
accept_handle,
act,
priority,
- signal_number);
+ signal_number,
+ addr_family);
}
ACE_Asynch_Operation_Impl *
diff --git a/ace/Asynch_IO.h b/ace/Asynch_IO.h
index 4942e3d73c8..daeee961aa3 100644
--- a/ace/Asynch_IO.h
+++ b/ace/Asynch_IO.h
@@ -825,28 +825,44 @@ public:
/**
* This starts off an asynchronous accept. The asynchronous accept
* call also allows any initial data to be returned to the
- * <handler>. Upto <bytes_to_read> will be read and stored in the
- * <message_block>. The <accept_handle> will be used for the
- * <accept> call. If (<accept_handle> == INVALID_HANDLE), a new
- * handle will be created. Priority of the
- * operation is specified by <priority>. On POSIX4-Unix, this is
- * supported. Works like <nice> in Unix. Negative values are not
- * allowed. 0 means priority of the operation same as the process
- * priority. 1 means priority of the operation is one less than
- * process. And so forth. On Win32, this is a no-op.
- *
- * <message_block> must be specified. This is because the address of
- * the new connection is placed at the end of this buffer.
- * <signal_number> is the POSIX4 real-time signal number to be used
- * for the operation. <signal_number> ranges from ACE_SIGRTMIN to
- * ACE_SIGRTMAX. This argument is a no-op on non-POSIX4 systems.
+ * handler specified to @c open().
+ * @param message_block A message block to receive initial data, as well
+ * as the local and remote addresses when the
+ * connection is made. Since the block receives
+ * the addresses regardless of whether or not
+ * initial data is available or requested, the
+ * message block size must be at least
+ * @a bytes_to_read plus two times the size of
+ * the addresses used (IPv4 or IPv6).
+ * @param bytes_to_read The maximum number of bytes of initial data
+ * to read into @a message_block.
+ * @param accept_handle The handle that the new connection will be
+ * accepted on. If @c INVALID_HANDLE, a new
+ * handle will be created using @a addr_family.
+ * @param act Value to be passed in result when operation
+ * completes.
+ * @param priority Priority of the operation. On POSIX4-Unix, this
+ * is supported. Works like @c nice in Unix.
+ * Negative values are not allowed. 0 means
+ * priority of the operation same as the process
+ * priority. 1 means priority of the operation is
+ * one less than process. And so forth.
+ * On Win32, this argument is ignored.
+ * @param signal_number The POSIX4 real-time signal number to be used
+ * for the operation. Value range is from
+ * @c ACE_SIGRTMIN to @c ACE_SIGRTMAX.
+ * This argument is ignored on non-POSIX4 systems.
+ * @param addr_family The address family to use if @a accept_handle
+ * is @c ACE_INVALID_HANDLE and a new handle must
+ * be opened. Values are @c AF_INET and @c PF_INET6.
*/
int accept (ACE_Message_Block &message_block,
size_t bytes_to_read,
ACE_HANDLE accept_handle = ACE_INVALID_HANDLE,
const void *act = 0,
int priority = 0,
- int signal_number = ACE_SIGRTMIN);
+ int signal_number = ACE_SIGRTMIN,
+ int addr_family = AF_INET);
/// Return the underlying implementation class.
// (this should be protected...)
diff --git a/ace/Asynch_IO_Impl.h b/ace/Asynch_IO_Impl.h
index 5657c2c49dc..3742b48a24e 100644
--- a/ace/Asynch_IO_Impl.h
+++ b/ace/Asynch_IO_Impl.h
@@ -483,7 +483,8 @@ public:
ACE_HANDLE accept_handle,
const void *act,
int priority,
- int signal_number) = 0;
+ int signal_number,
+ int addr_family) = 0;
protected:
/// Do-nothing constructor.
diff --git a/ace/POSIX_Asynch_IO.cpp b/ace/POSIX_Asynch_IO.cpp
index e03b6d8ae1b..c4eef31cd4a 100644
--- a/ace/POSIX_Asynch_IO.cpp
+++ b/ace/POSIX_Asynch_IO.cpp
@@ -896,7 +896,8 @@ ACE_POSIX_Asynch_Accept::accept (ACE_Message_Block &message_block,
ACE_HANDLE accept_handle,
const void *act,
int priority,
- int signal_number)
+ int signal_number,
+ int addr_family)
{
ACE_TRACE (ACE_LIB_TEXT("ACE_POSIX_Asynch_Accept::accept\n"));
@@ -911,10 +912,14 @@ ACE_POSIX_Asynch_Accept::accept (ACE_Message_Block &message_block,
// Sanity check: make sure that enough space has been allocated by
// the caller.
- size_t address_size = sizeof (sockaddr_in) + sizeof (sockaddr);
- size_t space_in_use = message_block.wr_ptr () - message_block.base ();
- size_t total_size = message_block.size ();
- size_t available_space = total_size - space_in_use;
+ size_t address_size = sizeof (sockaddr_in);
+#if defined (ACE_HAS_IPV6)
+ if (addr_family == AF_INET6)
+ address_size = sizeof (sockaddr_in6);
+#else
+ ACE_UNUSED_ARG (addr_family);
+#endif
+ size_t available_space = message_block.space ();
size_t space_needed = bytes_to_read + 2 * address_size;
if (available_space < space_needed)
diff --git a/ace/POSIX_Asynch_IO.h b/ace/POSIX_Asynch_IO.h
index 405b6dc9f85..d90365a0be0 100644
--- a/ace/POSIX_Asynch_IO.h
+++ b/ace/POSIX_Asynch_IO.h
@@ -697,7 +697,8 @@ public:
ACE_HANDLE accept_handle,
const void *act,
int priority,
- int signal_number = 0);
+ int signal_number = 0,
+ int addr_family = AF_INET);
/**
* Cancel all pending pseudo-asynchronus requests
diff --git a/ace/WIN32_Asynch_IO.cpp b/ace/WIN32_Asynch_IO.cpp
index b88ae61b5f4..ed50a210ab5 100644
--- a/ace/WIN32_Asynch_IO.cpp
+++ b/ace/WIN32_Asynch_IO.cpp
@@ -2028,15 +2028,20 @@ ACE_WIN32_Asynch_Accept::accept (ACE_Message_Block &message_block,
ACE_HANDLE accept_handle,
const void *act,
int priority,
- int signal_number)
+ int signal_number,
+ int addr_family)
{
#if (defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)) || (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0))
// Sanity check: make sure that enough space has been allocated by
// the caller.
- size_t address_size = sizeof (sockaddr_in) + sizeof (sockaddr);
- size_t space_in_use = message_block.wr_ptr () - message_block.base ();
- size_t total_size = message_block.size ();
- size_t available_space = total_size - space_in_use;
+ size_t address_size =
+#if defined (ACE_HAS_IPV6)
+ addr_family == AF_INET ? sizeof (sockaddr_in) : sizeof (sockaddr_in6);
+#else
+ sizeof (sockaddr_in);
+#endif /* ACE_HAS_IPV6 */
+ address_size += 16; // AcceptEx requires address size + 16 (minimum)
+ size_t available_space = message_block.space ();
size_t space_needed = bytes_to_read + 2 * address_size;
if (available_space < space_needed)
ACE_ERROR_RETURN ((LM_ERROR, ACE_LIB_TEXT ("Buffer too small\n")), -1);
@@ -2055,7 +2060,7 @@ ACE_WIN32_Asynch_Accept::accept (ACE_Message_Block &message_block,
// If the <accept_handle> is invalid, we will create a new socket.
if (accept_handle == ACE_INVALID_HANDLE)
{
- accept_handle = ACE_OS::socket (PF_INET,
+ accept_handle = ACE_OS::socket (addr_family,
SOCK_STREAM,
0);
if (accept_handle == ACE_INVALID_HANDLE)
@@ -2137,6 +2142,7 @@ ACE_WIN32_Asynch_Accept::accept (ACE_Message_Block &message_block,
ACE_UNUSED_ARG (act);
ACE_UNUSED_ARG (priority);
ACE_UNUSED_ARG (signal_number);
+ ACE_UNUSED_ARG (addr_family);
ACE_NOTSUP_RETURN (-1);
#endif /* (defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)) || (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)) || (defined (ACE_HAS_AIO_CALLS) */
}
diff --git a/ace/WIN32_Asynch_IO.h b/ace/WIN32_Asynch_IO.h
index c9d26ff00a6..8d414b1027a 100644
--- a/ace/WIN32_Asynch_IO.h
+++ b/ace/WIN32_Asynch_IO.h
@@ -1103,7 +1103,8 @@ public:
ACE_HANDLE accept_handle,
const void *act,
int priority,
- int signal_number = 0);
+ int signal_number = 0,
+ int addr_family = AF_INET);
/// Destructor.
~ACE_WIN32_Asynch_Accept (void);