Loading...
Searching...
No Matches
UDPSocket.cpp
Go to the documentation of this file.
// -*- c++ -*-
//------------------------------------------------------------------------------
// UDPSocket.C
//------------------------------------------------------------------------------
// Copyright (c) 2000 by Vladislav Grinchenko
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
//------------------------------------------------------------------------------
// Created: 03/22/99
//------------------------------------------------------------------------------
#include "assa/UDPSocket.h"
using namespace ASSA;
bool
UDPSocket::
open (const int domain_)
{
trace("UDPSocket::open");
m_type = domain_;
m_fd = ::socket (m_type, SOCK_DGRAM, 0);
if (m_fd < 0) {
setstate (Socket::failbit);
return false;
}
clear ();
return true;
}
bool
UDPSocket::
close ()
{
trace("UDPSocket::close()");
if ( m_fd >= 0 ) {
::close(m_fd);
setstate (Socket::failbit);
m_fd = -1;
}
return true;
}
bool
UDPSocket::
bind (const Address& my_address_)
{
trace("UDPSocket::bind");
int ret = ::bind (m_fd, (SA*) my_address_.getAddress(),
my_address_.getLength());
if (ret < 0) {
setstate (Socket::failbit);
return false;
}
return true;
}
trace
#define trace(s)
trace() is used to trace function call chain in C++ program.
Definition Logger.h:429
UDPSocket.h
Class UDPSocket is an implementation of UNIX domain socket that is the base class for more specialize...
ASSA::Address
Definition Address.h:51
ASSA::Address::getAddress
virtual SA * getAddress() const =0
Retrieve pointer to the address structure.
ASSA::Address::getLength
virtual const int getLength() const =0
Return length of the underlying address structure.
ASSA::Socket::m_type
int m_type
Socket domain type.
Definition Socket.h:488
ASSA::Socket::setstate
void setstate(iostate flag_)
Set socket state to flag_ by adding flag_ to the existing state.
Definition Socket.h:577
ASSA::Socket::m_fd
handler_t m_fd
File descriptor.
Definition Socket.h:485
ASSA::Socket::clear
void clear(iostate state_=Socket::goodbit)
Clear the socket state. Closed socket remains in bad state.
Definition Socket.h:571
ASSA::Socket::failbit
@ failbit
indicates that an input operation failed to read the expected characters, or that an output operation...
Definition Socket.h:84
ASSA::UDPSocket::open
bool open(const int domain_)
Create socket.
Definition UDPSocket.cpp:22
ASSA::UDPSocket::bind
bool bind(const Address &my_address_)
Server in UDP client-server scenario has to bind socket to its local well-known port.
Definition UDPSocket.cpp:52
ASSA::UDPSocket::close
bool close()
Close socket connection.
Definition UDPSocket.cpp:39
ASSA
Definition Acceptor.h:40
ASSA::SA
struct sockaddr SA
Definition Address.h:33