Faith::Socket Class Reference

#include <faith/socket.h>

Inheritance diagram for Faith::Socket:

Faith::Object List of all members.

Public Types

 NoError
 System
 InvalidAddress
 ConnectionRefused
 Unreachable
enum  SocketError {
  NoError, System, InvalidAddress, ConnectionRefused,
  Unreachable
}

Public Slots

void connect ()
void close ()

Signals

void connected ()
void connectFailed ()
void canRead ()
void canWrite ()
void peerDisconnected ()

Public Member Functions

 Socket (const Faith::String &address, int port, Object *parent=0)
 Socket (int fd, Object *parent=0)
 Socket (Object *parent=0)
 ~Socket ()
SocketError error () const
void setPeer (const Faith::String &address, int port)
Faith::String peer () const
int read (void *data, int count)
int write (const void *data, int count)
bool isClosed () const
bool isConnected () const
bool isConnectionFailed () const
bool hasData () const

Member Enumeration Documentation

enum Faith::Socket::SocketError

Enumerator:
NoError 
System 
InvalidAddress 
ConnectionRefused 
Unreachable 


Constructor & Destructor Documentation

Faith::Socket::Socket ( const Faith::String address,
int  port,
Object parent = 0 
)

connects to the address address and the port port

The actual connection doesn't occur until connect() is called

Faith::Socket::Socket ( int  fd,
Object parent = 0 
)

creates a socket from the given file descriptor, which is already open and connected

Faith::Socket::Socket ( Object parent = 0  ) 

Faith::Socket::~Socket (  ) 

closes the socket if it is open


Member Function Documentation

void Faith::Socket::canRead (  )  [signal]

void Faith::Socket::canWrite (  )  [signal]

void Faith::Socket::close (  )  [slot]

Terminate the call. The other end will be told after having recieved all that was written

void Faith::Socket::connect (  )  [slot]

begins the connection to the peer

This function will emit connected or connectFailed when it is done

After this, canRead and canWrite may be emitted as well

void Faith::Socket::connected (  )  [signal]

void Faith::Socket::connectFailed (  )  [signal]

SocketError Faith::Socket::error (  )  const [inline]

Returns:
the error state. If there is no error, returns NoError

bool Faith::Socket::hasData (  )  const

Returns:
true if read can read something

bool Faith::Socket::isClosed (  )  const

Returns:
true if the socket has been closed and there is no more data to read

bool Faith::Socket::isConnected (  )  const

There is another end connected

bool Faith::Socket::isConnectionFailed (  )  const

The connection has failed (and connectFailed was emitted

Faith::String Faith::Socket::peer (  )  const

Returns:
the address of the peer, or an empty string if the peer is unavailable

void Faith::Socket::peerDisconnected (  )  [signal]

emitted when the other end disconnects (before you do, that is) (The next read will return 0)

int Faith::Socket::read ( void *  data,
int  count 
)

reads from the socket into data

this is a non-blocking operation, so if data is not immediately available, a value less than count may be returned (even 0)

Parameters:
data is the array to write into, it has a size of at length count
count is the number of bytes to read
Returns:
the number of bytes read, possibly 0 if the other end has closed the socket, or there was an error

void Faith::Socket::setPeer ( const Faith::String address,
int  port 
)

sets the address to connect to

int Faith::Socket::write ( const void *  data,
int  count 
)

writes into the socket from data

This is non-blocking, so it may not write all the data specified, returning how much actually was written

Parameters:
data is the array to read the data from, it has a size no smaller than count
count the number of bytes to attempt to write
Returns:
the number of bytes written, possibly 0 if there was an error


The documentation for this class was generated from the following file:
Generated on Fri Sep 1 00:23:09 2006 for Faith by  doxygen 1.4.7