1 #include "../include/tcpsockbuf.hpp"
2 #include "../include/util.hpp"
3 #if !defined CSDBG_WITH_PLUGIN && !defined CSDBG_WITH_HIGHLIGHT
4 #include "../include/exception.hpp"
30 if (
unlikely(addr == NULL || strlen(addr) == 0) )
176 m_handle = socket(AF_INET, SOCK_STREAM, 0);
179 "failed to create stream socket (errno %d - %s)",
186 addr.sin_family = AF_INET;
187 addr.sin_port = htons(
m_port);
188 addr.sin_addr.s_addr = inet_addr(
m_address);
196 while (
unlikely(retval < 0 && errno == EINTR) );
201 "failed to connect TCP/IP socket @ %s:%d (errno %d - %s)",
229 "failed to send data @ %s:%d (errno %d - %s)",
269 if (
unlikely(val == NULL || sz == 0) )
275 i32 retval = setsockopt(
m_handle, SOL_SOCKET, nm, val, sz);
278 "failed to set socket option %d (errno %d - %s)",
virtual streambuf & flush()=0
To be implemented.
This abstract class is the base for all buffered output stream types (for files, sockets, serial interfaces e.t.c)
static void * memset(void *, u8, u32)
Fill a memory block with a constant byte.
char i8
8-bit signed integer
i8 * m_address
Peer IP address (numerical, IPv4)
tcpsockbuf(const i8 *, i32=g_ldp_port)
Object constructor.
i32 m_handle
Stream handle (descriptor)
virtual ~tcpsockbuf()
Object destructor.
#define likely(expr)
Offer a hint (positive) to the pipeline branch predictor.
virtual const i8 * address() const
Get the peer IP address.
virtual tcpsockbuf & sync() const
Commit cached data to the network.
virtual tcpsockbuf & open()
Connect the socket to its peer.
struct sockaddr_in tcp_addr_t
TCP IPv4 address.
A buffered TCP/IP socket output stream.
virtual streambuf & operator=(const streambuf &)
Assignment operator.
virtual tcpsockbuf & shutdown(i32) const
Shutdown one or both socket channels.
virtual bool is_connected() const
Check if the socket is connected to its peer.
virtual tcpsockbuf & operator=(const tcpsockbuf &)
Assignment operator.
virtual tcpsockbuf & set_option(i32, const void *, u32)
Set a socket option (applies only for the SOL_SOCKET ioctl level)
unsigned int u32
32-bit unsigned integer
int i32
32-bit signed integer
virtual i32 port() const
Get the peer TCP port.
This class is a throwable with a textual description of an error.
virtual tcpsockbuf & flush()
Flush the buffered data to the socket.
struct sockaddr ip_addr_t
IP address.
#define unlikely(expr)
Offer a hint (negative) to the pipeline branch predictor.
virtual streambuf & close()
Close the stream.
#define __D_ASSERT(x)
Assertion macro.
virtual tcpsockbuf * clone() const
Object virtual copy constructor.