Class Socket

Index Home MAE > MAE Architecture > MAE Data Types > Class Index > Class Socket

Public Properties
Public Methods
Socket(host, port)
Socket()
bool open()
bool open(host, port)
bool close()
bool isClosed() const
bool eof() const
int fd() const
int getErrno() const
bool sleep(seconds, useconds, exitOnInterrupt)
int isReadReady(wait)
int isWriteReady(wait)
bool signalRaised() const
void clearSignal()
inline void signalLock(locked)
int writeBytes(text)
int write(c)
string readLine(wait, ignoreSignal)
bool setTcpNoDelay(nodelay)
Protected Properties
Protected Methods
void clearErrno()

#include <Socket.h >

Public Properties

int bytesWritten

int linesWritten

int bytesRead

int linesRead


Public Methods

Socket(host, port)

const string& host

The hostname to connect to (if empty, then localhost)

int port

The remote TCP port to connect to


Prepare for a TCP socket connection

Return value: instance of Socket to open().  If FALSE, check errno().

Socket()

bool open()

Open the TCP connection

Return value: TRUE if connected, FALSE otherwise.  If FALSE, check errno().

bool open(host, port)

string host

int port


bool close()

Close the TCP connection

Return value: TRUE if closed, FALSE otherwise.  If FALSE, check errno().

bool isClosed() const

Determine if socket is open/active

Return value: TRUE if socket is closed

bool eof() const

Determine if the socket connection has hit EOF

Return value: TRUE if EOF detected

int fd() const

Get the file descriptor (for select() of socket)

Return value: file descriptor

int getErrno() const

Get the last known error state after a Socket method is called

Return value: the value of errno after the last I/O call

bool sleep(seconds, useconds, exitOnInterrupt)

int seconds

int useconds

Default value: 0

bool exitOnInterrupt

Default value: false


Sleep the specified number of seconds and microseconds

Return value: true if full time elapsed, false otherwise

int isReadReady(wait)

bool wait

Default value: false


Determine if socket is ready to be read (it has input)

Return value: TRUE if data ready to be read

int isWriteReady(wait)

bool wait

Default value: false


Determine if socket is ready to be written

Return value: TRUE if data ready to be written

bool signalRaised() const

Check if any signal was received during I/O (EINTR)

Return value: true if a signal was raised

void clearSignal()

Clear the flag that a signal was raised

inline void signalLock(locked)

bool locked


Signal is locked when being serviced

int writeBytes(text)

const string& text

The text scring to write


Write out the specified bytes to the socket

Return value: the number of bytes successfully written

int write(c)

char c

the character to write


Write out a single character to socket

Return value: the number of characters successfully written (1 or 0).

string readLine(wait, ignoreSignal)

bool wait

Default value: true

bool ignoreSignal

Default value: false


Read text up to a newline.

Return value: the string read.  If empty, check errno().

bool setTcpNoDelay(nodelay)

bool nodelay


Disable buffering on socket.

Return value: TRUE if operation successful, FALSE otherwise.

Protected Properties

string host_

int port_

int fd_

int errno_

bool eof_

bool signal_

bool signal_lock_


Protected Methods

void clearErrno()