SoDaRadio-5.0.3-master:8901fb5
Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
SoDa::IP::LineServerSocket Class Reference

This is an IP socket that returns newline-delimited strings arriving on the socket. More...

#include <LineSocket.hxx>

Inheritance diagram for SoDa::IP::LineServerSocket:
SoDa::IP::ServerSocket SoDa::IP::NetSocket

Public Member Functions

 LineServerSocket (int portnum, TransportType transport=TCP)
 constructor More...
 
int getLine (char *buf, unsigned int maxsize)
 capture a newline-terminated buffer from the socket This is a non-blocking method. More...
 
- Public Member Functions inherited from SoDa::IP::ServerSocket
 ServerSocket (int portnum, TransportType transport=TCP)
 
 ~ServerSocket ()
 
bool isReady ()
 
int get (void *ptr, unsigned int size)
 
int put (const void *ptr, unsigned int size)
 
- Public Member Functions inherited from SoDa::IP::NetSocket
 NetSocket ()
 
int put (const void *ptr, unsigned int size)
 
int get (void *ptr, unsigned int size)
 
int putRaw (const void *ptr, unsigned int size)
 
int getRaw (const void *ptr, unsigned int size, unsigned int usec_timeout=0)
 get a raw string of <size> bytes... More...
 
void setNonBlocking ()
 
void setBlocking ()
 

Static Public Attributes

static const unsigned int temp_buf_size = 128
 This is the size of the running buffer that we read into from the socket. More...
 

Protected Attributes

std::queue< char > inbuf
 Do this the simple way – accumulate characters in a queue then return each "\n" terminated substring as we find it. More...
 
int ready_line_count
 keep a count of the number of "\n" delimited strings we've seen that haven't yet been returned from getLine() More...
 
char temp_buf [temp_buf_size]
 This is the running buffer that we read into from the socket. More...
 
- Protected Attributes inherited from SoDa::IP::ServerSocket
bool ready
 

Additional Inherited Members

- Public Attributes inherited from SoDa::IP::NetSocket
int server_socket
 
int conn_socket
 
int portnum
 
struct sockaddr_in server_address client_address
 
bool non_blocking_mode
 
struct timeval timeout
 

Detailed Description

This is an IP socket that returns newline-delimited strings arriving on the socket.

LineServerSocket builds on the IP::ServerSocket class.

Definition at line 48 of file LineSocket.hxx.

Constructor & Destructor Documentation

◆ LineServerSocket()

SoDa::IP::LineServerSocket::LineServerSocket ( int  portnum,
TransportType  transport = TCP 
)
inline

constructor

Parameters
portnumthe port number for this server
transportone of IP::UDP or IP::TCP

Definition at line 56 of file LineSocket.hxx.

References ready_line_count, and SoDa::IP::NetSocket::setNonBlocking().

Member Function Documentation

◆ getLine()

int SoDa::IP::LineServerSocket::getLine ( char *  buf,
unsigned int  maxsize 
)
inline

capture a newline-terminated buffer from the socket This is a non-blocking method.

Parameters
bufpointer to a buffer to receive the string – newline is removed.
maxsizemaximum allowed length of string.
Returns
0 if no newline terminated string is available, -1 if the client has disconnected, and length of the buffer, otherwise.

Definition at line 84 of file LineSocket.hxx.

References SoDa::IP::NetSocket::conn_socket, inbuf, SoDa::IP::ServerSocket::isReady(), SoDa::IP::ServerSocket::ready, ready_line_count, and temp_buf.

Referenced by main().

Member Data Documentation

◆ inbuf

std::queue<char> SoDa::IP::LineServerSocket::inbuf
protected

Do this the simple way – accumulate characters in a queue then return each "\n" terminated substring as we find it.

Definition at line 148 of file LineSocket.hxx.

Referenced by getLine().

◆ ready_line_count

int SoDa::IP::LineServerSocket::ready_line_count
protected

keep a count of the number of "\n" delimited strings we've seen that haven't yet been returned from getLine()

Definition at line 154 of file LineSocket.hxx.

Referenced by getLine(), and LineServerSocket().

◆ temp_buf

char SoDa::IP::LineServerSocket::temp_buf[temp_buf_size]
protected

This is the running buffer that we read into from the socket.

This is NOT the maximum length of an unterminated string, as characters are read from the temp_buf and then pushed onto a queue.

Definition at line 162 of file LineSocket.hxx.

Referenced by getLine().

◆ temp_buf_size

const unsigned int SoDa::IP::LineServerSocket::temp_buf_size = 128
static

This is the size of the running buffer that we read into from the socket.

This is NOT the maximum length of an unterminated string, as characters are read from the temp_buf and then pushed onto a queue.

Definition at line 71 of file LineSocket.hxx.


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