1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
// -*- 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());
}
|