#include <rludpsocket.h>
|
| rlUdpSocket (int debug=0) |
|
virtual | ~rlUdpSocket () |
|
int | setSockopt (int opt) |
|
int | setSockopt (int level, int optname, void *optval, int optlen) |
|
int | bind (int port) |
|
int | select (int timeout) |
|
int | recvfrom (void *buf, int maxlen, rlIpAdr *source, int timeout=-1) |
|
int | sendto (const void *buf, int len, rlIpAdr *dest) |
|
int | printf (rlIpAdr *dest, const char *format,...) |
|
class for encapsulating UDP socket calls
Definition at line 53 of file rludpsocket.h.
rlUdpSocket::rlUdpSocket |
( |
int |
debug = 0 | ) |
|
Definition at line 72 of file rludpsocket.cpp.
{
s = socket(AF_INET,SOCK_DGRAM,0);
{
::printf(
"rlUdpSocket::rlUdpSocket could not get socket\n");
}
}
rlUdpSocket::~rlUdpSocket |
( |
| ) |
|
|
virtual |
int rlUdpSocket::bind |
( |
int |
port | ) |
|
return > 0 -> socket else error
Definition at line 122 of file rludpsocket.cpp.
{
if(port < 0 || port >= 256*256) return -1;
address.sin_port = htons((
short) port);
address.sin_addr.s_addr = htonl(INADDR_ANY);
{
::printf(
"rlUdpSocket::setAdr() bind() failed port=%d\n", port);
return -1;
}
return 0;
}
int rlUdpSocket::printf |
( |
rlIpAdr * |
dest, |
|
|
const char * |
format, |
|
|
|
... |
|
) |
| |
return >= 0 -> number of bytes written else error
Definition at line 218 of file rludpsocket.cpp.
{
int ret;
va_list ap;
va_start(ap,format);
va_end(ap);
if(ret < 0) return ret;
return sendto(message,strlen(message)+1,dest);
}
int rlUdpSocket::recvfrom |
( |
void * |
buf, |
|
|
int |
maxlen, |
|
|
rlIpAdr * |
source, |
|
|
int |
timeout = -1 |
|
) |
| |
return > 0 -> number of bytes read return == 0 -> timeout else error
Definition at line 160 of file rludpsocket.cpp.
{
int ret, len;
if(timeout >= 0)
{
if(ret != 1) return -1;
}
#ifdef RLWIN32
(
struct sockaddr *) &source->
address, (
int FAR *) &len);
#endif
#ifdef RLUNIX
(
struct sockaddr *) &source->
address, (socklen_t *) &len);
#endif
#ifdef __VMS
(
struct sockaddr *) &source->
address, (
size_t *) &len);
#endif
if(ret < 0)
{
::printf(
"ERROR: rlUdpSocket::read()\n");
return -2;
}
{
unsigned char *cbuf = (unsigned char *) buf;
::printf(
"rlUdpSocket()::recvfrom() ret=%d data=[0x%x",ret,cbuf[0]);
for(
int i=1; i<ret; i++) ::
printf(
",0x%x",cbuf[i]);
}
return ret;
}
int rlUdpSocket::select |
( |
int |
timeout | ) |
|
return == 0 -> timeout
Definition at line 139 of file rludpsocket.cpp.
{
if(timeout < 0) return -1;
struct timeval timout;
fd_set wset,rset,eset;
int ret,maxfdp1;
FD_ZERO(&rset);
FD_ZERO(&wset);
FD_ZERO(&eset);
timout.tv_sec = timeout / 1000;
timout.tv_usec = (timeout % 1000) * 1000;
ret =
::select(maxfdp1,&rset,&wset,&eset,&timout);
if(ret == 0) return 0;
return 1;
}
int rlUdpSocket::sendto |
( |
const void * |
buf, |
|
|
int |
len, |
|
|
rlIpAdr * |
dest |
|
) |
| |
return >= 0 -> number of bytes written else error
Definition at line 198 of file rludpsocket.cpp.
{
#ifdef RLWIN32
(
struct sockaddr *) &dest->
address,
sizeof(
struct sockaddr_in));
#else
(
struct sockaddr *) &dest->
address,
sizeof(
struct sockaddr_in));
#endif
if(ret < 0)
::printf(
"ERROR: rlUdpSocket::sendto()\n");
{
unsigned char *cbuf = (unsigned char *) buf;
::printf(
"rlUdpSocket()::sendto() ret=%d data=[0x%x",ret,cbuf[0]);
for(
int i=1; i<ret; i++) ::
printf(
",0x%x",cbuf[i]);
}
return ret;
}
int rlUdpSocket::setSockopt |
( |
int |
opt | ) |
|
setsocketopt for SOL_SOCKET level
Definition at line 98 of file rludpsocket.cpp.
{
const int on = 1;
#ifdef RLWIN32
return setsockopt(
s,SOL_SOCKET,opt,(
const char *) &on,
sizeof(on));
#else
return setsockopt(
s,SOL_SOCKET,opt,&on,
sizeof(on));
#endif
}
int rlUdpSocket::setSockopt |
( |
int |
level, |
|
|
int |
optname, |
|
|
void * |
optval, |
|
|
int |
optlen |
|
) |
| |
setsocketopt with full control
Definition at line 110 of file rludpsocket.cpp.
{
if(optlen <= 0) return -1;
#ifdef RLWIN32
return setsockopt(
s,level,optname,(
const char *) &optval,optlen);
#else
return setsockopt(
s,level,optname,optval,optlen);
#endif
}
struct sockaddr_in rlUdpSocket::address |
|
private |
int rlUdpSocket::readflag |
int rlUdpSocket::writeflag |
The documentation for this class was generated from the following files: