Evo C++ Library v0.5.1
|
#include <evo/iosock.h>
Socket for I/O casting (datagram/UDP).
Public Member Functions | |
SocketCast (bool exceptions=1) | |
Constructor. More... | |
SocketCast (SocketAddressBase *address, bool exceptions=1) | |
Constructor. More... | |
~SocketCast () | |
Destructor. More... | |
bool | bind (const SocketAddressBase &address, int socktype=SOCK_DGRAM, int protocol=0) |
Create and bind datagram socket to address (read/write). More... | |
bool | cast (const SocketAddressBase *address=NULL, int family=AF_UNSPEC, int socktype=SOCK_DGRAM, int protocol=0) |
Create unbound datagram socket for casting (write only). More... | |
void | close () |
Close socket. More... | |
Error | error () const |
Get error code from last operation. More... | |
template<class TOut > | |
TOut & | errormsg_out (TOut &out) |
Write detailed error message with errno to output stream/string. More... | |
bool | excep () const |
Get whether exceptions are enabled. More... | |
void | excep (bool val) |
Set whether exceptions are enabled. More... | |
virtual bool | flush () |
Flush any pending output in stream write buffer, if buffered. More... | |
template<class T > | |
T * | get_opt (int level, int optname, T *buf) |
Get socket option value. More... | |
Long | get_opt_num (int level, int optname) |
Get socket option flag or numeric value. More... | |
ulong | get_timeout () const |
Get timeout for socket operations. More... | |
virtual bool | isopen () const |
Get whether stream is open. More... | |
operator SafeBoolType () const | |
Safe (explicit) evaluation as bool type. More... | |
bool | operator! () const |
Negation operator checks whether an error was set by a previous operation. More... | |
ulong | read (void *buf, ulong size, int flags=0, SocketAddressBase *address=NULL) |
Read message from socket. More... | |
ulong | readbin (void *buf, ulong size) |
Read binary input from stream. More... | |
template<class T > | |
bool | set_opt (int level, int optname, const T &val) |
Set socket option value. More... | |
bool | set_opt_num (int level, int optname, long val) |
Set socket option flag or numeric value. More... | |
SocketCast & | set_timeout (ulong timeout_ms) |
Set timeout for socket operations. More... | |
ulong | write (const void *buf, ulong size, int flags=0, const SocketAddressBase *address=NULL) |
Write message to socket. More... | |
ulong | writebin (const void *buf, ulong size) |
Write binary output to stream. More... | |
Protected Attributes | |
Error | error_ |
Last error code. More... | |
bool | excep_ |
Whether to throw exceptions. More... | |
|
inline |
Constructor.
exceptions | Whether to enable exceptions on error, default set by Evo config: EVO_EXCEPTIONS |
|
inline |
Constructor.
address | Default address to cast (write) to, NULL for none – may be overridden by write() |
exceptions | Whether to enable exceptions on error, default set by Evo config: EVO_EXCEPTIONS |
|
inline |
Destructor.
|
inline |
|
inline |
Create unbound datagram socket for casting (write only).
address | Default address to cast (write) to, NULL for none – may be overridden by write() |
family | Socket family type (AF_INET, AF_INET6), AF_UNSPEC to use family from address (if not NULL), or default to AF_INET (IPv4) |
socktype | Socket type value, defaults to standard UDP |
protocol | Socket protocol, 0 for default |
|
inline |
Close socket.
|
inlineinherited |
Get error code from last operation.
|
inline |
|
inlineinherited |
Get whether exceptions are enabled.
|
inlineinherited |
Set whether exceptions are enabled.
val | Whether to enable exceptions |
|
inlinevirtualinherited |
Flush any pending output in stream write buffer, if buffered.
Reimplemented in Stream< T >, Stream< IoFile >, Stream< IoSocket >, StreamOut< T >, and StreamOut< IoFile >.
|
inline |
Get socket option value.
level | Protocol level ID (SOL_SOCKET, IPPROTO_IP, etc) |
optname | Option name ID |
buf | Buffer to store option value |
T | Option value type – results are system dependent on incorrect type for option, may return an error or invalid value |
|
inline |
Get socket option flag or numeric value.
level | Protocol level ID (SOL_SOCKET, IPPROTO_IP, etc) |
optname | Option name ID |
|
inline |
Get timeout for socket operations.
|
inlinevirtualinherited |
Get whether stream is open.
Reimplemented in Stream< T >, Stream< IoFile >, Stream< IoSocket >, StreamOut< T >, StreamOut< IoFile >, StreamIn< T >, and StreamIn< IoFile >.
|
inlineinherited |
Safe (explicit) evaluation as bool type.
|
inlineinherited |
|
inline |
Read message from socket.
buf | Buffer to store message |
size | Buffer size in bytes |
flags | Flags passed to recvfrom(), 0 for none |
address | Pointer to store source address (must be correct type for socket), NULL to skip |
|
inlinevirtual |
Read binary input from stream.
buf | Buffer to store data read |
size | Size to read |
Reimplemented from IoBase.
|
inline |
Set socket option value.
level | Protocol level ID (SOL_SOCKET, IPPROTO_IP, etc) |
optname | Option name ID |
val | Value to set – must be correct type for level and optname |
T | Option value type |
|
inline |
Set socket option flag or numeric value.
level | Protocol level ID (SOL_SOCKET, IPPROTO_IP, etc) |
optname | Option name ID |
val | Value to set |
|
inline |
Set timeout for socket operations.
timeout_ms | Timeout in milliseconds, 0 for indefinite |
|
inline |
Write message to socket.
buf | Buffer with message |
size | Message size in bytes |
flags | Flags passed to sendto(), 0 for none |
address | Target address to write to, NULL for default set by set_target() |
|
inlinevirtual |
Write binary output to stream.
buf | Data to write |
size | Size to write |
Reimplemented from IoBase.
|
protectedinherited |
Last error code.
|
protectedinherited |
Whether to throw exceptions.