summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornanbor <nanbor@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2000-02-01 23:27:39 +0000
committernanbor <nanbor@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2000-02-01 23:27:39 +0000
commite18ff12c8e08df2e24b8d07913d868616539da6f (patch)
tree26e4a8c1fd4ba36c6694a83258ad382b6eca22cb
parent3fb5b8807f96a1b66c7430d99cd91889cc14b0b4 (diff)
downloadATCD-e18ff12c8e08df2e24b8d07913d868616539da6f.tar.gz
*** empty log message ***
-rw-r--r--ace/MEM_Acceptor.cpp45
-rw-r--r--ace/MEM_Acceptor.h47
-rw-r--r--ace/MEM_Acceptor.i49
-rw-r--r--ace/MEM_Connector.cpp42
-rw-r--r--ace/MEM_Connector.h18
-rw-r--r--ace/MEM_IO.h8
-rw-r--r--ace/MEM_IO.i19
-rw-r--r--ace/OS.h10
-rw-r--r--examples/IPC_SAP/SOCK_SAP/CPP-inserver.cpp13
-rw-r--r--examples/IPC_SAP/SOCK_SAP/CPP-memclient.cpp9
-rw-r--r--examples/IPC_SAP/SOCK_SAP/CPP-memserver.cpp13
11 files changed, 209 insertions, 64 deletions
diff --git a/ace/MEM_Acceptor.cpp b/ace/MEM_Acceptor.cpp
index 817f9b36e0e..c2414f1093c 100644
--- a/ace/MEM_Acceptor.cpp
+++ b/ace/MEM_Acceptor.cpp
@@ -27,33 +27,50 @@ ACE_MEM_Acceptor::ACE_MEM_Acceptor (void)
// General purpose routine for performing server ACE_SOCK creation.
-ACE_MEM_Acceptor::ACE_MEM_Acceptor (const ACE_Addr &remote_sap,
+ACE_MEM_Acceptor::ACE_MEM_Acceptor (const u_short local_port,
int reuse_addr,
- int protocol_family,
int backlog,
int protocol)
{
ACE_TRACE ("ACE_MEM_Acceptor::ACE_MEM_Acceptor");
- if (this->open (remote_sap,
+ if (this->open (local_port,
reuse_addr,
- protocol_family,
backlog,
protocol) == -1)
ACE_ERROR ((LM_ERROR,
"ACE_MEM_Acceptor::ACE_MEM_Acceptor"));
}
+ACE_MEM_Acceptor::open (const u_short local_port,
+ int reuse_addr,
+ int back_log,
+ int protocol)
+{
+ ACE_TRACE ("ACE_MEM_Acceptor::open");
+ ACE_INET_Addr local_addr (local_port,
+ ASYS_TEXT ("localhost"));
+
+ return this->ACE_SOCK_Acceptor::open (local_addr,
+ reuse_addr,
+ PF_INET,
+ back_log,
+ protocol);
+}
+
// General purpose routine for accepting new connections.
int
ACE_MEM_Acceptor::accept (ACE_MEM_Stream &new_stream,
- ACE_Addr *remote_addr,
+ u_short *remote_port,
ACE_Time_Value *timeout,
int restart,
int reset_new_handle) const
{
ACE_TRACE ("ACE_MEM_Acceptor::accept");
+ int *len_ptr = 0;
+ sockaddr *addr = 0;
+
int in_blocking_mode = 0;
if (this->shared_accept_start (timeout,
restart,
@@ -61,17 +78,6 @@ ACE_MEM_Acceptor::accept (ACE_MEM_Stream &new_stream,
return -1;
else
{
- int *len_ptr = 0;
- sockaddr *addr = 0;
- int len = 0;
-
- if (remote_addr != 0)
- {
- len = remote_addr->get_size ();
- len_ptr = &len;
- addr = (sockaddr *) remote_addr->get_addr ();
- }
-
do
new_stream.set_handle (ACE_OS::accept (this->get_handle (),
addr,
@@ -81,11 +87,8 @@ ACE_MEM_Acceptor::accept (ACE_MEM_Stream &new_stream,
&& errno == EINTR
&& timeout == 0);
- // Reset the size of the addr, which is only necessary for UNIX
- // domain sockets.
- if (new_stream.get_handle () != ACE_INVALID_HANDLE
- && remote_addr != 0)
- remote_addr->set_size (len);
+ if (remote_port != 0)
+ *remote_port = (* (sockaddr_in*) addr).sin_port;
}
if (this->shared_accept_finish (new_stream,
diff --git a/ace/MEM_Acceptor.h b/ace/MEM_Acceptor.h
index 762c06f5b90..1c9fddd10c9 100644
--- a/ace/MEM_Acceptor.h
+++ b/ace/MEM_Acceptor.h
@@ -44,15 +44,24 @@ public:
ACE_MEM_Acceptor (void);
// Default constructor.
- ACE_MEM_Acceptor (const ACE_Addr &local_sap,
+ ACE_MEM_Acceptor (const u_short local_port,
int reuse_addr = 0,
- int protocol_family = PF_INET,
int backlog = ACE_DEFAULT_BACKLOG,
int protocol = 0);
// Initiate a passive mode socket.
+ int open (const u_short local_port,
+ int reuse_addr = 0,
+ int backlog = ACE_DEFAULT_BACKLOG,
+ int protocol = 0);
+ // Initialize a passive-mode BSD-style acceptor socket (no QoS).
+ // <local_sap> is the address that we're going to listen for
+ // connections on. If <reuse_addr> is 1 then we'll use the
+ // <SO_REUSEADDR> to reuse this address. Returns 0 on success and
+ // -1 on failure.
+
int accept (ACE_MEM_Stream &new_ipc_sap,
- ACE_Addr * = 0,
+ u_short * = 0,
ACE_Time_Value *timeout = 0,
int restart = 1,
int reset_new_handle = 0) const;
@@ -65,7 +74,7 @@ public:
// called.
// = Meta-type info
- typedef ACE_Addr PEER_ADDR;
+ typedef u_short PEER_ADDR;
typedef ACE_MEM_Stream PEER_STREAM;
void dump (void) const;
@@ -73,6 +82,36 @@ public:
ACE_ALLOC_HOOK_DECLARE;
// Declare the dynamic allocation hooks.
+
+protected:
+ // = The following methods should not be accessable externally.
+ int open (const ACE_Addr &local_sap,
+ int reuse_addr = 0,
+ int protocol_family = PF_INET,
+ int backlog = ACE_DEFAULT_BACKLOG,
+ int protocol = 0);
+
+ int open (const ACE_Addr &local_sap,
+ ACE_Protocol_Info *protocolinfo,
+ ACE_SOCK_GROUP g,
+ u_long flags,
+ int reuse_addr,
+ int protocol_family,
+ int backlog = ACE_DEFAULT_BACKLOG,
+ int protocol = 0);
+
+ int accept (ACE_SOCK_Stream &new_stream,
+ ACE_Addr *remote_addr = 0,
+ ACE_Time_Value *timeout = 0,
+ int restart = 1,
+ int reset_new_handle = 0) const;
+
+ int accept (ACE_SOCK_Stream &new_stream,
+ ACE_Accept_QoS_Params qos_params,
+ ACE_Addr *remote_addr = 0,
+ ACE_Time_Value *timeout = 0,
+ int restart = 1,
+ int reset_new_handle = 0) const;
};
#if defined (__ACE_INLINE__)
diff --git a/ace/MEM_Acceptor.i b/ace/MEM_Acceptor.i
index b7ae3f98891..63190298626 100644
--- a/ace/MEM_Acceptor.i
+++ b/ace/MEM_Acceptor.i
@@ -2,3 +2,52 @@
// $Id$
// MEM_Acceptor.i
+
+ASYS_INLINE int
+ACE_MEM_Acceptor::open (const ACE_Addr &local_sap,
+ int reuse_addr,
+ int protocol_family,
+ int backlog,
+ int protocol)
+{
+ return this->ACE_SOCK_Acceptor:: open
+ (local_sap, reuse_addr, protocol_family, backlog, protocol);
+}
+
+ASYS_INLINE int
+ACE_MEM_Acceptor::open (const ACE_Addr &local_sap,
+ ACE_Protocol_Info *protocolinfo,
+ ACE_SOCK_GROUP g,
+ u_long flags,
+ int reuse_addr,
+ int protocol_family,
+ int backlog,
+ int protocol)
+{
+ return this->ACE_SOCK_Acceptor::open
+ (local_sap, protocolinfo, g, flags, reuse_addr, protocol_family,
+ backlog, protocol);
+}
+
+ASYS_INLINE int
+ACE_MEM_Acceptor::accept (ACE_SOCK_Stream &new_stream,
+ ACE_Addr *remote_addr,
+ ACE_Time_Value *timeout,
+ int restart,
+ int reset_new_handle) const
+{
+ return this->ACE_SOCK_Acceptor::accept
+ (new_stream, remote_addr, timeout, restart, reset_new_handle);
+}
+
+ASYS_INLINE int
+ACE_MEM_Acceptor::accept (ACE_SOCK_Stream &new_stream,
+ ACE_Accept_QoS_Params qos_params,
+ ACE_Addr *remote_addr,
+ ACE_Time_Value *timeout,
+ int restart,
+ int reset_new_handle) const
+{
+ return this->ACE_SOCK_Acceptor::accept
+ (new_stream, qos_params, remote_addr, timeout, restart, reset_new_handle);
+}
diff --git a/ace/MEM_Connector.cpp b/ace/MEM_Connector.cpp
index a46daf8283f..94957e85d52 100644
--- a/ace/MEM_Connector.cpp
+++ b/ace/MEM_Connector.cpp
@@ -29,48 +29,62 @@ ACE_MEM_Connector::ACE_MEM_Connector (void)
// Establish a connection.
ACE_MEM_Connector::ACE_MEM_Connector (ACE_MEM_Stream &new_stream,
- const ACE_INET_Addr &remote_sap,
+ const u_short remote_port,
ACE_Time_Value *timeout,
- const ACE_Addr &local_sap,
+ const u_short &local_port,
int reuse_addr,
int flags,
int perms,
- int protocol_family,
int protocol)
{
ACE_TRACE ("ACE_MEM_Connector::ACE_MEM_Connector");
// This is necessary due to the weird inheritance relationships of
// ACE_MEM_Stream.
this->connect (new_stream,
- remote_sap,
+ remote_port,
timeout,
- local_sap,
+ local_port,
reuse_addr,
flags,
perms,
- protocol_family,
protocol);
}
int
ACE_MEM_Connector::connect (ACE_MEM_Stream &new_stream,
- const ACE_INET_Addr &remote_sap,
+ const u_short remote_port,
ACE_Time_Value *timeout,
- const ACE_Addr &local_sap,
+ const u_short &local_port,
int reuse_addr,
int flags,
int perms,
- int protocol_family,
int protocol)
{
ACE_TRACE ("ACE_MEM_Connector::connect");
ACE_SOCK_Stream temp_stream;
- if (ACE_SOCK_Connector::connect (temp_stream, remote_sap,
- timeout, local_sap,
- reuse_addr, flags, perms,
- protocol_family, protocol) == -1)
- return -1;
+ ACE_INET_Addr remote_sap = ACE_INET_Addr (remote_port,
+ ASYS_TEXT ("localhost"));
+
+ if (local_port != 0)
+ {
+ ACE_INET_Addr local_sap = ACE_INET_Addr (local_port,
+ ASYS_TEXT ("localhost"));
+
+ if (ACE_SOCK_Connector::connect (temp_stream, remote_sap,
+ timeout, local_sap,
+ reuse_addr, flags, perms,
+ PF_INET, protocol) == -1)
+ return -1;
+ }
+ else
+ {
+ if (ACE_SOCK_Connector::connect (temp_stream, remote_sap,
+ timeout, ACE_Addr::sap_any,
+ reuse_addr, flags, perms,
+ PF_INET, protocol) == -1)
+ return -1;
+ }
ACE_HANDLE new_handle = temp_stream.get_handle ();
new_stream.set_handle (new_handle);
diff --git a/ace/MEM_Connector.h b/ace/MEM_Connector.h
index 72013c1f077..da2b692e9c7 100644
--- a/ace/MEM_Connector.h
+++ b/ace/MEM_Connector.h
@@ -24,7 +24,7 @@
#include "ace/SOCK_Connector.h"
#include "ace/MEM_Stream.h"
-class ACE_Export ACE_MEM_Connector : public ACE_SOCK_Connector
+class ACE_Export ACE_MEM_Connector : protected ACE_SOCK_Connector
{
// = TITLE
// Defines the format and interface for the connector side of
@@ -35,13 +35,12 @@ public:
// Default constructor.
ACE_MEM_Connector (ACE_MEM_Stream &new_stream,
- const ACE_INET_Addr &remote_sap,
+ const u_short remote_port,
ACE_Time_Value *timeout = 0,
- const ACE_Addr &local_sap = ACE_Addr::sap_any,
+ const u_short &local_sap = 0,
int reuse_addr = 0,
int flags = 0,
int perms = 0,
- int protocol_family = PF_INET,
int protocol = 0);
// Actively connect and produce a <new_stream> if things go well.
// The <remote_sap> is the address that we are trying to connect
@@ -53,18 +52,17 @@ public:
// this is the amount of time to wait before timing out. If the
// time expires before the connection is made <errno == ETIME>. The
// <local_sap> is the value of local address to bind to. If it's
- // the default value of <ACE_Addr::sap_any> then the user is letting
+ // the default value of <0> then the user is letting
// the OS do the binding. If <reuse_addr> == 1 then the
// <local_addr> is reused, even if it hasn't been cleanedup yet.
int connect (ACE_MEM_Stream &new_stream,
- const ACE_INET_Addr &remote_sap,
+ const u_short remote_port,
ACE_Time_Value *timeout = 0,
- const ACE_Addr &local_sap = ACE_Addr::sap_any,
+ const u_short &local_sap = 0,
int reuse_addr = 0,
int flags = 0,
int perms = 0,
- int protcol_family = PF_INET,
int protocol = 0);
// Actively connect and produce a <new_stream> if things go well.
// The <remote_sap> is the address that we are trying to connect
@@ -76,12 +74,12 @@ public:
// this is the amount of time to wait before timing out. If the
// time expires before the connection is made <errno == ETIME>. The
// <local_sap> is the value of local address to bind to. If it's
- // the default value of <ACE_Addr::sap_any> then the user is letting
+ // the default value of <0> then the user is letting
// the OS do the binding. If <reuse_addr> == 1 then the
// <local_addr> is reused, even if it hasn't been cleanedup yet.
// = Meta-type info
- typedef ACE_Addr PEER_ADDR;
+ typedef u_short PEER_ADDR;
typedef ACE_MEM_Stream PEER_STREAM;
void dump (void) const;
diff --git a/ace/MEM_IO.h b/ace/MEM_IO.h
index 754490c2967..de7d8963b2f 100644
--- a/ace/MEM_IO.h
+++ b/ace/MEM_IO.h
@@ -145,6 +145,14 @@ public:
ACE_ALLOC_HOOK_DECLARE;
// Declare the dynamic allocation hooks.
+ /* int get_local_port (u_short &) const;
+ // Return the local endpoint port number. Returns 0 if successful,
+ // else -1.
+
+ int get_remote_port (u_short &) const;
+ // Return the port number of the remotely connected peer (if there
+ // is one). Returns 0 if successful, else -1.
+ */
private:
void *recv_buffer_;
// Internal pointer for support recv/send.
diff --git a/ace/MEM_IO.i b/ace/MEM_IO.i
index ec3fc4d7fad..46a9a4535fd 100644
--- a/ace/MEM_IO.i
+++ b/ace/MEM_IO.i
@@ -211,3 +211,22 @@ ACE_MEM_IO::recv (void *buf,
return count;
}
+/*
+ASYS_INLINE int
+ACE_MEM_IO::get_local_port (u_short &x) const
+{
+ ACE_Addr addr;
+ int retv = ACE_SOCK::get_local_addr (addr);
+ x = addr.get_port_number ();
+ return retv;
+}
+
+ASYS_INLINE int
+ACE_MEM_IO::get_remote_port (u_short &x) const
+{
+ ACE_Addr addr;
+ int retv = ACE_SOCK::get_remote_addr (addr);
+ x = addr.get_port_number ();
+ return retv;
+}
+*/
diff --git a/ace/OS.h b/ace/OS.h
index 116d3c66eca..10ab896fcc7 100644
--- a/ace/OS.h
+++ b/ace/OS.h
@@ -1632,7 +1632,7 @@ private: ACE_Time_Value *max_wait_time_;
# define ACE_SOCK_CONNECTOR ACE_SOCK_Connector
# define ACE_SOCK_STREAM ACE_SOCK_Stream
-// Handle ACE_SOCK_*
+// Handle ACE_MEM_*
# define ACE_MEM_ACCEPTOR ACE_MEM_Acceptor
# define ACE_MEM_CONNECTOR ACE_MEM_Connector
# define ACE_MEM_STREAM ACE_MEM_Stream
@@ -1713,10 +1713,10 @@ private: ACE_Time_Value *max_wait_time_;
# define ACE_SOCK_CONNECTOR ACE_SOCK_Connector, ACE_INET_Addr
# define ACE_SOCK_STREAM ACE_SOCK_Stream, ACE_INET_Addr
-// Handle ACE_SOCK_*
-# define ACE_MEM_ACCEPTOR ACE_MEM_Acceptor, ACE_INET_Addr
-# define ACE_MEM_CONNECTOR ACE_MEM_Connector, ACE_INET_Addr
-# define ACE_MEM_STREAM ACE_MEM_Stream, ACE_INET_Addr
+// Handle ACE_MEM_*
+# define ACE_MEM_ACCEPTOR ACE_MEM_Acceptor, u_short
+# define ACE_MEM_CONNECTOR ACE_MEM_Connector, u_short
+# define ACE_MEM_STREAM ACE_MEM_Stream, u_short
// Handle ACE_LSOCK_*
# define ACE_LSOCK_ACCEPTOR ACE_LSOCK_Acceptor, ACE_UNIX_Addr
diff --git a/examples/IPC_SAP/SOCK_SAP/CPP-inserver.cpp b/examples/IPC_SAP/SOCK_SAP/CPP-inserver.cpp
index c51840de7e7..0789e4ad843 100644
--- a/examples/IPC_SAP/SOCK_SAP/CPP-inserver.cpp
+++ b/examples/IPC_SAP/SOCK_SAP/CPP-inserver.cpp
@@ -338,9 +338,11 @@ run_event_loop (u_short port)
"(%P|%t) select timed out\n"));
else
{
+ ACE_INET_Addr x_factor;
if (temp.is_set (twoway_acceptor.get_handle ()))
{
- if (twoway_acceptor.accept (new_stream) == -1)
+ if (twoway_acceptor.accept (new_stream,
+ &x_factor) == -1)
{
ACE_ERROR ((LM_ERROR,
"%p\n",
@@ -351,13 +353,17 @@ run_event_loop (u_short port)
ACE_DEBUG ((LM_DEBUG,
"(%P|%t) spawning twoway server\n"));
+ ACE_DEBUG ((LM_DEBUG, "(%P|%t) *** Got x_factor: %s:%d\n",
+ x_factor.get_host_name (),
+ x_factor.get_port_number ()));
+
// Run the twoway server.
run_server (twoway_server,
new_stream.get_handle ());
}
if (temp.is_set (oneway_acceptor.get_handle ()))
{
- if (oneway_acceptor.accept (new_stream) == -1)
+ if (oneway_acceptor.accept (new_stream, &x_factor) == -1)
{
ACE_ERROR ((LM_ERROR, "%p\n", "accept"));
continue;
@@ -366,6 +372,9 @@ run_event_loop (u_short port)
ACE_DEBUG ((LM_DEBUG,
"(%P|%t) spawning oneway server\n"));
+ ACE_DEBUG ((LM_DEBUG, "(%P|%t) *** Got x_factor: %s:%d\n",
+ x_factor.get_host_name (),
+ x_factor.get_port_number ()));
// Run the oneway server.
run_server (oneway_server,
new_stream.get_handle ());
diff --git a/examples/IPC_SAP/SOCK_SAP/CPP-memclient.cpp b/examples/IPC_SAP/SOCK_SAP/CPP-memclient.cpp
index 616cd30b6fe..e96c72abab6 100644
--- a/examples/IPC_SAP/SOCK_SAP/CPP-memclient.cpp
+++ b/examples/IPC_SAP/SOCK_SAP/CPP-memclient.cpp
@@ -19,16 +19,19 @@ ACE_RCSID(SOCK_SAP, CPP_inclient, "$Id$")
static int
run_client (void)
{
- ACE_INET_Addr server_addr(ACE_DEFAULT_SERVER_PORT, "localhost");
ACE_MEM_Connector connector;
ACE_MEM_Stream stream;
- if (connector.connect (stream, server_addr) == -1)
+ if (connector.connect (stream, ACE_DEFAULT_SERVER_PORT) == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "connect"), -1);
char buf [MAXPATHLEN];
while (gets (buf) >0)
- stream.send (buf, ACE_OS::strlen (buf)+1);
+ {
+ stream.send (buf, ACE_OS::strlen (buf)+1);
+ stream.recv (buf, MAXPATHLEN);
+ ACE_DEBUG ((LM_DEBUG, "Echo: %s\n", buf));
+ }
return 0;
}
diff --git a/examples/IPC_SAP/SOCK_SAP/CPP-memserver.cpp b/examples/IPC_SAP/SOCK_SAP/CPP-memserver.cpp
index f5f1fc78ce5..107b58fd762 100644
--- a/examples/IPC_SAP/SOCK_SAP/CPP-memserver.cpp
+++ b/examples/IPC_SAP/SOCK_SAP/CPP-memserver.cpp
@@ -18,11 +18,10 @@ run_event_loop (u_short port)
// Create the acceptors.
ACE_MEM_Acceptor acceptor;
- // Create the server addresses.
- ACE_INET_Addr server_addr (port, "localhost");
+ ACE_INET_Addr server_addr;
// Create acceptors, reuse the address.
- if (acceptor.open (server_addr, 1) == -1)
+ if (acceptor.open (port, 1) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"%p\n",
"open"),
@@ -49,8 +48,12 @@ run_event_loop (u_short port)
-1);
char buf[MAXPATHLEN];
- while (new_stream.recv (buf, MAXPATHLEN) != -1)
- ACE_DEBUG ((LM_DEBUG, "%s\n", buf));
+ int len = 0;
+ while ((len = new_stream.recv (buf, MAXPATHLEN)) != -1)
+ {
+ ACE_DEBUG ((LM_DEBUG, "%s\n", buf));
+ new_stream.send (buf, len);
+ }
return new_stream.remove ();
}