ONPOSIX  2.0
 All Classes Namespaces Files Functions Variables Enumerator Friends Macros Pages
DgramSocketClientDescriptor Class Reference

Class for a connection-less client. More...

#include <DgramSocketClientDescriptor.hpp>

Inheritance diagram for DgramSocketClientDescriptor:
Inheritance graph

Public Member Functions

virtual ~DgramSocketClientDescriptor ()
 DgramSocketClientDescriptor (const std::string &name)
 Constructor for local (i.e., AF_UNIX) sockets.
 DgramSocketClientDescriptor (const std::string &address, const uint16_t port)
 Constructor for UDP (i.e., AF_INET) sockets.
- Public Member Functions inherited from PosixDescriptor
virtual ~PosixDescriptor ()
 Destructor.
void async_read (void(*handler)(Buffer *b, size_t size), Buffer *b, size_t size)
 Run asynchronous read operation.
void async_read (void(*handler)(void *b, size_t size), void *b, size_t size)
 Run asynchronous read operation.
void async_write (void(*handler)(Buffer *b, size_t size), Buffer *b, size_t size)
 Run asynchronous write operation.
void async_write (void(*handler)(void *b, size_t size), void *b, size_t size)
 Run asynchronous write operation.
int read (Buffer *b, size_t size)
 Method to read from the descriptor and fill a buffer.
int read (void *p, size_t size)
 Method to read from the descriptor.
int write (Buffer *b, size_t size)
 Method to write data in a buffer to the descriptor.
int write (const void *p, size_t size)
 Method to write to the descriptor.
int write (const std::string &s)
 Method to write a string to the descriptor.
virtual void close ()
 Method to close the descriptor.
int getDescriptorNumber () const
 Method to get descriptor number.
 PosixDescriptor (const PosixDescriptor &src)
 Copy constructor.
PosixDescriptoroperator= (const PosixDescriptor &src)
 Assignment operator.
bool flush ()
 Method to flush this specific descriptor.
int ioctl (int request)
 Ioctl on the file descriptor.
int ioctl (int request, void *argp)
 Ioctl on the file descriptor.

Additional Inherited Members

- Protected Member Functions inherited from PosixDescriptor
int do_read (void *p, size_t size)
 Low-level read.
int do_write (const void *p, size_t size)
 Low-level write.
 PosixDescriptor ()
 Constructor.
- Protected Attributes inherited from PosixDescriptor
int fd_
 Number of the file descriptor.

Detailed Description

Class for a connection-less client.

Definition at line 31 of file DgramSocketClientDescriptor.hpp.

Constructor & Destructor Documentation

virtual ~DgramSocketClientDescriptor ( )
inlinevirtual

Definition at line 33 of file DgramSocketClientDescriptor.hpp.

{}
DgramSocketClientDescriptor ( const std::string &  name)

Constructor for local (i.e., AF_UNIX) sockets.

It calls socket()+connect().

Parameters
nameName of the local socket on the filesystem
Exceptions
runtime_errorin case of error in socket() or connect()

Definition at line 38 of file DgramSocketClientDescriptor.cpp.

{
// socket()
fd_ = socket(AF_UNIX, SOCK_DGRAM, 0);
if (fd_ < 0) {
ERROR("Client socket creation");
throw std::runtime_error ("Client socket error");
}
// connect()
struct sockaddr_un serv_addr;
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sun_family = AF_UNIX;
strncpy(serv_addr.sun_path, name.c_str(), sizeof(serv_addr.sun_path) - 1);
if (connect(fd_, (struct sockaddr *) &serv_addr,
sizeof(serv_addr)) < 0) {
ERROR("connect()");
throw std::runtime_error ("Client socket error");
}
}

Here is the call graph for this function:

DgramSocketClientDescriptor ( const std::string &  address,
const uint16_t  port 
)

Constructor for UDP (i.e., AF_INET) sockets.

It calls socket()+connect().

Parameters
portPort of the socket
Exceptions
runtime_errorin case of error in socket() or connect()

Definition at line 68 of file DgramSocketClientDescriptor.cpp.

{
// socket()
fd_ = socket(AF_INET, SOCK_DGRAM, 0);
if (fd_ < 0) {
ERROR("Client socket creation");
throw std::runtime_error ("Client socket error");
}
// connect()
struct sockaddr_in serv_addr;
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(port);
struct in_addr addr;
inet_aton(address.c_str(), &addr);
bcopy(&addr, &serv_addr.sin_addr.s_addr, sizeof(addr));
if (connect(fd_, (struct sockaddr *) &serv_addr,
sizeof(serv_addr)) < 0) {
ERROR("connect()");
throw std::runtime_error ("Client socket error");
}
}

Here is the call graph for this function:


The documentation for this class was generated from the following files: