Loading...
Searching...
No Matches
UnConUDPSocket.cpp
Go to the documentation of this file.
// -*- c++ -*-
//------------------------------------------------------------------------------
// UnConUDPSocket.C
//------------------------------------------------------------------------------
// Copyright (c) 1999 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/23/99
//------------------------------------------------------------------------------
#include "assa/UnConUDPSocket.h"
#if defined (WIN32)
typedef unsigned int socklen_t;
#endif
using namespace ASSA;
int
UnConUDPSocket::
recvfrom (char* buf_, int size_, Address* peer_addr_)
{
// ::recvfrom() can return 0 bytes which is not
// considered an eof. Peer can advertise its address to
// the server by sending 0 bytes length message.
//
// char self[] = "Socket::recvfro"; trace(self);
// Setting saddr_len is crucial to proper ::recvfrom() operation.
// If left improprely initialized, ::recvfrom() won't fill in peer's
// address and won't report an error either. If SA ptr is passed to
// recvfrom() along with uninitialized address len (or set to 0),
// recvfrom() returns zeroed out address structure!!!
int len;
socklen_t pa_len = peer_addr_->getLength();
SA* pa = peer_addr_->getAddress();
#if defined (__CYGWIN32__) || defined (WIN32)
len = ::recvfrom(getHandler(), buf_, size_, 0, pa, (int*)&pa_len);
#else // posix/unix
len = ::recvfrom(getHandler(), buf_, size_, 0, pa, &pa_len);
#endif
// Q: for UNIX domain socket, returned length will be essential to
// remember and probably should be set in peer_addr_ by calling
// setLength().....
return len;
}
int
UnConUDPSocket::
sendto (const char* buf_, const unsigned int size_, const Address* peer_addr_)
{
return ::sendto (getHandler(), buf_, size_, 0,
peer_addr_->getAddress(),
peer_addr_->getLength());
}
UnConUDPSocket.h
Class UnConUPDSocket class is unconnected UDP socket.
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::UDPSocket::getHandler
handler_t getHandler() const
Get socket file descriptor.
Definition UDPSocket.h:74
ASSA::UnConUDPSocket::recvfrom
int recvfrom(char *buf_, int size_, Address *peer_addr_)
recvfrom() function receives a message from connectionless-mode socket.
Definition UnConUDPSocket.cpp:25
ASSA::UnConUDPSocket::sendto
int sendto(const char *buf_, const unsigned int size_, const Address *dest_addr_)
sendto() function sends a message through connectionless-mode socket.
Definition UnConUDPSocket.cpp:60
ASSA
Definition Acceptor.h:40
ASSA::SA
struct sockaddr SA
Definition Address.h:33