summaryrefslogtreecommitdiff
path: root/ace/SOCK.cpp
diff options
context:
space:
mode:
authorlevine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1996-10-21 21:41:34 +0000
committerlevine <levine@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1996-10-21 21:41:34 +0000
commita5fdebc5f6375078ec1763850a4ca23ec7fe6458 (patch)
treebcf0a25c3d45a209a6e3ac37b233a4812f29c732 /ace/SOCK.cpp
downloadATCD-a5fdebc5f6375078ec1763850a4ca23ec7fe6458.tar.gz
Initial revision
Diffstat (limited to 'ace/SOCK.cpp')
-rw-r--r--ace/SOCK.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/ace/SOCK.cpp b/ace/SOCK.cpp
new file mode 100644
index 00000000000..251e9e71eac
--- /dev/null
+++ b/ace/SOCK.cpp
@@ -0,0 +1,97 @@
+// SOCK.cpp
+// $Id$
+
+#define ACE_BUILD_DLL
+#include "ace/SOCK.h"
+#include "ace/Log_Msg.h"
+
+ACE_ALLOC_HOOK_DEFINE(ACE_SOCK)
+
+#if defined (ACE_WIN32)
+// Static used to initialize WinSock.
+ACE_SOCK ACE_SOCK::dummy_;
+#endif /* ACE_WIN32 */
+
+void
+ACE_SOCK::dump (void) const
+{
+ ACE_TRACE ("ACE_SOCK::dump");
+}
+
+ACE_SOCK::ACE_SOCK (void)
+{
+ ACE_TRACE ("ACE_SOCK::ACE_SOCK");
+
+ // Make sure that we've initialized the WinSock library before using
+ // sockets!
+ ACE_OS::socket_init (ACE_WSOCK_VERSION);
+}
+
+// Returns information about the remote peer endpoint (if there is
+// one).
+
+int
+ACE_SOCK::get_remote_addr (ACE_Addr &sa) const
+{
+ ACE_TRACE ("ACE_SOCK::get_remote_addr");
+ int len = sa.get_size ();
+ sockaddr *addr = (sockaddr *) sa.get_addr ();
+
+ if (ACE_OS::getpeername (this->get_handle (), addr, &len) == -1)
+ return -1;
+
+ sa.set_size (len);
+ return 0;
+}
+
+int
+ACE_SOCK::get_local_addr (ACE_Addr &sa) const
+{
+ ACE_TRACE ("ACE_SOCK::get_local_addr");
+ int len = sa.get_size ();
+ sockaddr *addr = (sockaddr *) sa.get_addr ();
+
+ if (ACE_OS::getsockname (this->get_handle (), addr, &len) == -1)
+ return -1;
+
+ sa.set_size ((int)len);
+ return 0;
+}
+
+int
+ACE_SOCK::open (int type,
+ int protocol_family,
+ int protocol)
+{
+ ACE_TRACE ("ACE_SOCK::open");
+ this->set_handle (ACE_OS::socket (protocol_family, type, protocol));
+ return this->get_handle () == ACE_INVALID_HANDLE ? -1 : 0;
+}
+
+// Close down a ACE_SOCK.
+
+int
+ACE_SOCK::close (void)
+{
+ ACE_TRACE ("ACE_SOCK::close");
+ int result = 0;
+
+ if (this->get_handle () != ACE_INVALID_HANDLE)
+ {
+ result = ACE_OS::closesocket (this->get_handle ());
+ this->set_handle (ACE_INVALID_HANDLE);
+ }
+ return result;
+}
+
+// General purpose constructor for performing server ACE_SOCK
+// creation.
+
+ACE_SOCK::ACE_SOCK (int type,
+ int protocol_family,
+ int protocol)
+{
+ ACE_TRACE ("ACE_SOCK::ACE_SOCK");
+ if (this->open (type, protocol_family, protocol) == -1)
+ ACE_ERROR ((LM_ERROR, "%p\n", "ACE_SOCK::ACE_SOCK"));
+}