/*
Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Her Majesty the
Queen in Right of Canada (Communications Research Center Canada)
*/
/*
This file is part of ODR-DabMux.
ODR-DabMux is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
ODR-DabMux is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ODR-DabMux. If not, see .
*/
#include "UdpSocket.h"
#include
#include
#include
#include
#include
#ifdef TRACE_ON
# ifndef TRACE_CLASS
# define TRACE_CLASS(class, func) cout <<"-" <<(class) <<"\t(" < newSize)
length = newSize;
if (tmp) {
memcpy(tmp, dataBuf, length);
delete []dataBuf;
dataBuf = tmp;
size = newSize;
}
}
/**
* Give the pointer to data. It is ajusted with the \a offset.
* @warning This pointer change. when the \a size of the buffer and the \a offset change.
* @return The pointer
*/
char *UdpPacket::getData()
{
return dataBuf + offset;
}
/**
* Add some data at the end of data buffer and adjust size.
* @param data Pointer to the data to add
* @param size Size in bytes of new data
*/
void UdpPacket::addData(const void *data, unsigned size)
{
if (length + size > this->size) {
setSize(this->size << 1);
}
memcpy(dataBuf + length, data, size);
length += size;
}
/**
* Returns the length of useful data. Data before the \a offset are ignored.
* @return The data length
*/
unsigned long UdpPacket::getLength()
{
return length - offset;
}
/**
* Returns the size of the data buffer.
* @return The data buffer size
*/
unsigned long UdpPacket::getSize()
{
return size;
}
/**
* Returns the offset value.
* @return The offset value
*/
unsigned long UdpPacket::getOffset()
{
return offset;
}
/**
* Sets the data length value. Data before the \a offset are ignored.
* @param len The new length of data
*/
void UdpPacket::setLength(unsigned long len)
{
length = len + offset;
}
/**
* Sets the data offset. Data length is ajusted to ignore data before the \a offset.
* @param val The new data offset.
*/
void UdpPacket::setOffset(unsigned long val)
{
offset = val;
if (offset > length)
length = offset;
}
/**
* Returns the UDP address of the data.
* @return The UDP address
*/
InetAddress &UdpPacket::getAddress()
{
return address;
}
/*
WSAEINTR
WSAEBADF
WSAEACCES
WSAEFAULT
WSAEINVAL
WSAEMFILE
WSAEWOULDBLOCK
WSAEINPROGRESS
WSAEALREADY
WSAENOTSOCK
WSAEDESTADDRREQ
WSAEMSGSIZE
WSAEPROTOTYPE
WSAENOPROTOOPT
WSAEPROTONOSUPPORT
WSAESOCKTNOSUPPORT
WSAEOPNOTSUPP
WSAEPFNOSUPPORT
WSAEAFNOSUPPORT
WSAEADDRINUSE
WSAEADDRNOTAVAIL
WSAENETDOWN
WSAENETUNREACH
WSAENETRESET
WSAECONNABORTED
WSAECONNRESET
WSAENOBUFS
WSAEISCONN
WSAENOTCONN
WSAESHUTDOWN
WSAETOOMANYREFS
WSAETIMEDOUT
WSAECONNREFUSED
WSAELOOP
WSAENAMETOOLONG
WSAEHOSTDOWN
WSAEHOSTUNREACH
WSAENOTEMPTY
WSAEPROCLIM
WSAEUSERS
WSAEDQUOT
WSAESTALE
WSAEREMOTE
WSAEDISCON
WSASYSNOTREADY
WSAVERNOTSUPPORTED
WSANOTINITIALISED
*/