00001 #include "ace_pch.h"
00002
00003
00004
00005 #include "ace/SOCK_CODgram.h"
00006 #include "ace/Log_Msg.h"
00007
00008 #if defined (ACE_LACKS_INLINE_FUNCTIONS)
00009 #include "ace/SOCK_CODgram.i"
00010 #endif
00011
00012 ACE_RCSID(ace, SOCK_CODgram, "$Id: SOCK_CODgram.cpp,v 1.1.1.3.40.1 2003/03/13 19:44:22 chad Exp $")
00013
00014 ACE_ALLOC_HOOK_DEFINE(ACE_SOCK_CODgram)
00015
00016 void
00017 ACE_SOCK_CODgram::dump (void) const
00018 {
00019 ACE_TRACE ("ACE_SOCK_CODgram::dump");
00020 }
00021
00022
00023
00024 ACE_SOCK_CODgram::ACE_SOCK_CODgram (const ACE_Addr &remote, const ACE_Addr &local,
00025 int protocol_family, int protocol,
00026 int reuse_addr)
00027 {
00028 ACE_TRACE ("ACE_SOCK_CODgram::ACE_SOCK_CODgram");
00029 if (this->open (remote, local,
00030 protocol_family, protocol, reuse_addr) == -1)
00031 ACE_ERROR ((LM_ERROR, ACE_LIB_TEXT ("%p\n"), ACE_LIB_TEXT ("ACE_SOCK_CODgram")));
00032 }
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 int
00056 ACE_SOCK_CODgram::open (const ACE_Addr &remote, const ACE_Addr &local,
00057 int protocol_family, int protocol,
00058 int reuse_addr)
00059 {
00060 ACE_TRACE ("ACE_SOCK_CODgram::open");
00061 if (ACE_SOCK::open (SOCK_DGRAM, protocol_family,
00062 protocol, reuse_addr) == -1)
00063 return -1;
00064 else
00065 {
00066 int error = 0;
00067
00068 if (local == ACE_Addr::sap_any && remote == ACE_Addr::sap_any)
00069 {
00070
00071
00072 if (protocol_family == PF_INET
00073 && ACE::bind_port (this->get_handle ()) == -1)
00074 error = 1;
00075 }
00076
00077 else if (local != ACE_Addr::sap_any && remote == ACE_Addr::sap_any)
00078 {
00079 if (ACE_OS::bind (this->get_handle (), (sockaddr *) local.get_addr (),
00080 local.get_size ()) == -1)
00081 error = 1;
00082 }
00083
00084 else if (local == ACE_Addr::sap_any && remote != ACE_Addr::sap_any)
00085 {
00086 if (ACE_OS::connect (this->get_handle (), (sockaddr *) remote.get_addr (),
00087 remote.get_size ()) == -1)
00088 error = 1;
00089 }
00090
00091
00092 else
00093 {
00094 if (ACE_OS::bind (this->get_handle (), (sockaddr *) local.get_addr (),
00095 local.get_size ()) == -1
00096 || ACE_OS::connect (this->get_handle (), (sockaddr *) remote.get_addr (),
00097 remote.get_size ()) == -1)
00098 error = 1;
00099 }
00100 if (error)
00101 {
00102 this->close ();
00103 this->set_handle (ACE_INVALID_HANDLE);
00104 }
00105 return error ? -1 : 0;
00106 }
00107 }