ost::TCPStream(3)

πŸ“¦ version 1.8.1, in ubuntu jammy

✨ NAME ✨ β€” ost::TCPStream(3)

okay bestie, welcome to the glow-up of ost::TCPStream πŸ’– (that's the manual page name, section 3, library functions β€” iykyk).

TCP streams are used to represent TCP client connections to a server by TCP protocol servers for accepting client connections.


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <socket.h>

Inherits streambuf, ost::Socket, and iostream.

Inherited by ost::SSLStream, ost::TCPSession, and ost::URLStream. the family tree is giving legacy royalty fr πŸ’…

πŸ‘‘ Public Member Functions

  • TCPStream(Family family=IPV4, bool throwflag=true, timeout_t to=0) β€” the constructor you NEED when you're building other classes, or when you wanna start an unconnected TCPStream so you can connect later. it's the blank canvas era 🎨
  • void disconnect(void) β€” disconnect the current session and get everything ready for a new one. bye bye session, hello fresh start ✨
  • int getSegmentSize(void) β€” get protocol segment size.
  • TCPStream(TCPSocket &server, bool throwflag=true, timeout_t timeout=0) β€” create a TCP stream by accepting a connection from a bound TCP socket acting as a server. this one does the whole 'accept' thing.
  • TCPStream(TCPV6Socket &server, bool throwflag=true, timeout_t timeout=0) β€” same energy, but the IPv6 flavor 🌈
  • void connect(TCPSocket &server) β€” accept a connection from a TCP Server.
  • void connect(TCPV6Socket &server) β€” the v6 twin 🫢
  • TCPStream(const IPV4Host &host, tpport_t port, unsigned mss=536, bool throwflag=true, timeout_t timeout=0) β€” create a TCP stream by connecting to a TCP socket (on a remote machine). long-distance relationship, but make it networking πŸ’Œ
  • TCPStream(const IPV6Host &host, tpport_t port, unsigned mss=536, bool throwflag=true, timeout_t timeout=0) β€” the v6 version, no notes πŸ’œ
  • TCPStream(const char *name, Family family=IPV4, unsigned mss=536, bool throwflag=false, timeout_t timer=0) β€” construct a named TCP Socket connected to a remote machine.
  • void setTimeout(timeout_t timer) β€” set the I/O operation timeout for socket I/O operations. nobody likes waiting forever, periodt ⏰
  • TCPStream(const TCPStream &source) β€” a copy constructor that creates a new stream buffer. twin moment πŸ‘―
  • virtual ~TCPStream() β€” flush and empty all buffers, and then remove the allocated buffers. clean exit, no loose ends πŸ’…
  • int sync(void) β€” flushes the stream input and output buffers, writes pending output.
  • size_t printf(const char *format,...) β€” print content into a socket.
  • bool isPending(Pending pend, timeout_t timeout=TIMEOUT_INF) β€” get the status of pending stream data.
  • ssize_t peek(void *buf, size_t len) β€” examine contents of next waiting packet. just a lil look, no touching πŸ‘€
  • size_t getBufferSize(void) const β€” return the size of the current stream buffering used.

🧚 Protected Member Functions

  • void allocate(size_t size) β€” used to allocate the buffer space needed for iostream operations.
  • void endStream(void) β€” used to terminate the buffer space and cleanup the socket connection.
  • int underflow() β€” this streambuf method is used to load the input buffer through the established tcp socket connection.
  • int uflow() β€” this streambuf method is used for doing unbuffered reads through the establish tcp socket connection when in interactive mode.
  • int overflow(int ch) β€” this streambuf method is used to write the output buffer through the established tcp connection.
  • void connect(const IPV4Host &host, tpport_t port, unsigned mss=536) β€” create a TCP stream by connecting to a TCP socket (on a remote machine).
  • void connect(const IPV6Host &host, tpport_t port, unsigned mss=536) β€” the v6 sibling, matching outfits πŸŽ€
  • void connect(const char *name, unsigned mss=536) β€” connect a TCP stream to a named destination host and port number, using getaddrinfo interface if available.
  • std::iostream * tcp(void) β€” used in derived classes to refer to the current object via it's iostream.

🌸 Protected Attributes

  • timeout_t timeout
  • size_t bufsize
  • Family family
  • char * gbuf
  • char * pbuf

πŸ’– Friends

  • TCPStream & crlf(TCPStream &)
  • TCPStream & lfcr(TCPStream &)

⭐ Additional Inherited Members

(yes bestie, the original literally just drops this heading here and leaves it at that β€” inherited members live in the parent docs, so go peek at those πŸ‘€)


🫢 Detailed Description 🫢

TCP streams are used to represent TCP client connections to a server by TCP protocol servers for accepting client connections.

The TCP stream is a C++ 'stream' class, and can accept streaming of data to and from other C++ objects using the << and >> operators. it's giving very main character energy fr fr πŸ‘‘

TCPStream itself can be formed either by connecting to a bound network address of a TCP server, or can be created when 'accepting' a network connection from a TCP server.

Author

David Sugar dyfet@ostel.com

streamable TCP socket connection.

Examples

tcp.cpp, and tcpstr1.cpp.


πŸ’… Constructor & Destructor Documentation πŸ’…

ost::TCPStream::TCPStream(Family family = IPV4, bool throwflag = true, timeout_t to = 0)

The constructor required for building other classes or to start an unconnected TCPStream for connect.

ost::TCPStream::TCPStream(TCPSocket & server, bool throwflag = true, timeout_t timeout = 0)

Create a TCP stream by accepting a connection from a bound TCP socket acting as a server. This performs an 'accept' call.

Parameters

  • server socket listening
  • throwflag flag to throw errors.
  • timeout for all operations.

ost::TCPStream::TCPStream(TCPV6Socket & server, bool throwflag = true, timeout_t timeout = 0)

the v6 accept twin, same vibes 🌈

ost::TCPStream::TCPStream(const IPV4Host & host, tpport_t port, unsigned mss = 536, bool throwflag = true, timeout_t timeout = 0)

Create a TCP stream by connecting to a TCP socket (on a remote machine).

Parameters

  • host address of remote TCP server.
  • port number to connect.
  • mss maximum segment size of streaming buffers.
  • throwflag flag to throw errors.
  • timeout for all operations.

ost::TCPStream::TCPStream(const IPV6Host & host, tpport_t port, unsigned mss = 536, bool throwflag = true, timeout_t timeout = 0)

same deal, v6 edition πŸ’œ

ost::TCPStream::TCPStream(const char * name, Family family = IPV4, unsigned mss = 536, bool throwflag = false, timeout_t timer = 0)

Construct a named TCP Socket connected to a remote machine.

Parameters

  • name of remote service.
  • family of protocol.
  • mss maximum segment size of streaming buffers.
  • throwflag flag to throw errors.
  • timer for timeout for all operations.

virtual ost::TCPStream::~TCPStream() [virtual]

Flush and empty all buffers, and then remove the allocated buffers. closing the tab on this whole era ✨


πŸŽ€ Member Function Documentation πŸŽ€

void ost::TCPStream::allocate(size_t size) [protected]

Used to allocate the buffer space needed for iostream operations. This function is called by the constructor.

Parameters

  • size of stream buffers from constructor.

void ost::TCPStream::connect(const char * name, unsigned mss = 536) [protected]

Connect a TCP stream to a named destination host and port number, using getaddrinfo interface if available.

Parameters

  • name of host and service to connect
  • mss maximum segment size of stream buffer

void ost::TCPStream::connect(const IPV4Host & host, tpport_t port, unsigned mss = 536) [protected]

Create a TCP stream by connecting to a TCP socket (on a remote machine).

Parameters

  • host address of remote TCP server.
  • port number to connect.
  • mss maximum segment size of streaming buffers.

Examples

tcp.cpp.

void ost::TCPStream::connect(const IPV6Host & host, tpport_t port, unsigned mss = 536) [protected]

the v6 connect, matching set 🫢

void ost::TCPStream::connect(TCPSocket & server)

Accept a connection from a TCP Server.

Parameters

  • server socket listening

void ost::TCPStream::connect(TCPV6Socket & server)

v6 accept twin, iconic duo πŸ’–

void ost::TCPStream::disconnect(void)

Disconnect the current session and prepare for a new one.

Examples

tcp.cpp, and tcpstr1.cpp.

void ost::TCPStream::endStream(void) [protected]

Used to terminate the buffer space and cleanup the socket connection. This fucntion is called by the destructor.

(yes, "fucntion" β€” that's the original's spelling, not me being chaotic. keeping it verbatim bestie πŸ™ˆ)

size_t ost::TCPStream::getBufferSize(void) const [inline]

Return the size of the current stream buffering used.

Returns

  • size of stream buffers.

int ost::TCPStream::getSegmentSize(void)

Get protocol segment size.

Examples

tcp.cpp.

bool ost::TCPStream::isPending(Pending pend, timeout_t timeout = TIMEOUT_INF) [virtual]

Get the status of pending stream data. This can be used to examine if input or output is waiting, or if an error or disconnect has occured on the stream. If a read buffer contains data then input is ready and if write buffer contains data it is first flushed and then checked.

Reimplemented from ost::Socket.

Examples

tcp.cpp.

int ost::TCPStream::overflow(int ch) [protected]

This streambuf method is used to write the output buffer through the established tcp connection.

Parameters

  • ch char to push through.

Returns

  • char pushed through.

ssize_t ost::TCPStream::peek(void * buf, size_t len) [inline]

Examine contents of next waiting packet.

Parameters

  • buf pointer to packet buffer for contents.
  • len of packet buffer.

Returns

  • number of bytes examined.

References _IOLEN64.

size_t ost::TCPStream::printf(const char * format, ...)

Print content into a socket.

Returns

  • count of bytes sent.

Parameters

  • format string

void ost::TCPStream::setTimeout(timeout_t timer) [inline]

Set the I/O operation timeout for socket I/O operations.

Parameters

  • timer to change timeout.

int ost::TCPStream::sync(void)

Flushes the stream input and output buffers, writes pending output.

Returns

  • 0 on success.

std::iostream* ost::TCPStream::tcp(void) [inline], [protected]

Used in derived classes to refer to the current object via it's iostream. For example, to send a set of characters in a derived method, one might use *tcp() << 'test'.

Returns

  • stream pointer of this object.

int ost::TCPStream::uflow() [protected]

This streambuf method is used for doing unbuffered reads through the establish tcp socket connection when in interactive mode. Also this method will handle proper use of buffers if not in interative mode.

Returns

  • char from tcp socket connection, EOF if not connected.

int ost::TCPStream::underflow() [protected]

This streambuf method is used to load the input buffer through the established tcp socket connection.

Returns

  • char from get buffer, EOF if not connected.

TCPStream& crlf(TCPStream &) [friend]

TCPStream& lfcr(TCPStream &) [friend]


πŸ“ Member Data Documentation πŸ“

size_t ost::TCPStream::bufsize [protected]

Family ost::TCPStream::family [protected]

char* ost::TCPStream::gbuf [protected]

char * ost::TCPStream::pbuf [protected]

timeout_t ost::TCPStream::timeout [protected]


πŸ’œ Author πŸ’œ

Generated automatically by Doxygen for GNU CommonC++ from the source code.


and that's a wrap bestie πŸŽ¬πŸ’– this whole page came straight out of GNU CommonC++, dated Sun Dec 27 2020 β€” so yeah, we're stanning a classic. go stream some sockets responsibly, mwah πŸ’…βœ¨

πŸ“¦ where this page comes from