Loading...
Searching...
No Matches
ConUDPSocket.cpp
Go to the documentation of this file.
// -*- c++ -*-
//------------------------------------------------------------------------
// ConUDPSocket.cpp
//------------------------------------------------------------------------------
// Copyright (C) 1999 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.
//------------------------------------------------------------------------
#ifndef WIN32
#include "assa/ConUDPSocket.h"
#include "assa/UNIXAddress.h"
#include "assa/INETAddress.h"
using namespace ASSA;
bool
ConUDPSocket::
connect (const Address& peer_address_)
{
char self[] = "ConUDPSocket::connect"; trace(self);
if ( ::connect (getHandler(),peer_address_.getAddress(),
peer_address_.getLength()) < 0 ) {
setstate (Socket::failbit);
return false;
}
return true;
}
void
ConUDPSocket::
unconnect()
{
// Ignore errors here. On some systems connect() might return
// EAFNOSUPPORT error, on some might not, but it is OK.
//
char self[] = "ConUDPSocket::unconnect"; trace(self);
if ( getDomain() == AF_INET ) {
INETAddress addr;
SA_IN* addrp = (SA_IN*) addr.getAddress();
addrp->sin_family = AF_UNSPEC;
(void) connect(addr);
}
else { // AF_LOCAL
// I haven't tested whether it works at all.
UNIXAddress addr("");
SA_UN* addrp = (SA_UN*) addr.getAddress();
addrp->sun_family = AF_UNSPEC;
(void) connect(addr);
}
}
int
ConUDPSocket::
read(char* packet_, const unsigned int size_)
{
int len;
len = ::read(getHandler(), packet_, size_);
if (len == -1) {
setstate (Socket::failbit);
}
else if ( len == 0 ) {
setstate (Socket::failbit | Socket::eofbit);
}
return len;
}
int
ConUDPSocket::
write (const char* packet_, const unsigned int size_)
{
return ::write(getHandler(), (const void*) packet_, size_);
}
#endif // WIN32
ConUDPSocket.h
Encapsulation of a connected UDP socket.
INETAddress.h
An incapsulation of TCP/UDP Internet Protocol socket address structure.
trace
#define trace(s)
trace() is used to trace function call chain in C++ program.
Definition Logger.h:429
UNIXAddress.h
UNIXAddress encapsulates UNIX domain socket address structure.
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::ConUDPSocket::connect
bool connect(const Address &peer_addr_)
Connect socket to the peer.
Definition ConUDPSocket.cpp:23
ASSA::ConUDPSocket::unconnect
void unconnect()
Unconnect connected socket.
Definition ConUDPSocket.cpp:37
ASSA::ConUDPSocket::write
int write(const char *buf_=NULL, const unsigned int size_=0)
Perform blocking write by writing packet of specified size.
Definition ConUDPSocket.cpp:80
ASSA::ConUDPSocket::read
int read(char *buf_, const unsigned int size_)
Read specified number of bytes off the socket.
Definition ConUDPSocket.cpp:64
ASSA::INETAddress
Definition INETAddress.h:27
ASSA::INETAddress::getAddress
SA * getAddress() const
Get hold of address structure.
Definition INETAddress.h:110
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::eofbit
@ eofbit
indicates that an input operation reached the end of an input sequence
Definition Socket.h:82
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::getDomain
const int getDomain() const
Get socket domain type.
Definition UDPSocket.h:77
ASSA::UDPSocket::getHandler
handler_t getHandler() const
Get socket file descriptor.
Definition UDPSocket.h:74
ASSA::UNIXAddress
Definition UNIXAddress.h:28
ASSA::UNIXAddress::getAddress
SA * getAddress() const
Retrieve underlying address structure.
Definition UNIXAddress.h:64
ASSA
Definition Acceptor.h:40
ASSA::SA_IN
struct sockaddr_in SA_IN
Definition Address.h:34
ASSA::SA_UN
struct sockaddr_un SA_UN
Definition Address.h:44