This class abstracts a UNIX socket descriptor. More...
#include <DwmSocket.hh>


Public Member Functions | |
| Socket () | |
| Constructor. | |
| Socket (const Socket &sock) | |
| Copy constructor. More... | |
| Socket & | operator= (const Socket &sock) |
| operator = (assignment operator). | |
| operator bool () const | |
| virtual bool | Open (int domain, int type, int protocol) |
| Opens the socket. More... | |
| int | Type () const |
| virtual Socket | Accept (struct sockaddr_in &addr) |
| Calls the UNIX accept(2) function. Returns the resulting socket. | |
| virtual Socket | Accept (Ipv4Address &addr, uint16_t &port) |
| Calls accept() on the socket and returns the resulting socket. More... | |
| virtual bool | Accept (Socket &s, struct sockaddr_in &addr) |
Calls the UNIX accept() function for the given socket s and attaches *this to the return if successful. More... | |
| virtual bool | Accept (Socket &s, Ipv4Address &addr, uint16_t &port) |
Calls the UNIX accept() function for the given socket s and attaches *this to the return if successful. More... | |
| virtual Socket | Accept (struct sockaddr_un &addr) |
| Calls the UNIX accept(2) function. Returns the resulting socket. | |
| virtual bool | Accept (Socket &s, struct sockaddr_un &addr) |
| virtual bool | Listen (int backlog) |
| Calls the UNIX listen(2) function. More... | |
| virtual bool | Bind (const struct sockaddr_in &addr) |
| Calls the UNIX bind(2) function. More... | |
| virtual bool | Bind (const Ipv4Address &addr, uint16_t port) |
Bind to the given IPv4 address addr and port. More... | |
| virtual bool | Bind (const struct sockaddr_un &addr) |
| Calls the UNIX bind(2) function. More... | |
| virtual bool | Connect (const struct sockaddr_in &name) |
| Calls the UNIX connect(2) function. More... | |
| virtual bool | Connect (const Ipv4Address &dstAddr, uint16_t port) |
Connect to the given IPv4 address dstAddr at the given port. More... | |
| virtual bool | Connect (const struct sockaddr_un &name) |
| Calls the UNIX connect(2) function. More... | |
| virtual bool | Getpeername (struct sockaddr *name, socklen_t &namelen) |
| Calls the UNIX getpeername(2) function. Returns true on success,. | |
| virtual bool | Getpeername (Ipv4Address &addr, uint16_t &port) |
| Calls getpeername() on the socket. More... | |
| virtual bool | Getsockname (struct sockaddr *name, socklen_t &namelen) |
| Calls the UNIX getsockname(2) function. Returns true on success,. | |
| virtual bool | Getsockname (Ipv4Address &addr, uint16_t &port) |
| Calls getsockname() on the socket. More... | |
| virtual bool | Setsockopt (int level, int optname, const void *optval, socklen_t optlen) |
| Calls the UNIX setsockopt(2) function. Returns true on success,. | |
| virtual bool | Getsockopt (int level, int optname, void *optval, socklen_t &optlen) |
| Calls the UNIX setsockopt(2) function. Returns true on success,. | |
| virtual ssize_t | RecvFrom (void *buf, size_t len, int flags, struct sockaddr_in &from) |
| Calls the UNIX recvfrom(2) function. | |
| virtual ssize_t | RecvFrom (void *buf, size_t len, int flags, Ipv4Address &srcAddr, uint16_t &srcPort) |
| Calls recvfrom() on the socket. More... | |
| virtual ssize_t | RecvFrom (std::string &s, int flags, Ipv4Address &srcAddr, uint16_t &srcPort) |
| Calls recvfrom() on the socket. More... | |
| virtual ssize_t | SendTo (const void *buf, size_t len, int flags, const struct sockaddr_in &to) |
| Calls the UNIX sendto(2) function. | |
| virtual ssize_t | SendTo (const void *buf, size_t len, int flags, const Ipv4Address &dstAddr, uint16_t dstPort) |
Calls sendto() on the socket, sending the given buffer buf of length len to the given destination address and port. More... | |
| virtual ssize_t | SendTo (const std::string &s, int flags, const Ipv4Address &dstAddr, uint16_t dstPort) |
Calls sendto() on the socket, sending the given string s to the given destination and port. More... | |
| virtual bool | JoinMulticastGroup (const Ipv4Address &groupAddr, const Ipv4Address &intfAddr) |
Join the given multicast group groupAddr on the given interface address intfAddr. More... | |
| bool | HeaderIncluded () const |
Public Member Functions inherited from Dwm::Descriptor | |
| Descriptor () | |
| Constructor. | |
| Descriptor (const Descriptor &d) | |
Copy constructor. Will dup() the descriptor of d. | |
| Descriptor (int d) | |
| Descriptor & | operator= (const Descriptor &d) |
| operator = (assignment operator). More... | |
| virtual | ~Descriptor () |
| Destructor. Note this will close the underlying UNIX descriptor. | |
| virtual bool | Close () |
| Closes the Descriptor. Returns true on success, false on failure. | |
| virtual bool | Attach (int fd) |
Associates the Descriptor with an existing UNIX descriptor fd. More... | |
| virtual bool | Detach () |
| Disassociates the Descriptor from the underlying UNIX descriptor. More... | |
| virtual bool | SetNonBlocking () |
| Sets the Descriptor to non-blocking. More... | |
| virtual bool | SetBlocking () |
| Sets the soccket to blocking. More... | |
| virtual | operator int () const |
| This completely blows encapsulation, but is needed so that Descriptor may be used in place of a UNIX descriptor in retrofitted code. More... | |
| virtual bool | FdSet (fd_set &fdSet) |
If Descriptor is valid, sets it in fdSet and returns true. More... | |
| virtual bool | FdClr (fd_set &fdSet) |
If Descriptor is valid, clears it in fdSet and returns true. More... | |
| virtual bool | FdIsSet (fd_set &fdSet) |
If Descriptor is valid and is set in fdSet, returns true. More... | |
| virtual bool | ReadWouldBlock () |
Protected Attributes | |
| int | _type |
| bool | _headerIncluded |
Protected Attributes inherited from Dwm::Descriptor | |
| int | _fd |
This class abstracts a UNIX socket descriptor.
| Dwm::Socket::Socket | ( | const Socket & | sock | ) |
Copy constructor.
Note we use dup() to duplicate the underlying UNIX socket descriptor, which allows us to close the underlying UNIX socket descriptor in our destructor.
|
virtual |
Calls accept() on the socket and returns the resulting socket.
If successful, addr will be set to the peer's address and port will be set to the peer's port.
|
virtual |
Calls the UNIX accept() function for the given socket s and attaches *this to the return if successful.
Returns true on success, false on failure. addr is a result parameter and will contain the address of the remote connection on success.
|
virtual |
Calls the UNIX accept() function for the given socket s and attaches *this to the return if successful.
Returns true on success, false on failure. addr and port are result parameters and will contain the address and port of the remote connection on success.
|
virtual |
Calls the UNIX bind(2) function.
Returns true on success, false on failure.
|
virtual |
Bind to the given IPv4 address addr and port.
Returns true on success, false on failure.
|
virtual |
Calls the UNIX bind(2) function.
Returns true on success, false on failure.
|
virtual |
Calls the UNIX connect(2) function.
Returns true on success, false on failure.
|
virtual |
Connect to the given IPv4 address dstAddr at the given port.
Returns true on success, false on failure.
|
virtual |
Calls the UNIX connect(2) function.
Returns true on success, false on failure.
|
virtual |
Calls getpeername() on the socket.
Returns true on success, false on failure. addr and port are result parameters, and will contain the address and port of the peer on success.
|
virtual |
Calls getsockname() on the socket.
Returns true on success, false on failure. addr and port are result parameters and will contain the address and port of the socket on success. Note this only works on IPv4 sockets, not UNIX domain sockets.
|
virtual |
Join the given multicast group groupAddr on the given interface address intfAddr.
Returns true on success, false on failure.
|
virtual |
Calls the UNIX listen(2) function.
Returns true on success, false on failure.
|
virtual |
Opens the socket.
Note this just calls the UNIX socket(2) function, and takes the same arguments. Returns true on success, false on failure.
|
virtual |
Calls recvfrom() on the socket.
A buffer buf of length len must be provided by the caller to receive the data. flags is passed to the recvfrom() function (see the recvfrom manpage). On success, returns the number of bytes received and sets srcAddr and srcPort to the source address and port of the received packet.
|
virtual |
Calls recvfrom() on the socket.
On success, stores the received data in s, the source address in srcAddr and the source port in srcPort and returns the number of bytes received. On failure, returns -1. Note that may contain embedded nulls and should NOT be treated like a C string; use s.size() to determine how much data was stored.
|
virtual |
Calls sendto() on the socket, sending the given buffer buf of length len to the given destination address and port.
Returns the number of bytes sent on success, -1 on failure.
|
virtual |
Calls sendto() on the socket, sending the given string s to the given destination and port.
flags is passed on to sendto() (see the sendto() manpage). On success, returns the number of bytes sent which should be the same as s.size(). On failure, returns -1. Note that s can contain binary data, including nulls, but can not be longer than 65535 bytes (the maximum size of an IP packet) minus the length of the transport header and any IP header options.