Pyro higlevel network API
Classes | Public Member Functions | Public Attributes | List of all members
net::Socket Class Reference

Classes

class  Private
 

Public Member Functions

 Socket (Host &cHost, bool bDatagram=false)
 Default constructor. More...
 
virtual ~Socket (void)
 Destructor. More...
 
virtual void SetHost (Host &cHost)
 
virtual Host GetHost (void)
 
virtual status_t Connect (void)
 
virtual bool IsConnected (void)
 
virtual status_t Disconnect (void)
 
virtual ssize_t Send (const void *pBuffer, ssize_t nSize)
 
virtual ssize_t Recieve (void *pBuffer, ssize_t nSize)
 
virtual ssize_t ReadLine (uint8 *pnBuffer, ssize_t nMax, bigtime_t nTimeout=SOCKET_DEFAULT_TIMEOUT)
 
virtual status_t WaitFor (char *pzString, uint8 *pnBuffer, ssize_t nMax, bigtime_t nTimeout=SOCKET_DEFAULT_TIMEOUT)
 
virtual status_t SetBlocking (bool bBlocking=true)
 
virtual bool IsBlocking (void)
 

Public Attributes

bool m_bTimeout
 

Constructor & Destructor Documentation

Socket::Socket ( Host cHost,
bool  bDatagram = false 
)
Description:
Create a Socket for a specified Host.
Parameters
cHostThe hostname E.g. www.example.com:80 The Socket class retrieves both the domain name and the port number from the Host name.
bDatagramfalse creates a TCP socket, true creates a UDP socket. Default is false
See Also
Connect()
Author
Kristian Van Der Vliet (vande.nosp@m.rs@l.nosp@m.iqwyd.nosp@m..com)
Socket::~Socket ( void  )
virtual
Description:
Destroy a Socket(). Will disconnect the Socket for you if it is connected.
Author
Kristian Van Der Vliet (vande.nosp@m.rs@l.nosp@m.iqwyd.nosp@m..com)

Member Function Documentation

status_t Socket::Connect ( void  )
virtual
Description:
Connect the Socket to the Host. The Host (Domain name and port) must have already been specified.
See Also
Socket(), SetHost(), Disconnect(), SetBlocking()
Author
Kristian Van Der Vliet (vande.nosp@m.rs@l.nosp@m.iqwyd.nosp@m..com)
status_t Socket::Disconnect ( void  )
virtual
Description:
Disconnects the Socket, if connected.
See Also
Connect()
Author
Kristian Van Der Vliet (vande.nosp@m.rs@l.nosp@m.iqwyd.nosp@m..com)
Host Socket::GetHost ( void  )
virtual
bool Socket::IsBlocking ( void  )
virtual
bool Socket::IsConnected ( void  )
virtual
ssize_t Socket::ReadLine ( uint8 *  pnBuffer,
ssize_t  nMax,
bigtime_t  nTimeout = SOCKET_DEFAULT_TIMEOUT 
)
virtual
Description
Recieves data from the server until the sequence
(CRLF) is encountered. This allows you to easily recieve a single line of data from a server. ReadLine() is a blocking operation; it will not return until either all of the data has been recieved or the operation times out.
Parameters
pnBufferA buffer to hold the data being recieved.
nMaxThe maximum amount of data to recieve from the server. nMax must not be larger than the size of pnBuffer.
nTimeoutTime to wait before the operation is abandoned. Default is 60 seconds.
Returns
-EINVAL if pBuffer was NULL or nMax was invalid, -ENOTCONN if the Socket is a TCP socket but it is not yet connected, -ETIME if nTimeout was reached before
was sent by the server, number of bytes read if successful.
See Also
Recieve(), WaitFor()
Author
Kristian Van Der Vliet (vande.nosp@m.rs@l.nosp@m.iqwyd.nosp@m..com)
ssize_t Socket::Recieve ( void *  pBuffer,
ssize_t  nSize 
)
virtual
Description
Recieves data from the server. Recieve() is a blocking operation; it will not return until either all of the data has been recieved or the operation times out.
Parameters
pBufferA buffer to hold the data being recieved.
nSizeThe number of bytes to be received.
Returns
-EINVAL if pBuffer was NULL or nSize was invalid, -ENOTCONN if the Socket is a TCP socket but it is not yet connected, number of bytes read if successful.
See Also
Connect(), SetBlocking()
Author
Kristian Van Der Vliet (vande.nosp@m.rs@l.nosp@m.iqwyd.nosp@m..com)
ssize_t Socket::Send ( const void *  pBuffer,
ssize_t  nSize 
)
virtual
Description
Send data to the server. Send() is a blocking operation; it will not return until either all of the data has been sent or the operation times out.
Parameters
pBufferA buffer containing the data to be sent.
nSizeThe number of bytes to be sent.
Returns
-EINVAL if pBuffer was NULL or nSize was invalid, -ENOTCONN if the Socket is a TCP socket but it is not yet connected, number of bytes sent if successful.
See Also
Connect(), SetBlocking()
Author
Kristian Van Der Vliet (vande.nosp@m.rs@l.nosp@m.iqwyd.nosp@m..com)
status_t Socket::SetBlocking ( bool  bBlocking = true)
virtual
Description
Set the blocking mode of the Socket. If the Socket is blocking then I/O methods such as Send() and Recieve() will not return until either data arrives or the operation times out. If the Socket is non-blocking then these operations will return imediatly if no data is available.
Parameters
bBlockingfalse Make the Socket non-blocking, true makes the Socket blocking. Default is true.
Returns
0 on success.
See Also
Connect(), IsBlocking()
Author
Kristian Van Der Vliet (vande.nosp@m.rs@l.nosp@m.iqwyd.nosp@m..com)
void Socket::SetHost ( Host cHost)
virtual
Description:
Set the Host to connect the Socket to.
Parameters
cHostThe hostname E.g. www.example.com:80 The Socket class retrieves both the domain name and the port number from the Host name. The Host and port can only be changed before the Socket is connected.
See Also
Connect()
Author
Kristian Van Der Vliet (vande.nosp@m.rs@l.nosp@m.iqwyd.nosp@m..com)
status_t Socket::WaitFor ( char *  pzString,
uint8 *  pnBuffer,
ssize_t  nMax,
bigtime_t  nTimeout = SOCKET_DEFAULT_TIMEOUT 
)
virtual
Description
Recieves data from the server until the sequence specified by pzString is encountered. This allows you to easily wait for a specific response from a server. WaitFor() is a blocking operation; it will not return until either all of the data has been recieved or the operation times out.
Parameters
pzStringThe sequence to wait for the server to send.
pnBufferA buffer to hold the data being recieved.
nMaxThe maximum amount of data to recieve from the server. nMax must not be larger than the size of pnBuffer.
nTimeoutTime to wait before the operation is abandoned. Default is 60 seconds.
Returns
-EINVAL if pBuffer was NULL or nMax was invalid, -ENOTCONN if the Socket is a TCP socket but it is not yet connected, -ETIME if nTimeout was reached before
was sent by the server, number of bytes read if successful.
See Also
Recieve(), ReadLine()
Author
Kristian Van Der Vliet (vande.nosp@m.rs@l.nosp@m.iqwyd.nosp@m..com)

Member Data Documentation

bool net::Socket::m_bTimeout