00001 // -*- c++ -*- 00002 //------------------------------------------------------------------------------ 00003 // UDPSocket.C 00004 //------------------------------------------------------------------------------ 00005 // Copyright (c) 2000 by Vladislav Grinchenko 00006 // 00007 // This library is free software; you can redistribute it and/or 00008 // modify it under the terms of the GNU Library General Public 00009 // License as published by the Free Software Foundation; either 00010 // version 2 of the License, or (at your option) any later version. 00011 // 00012 //------------------------------------------------------------------------------ 00013 // Created: 03/22/99 00014 //------------------------------------------------------------------------------ 00015 00016 #include "assa/UDPSocket.h" 00017 00018 using namespace ASSA; 00019 00020 bool 00021 UDPSocket:: 00022 open (const int domain_) 00023 { 00024 trace("UDPSocket::open"); 00025 00026 m_type = domain_; 00027 m_fd = ::socket (m_type, SOCK_DGRAM, 0); 00028 00029 if (m_fd < 0) { 00030 setstate (Socket::failbit); 00031 return false; 00032 } 00033 clear (); 00034 return true; 00035 } 00036 00037 bool 00038 UDPSocket:: 00039 close () 00040 { 00041 trace("UDPSocket::close()"); 00042 if ( m_fd >= 0 ) { 00043 ::close(m_fd); 00044 setstate (Socket::failbit); 00045 m_fd = -1; 00046 } 00047 return true; 00048 } 00049 00050 bool 00051 UDPSocket:: 00052 bind (const Address& my_address_) 00053 { 00054 trace("UDPSocket::bind"); 00055 00056 int ret = ::bind (m_fd, (SA*) my_address_.getAddress(), 00057 my_address_.getLength()); 00058 if (ret < 0) { 00059 setstate (Socket::failbit); 00060 return false; 00061 } 00062 return true; 00063 } 00064 00065 00066