Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Examples  

vpr::SocketDatagramImplSIM Class Reference

#include <SocketDatagramImplSIM.h>

Inheritance diagram for vpr::SocketDatagramImplSIM:

Inheritance graph
[legend]
Collaboration diagram for vpr::SocketDatagramImplSIM:

Collaboration graph
[legend]
List of all members.

Public Methods

 SocketDatagramImplSIM (void)
 SocketDatagramImplSIM (const vpr::InetAddr &local_addr, const vpr::InetAddr &remote_addr)
vpr::ReturnStatus recvfrom (void *msg, const vpr::Uint32 length, const int flags, vpr::InetAddr &from, vpr::Uint32 &bytes_read, const vpr::Interval timeout=vpr::Interval::NoTimeout)
vpr::ReturnStatus sendto (const void *msg, const vpr::Uint32 length, const int flags, const vpr::InetAddr &to, vpr::Uint32 &bytes_sent, const vpr::Interval timeout=vpr::Interval::NoTimeout)
virtual vpr::ReturnStatus isReadReady () const
 Tests if this socket can read without blocking. More...

virtual vpr::ReturnStatus isWriteReady () const
 Tests if this socket can write without blocking. More...


Constructor & Destructor Documentation

vpr::SocketDatagramImplSIM::SocketDatagramImplSIM void    [inline]
 

Definition at line 57 of file SocketDatagramImplSIM.h.

References vpr::SocketTypes::DATAGRAM, and vpr::SocketImplSIM::SocketImplSIM.

00058       : SocketImplSIM(vpr::SocketTypes::DATAGRAM)
00059    {
00060       /* Do nothing. */ ;
00061    }

vpr::SocketDatagramImplSIM::SocketDatagramImplSIM const vpr::InetAddr   local_addr,
const vpr::InetAddr   remote_addr
[inline]
 

Definition at line 63 of file SocketDatagramImplSIM.h.

References vpr::SocketTypes::DATAGRAM, and vpr::SocketImplSIM::SocketImplSIM.

00065       : SocketImplSIM(local_addr, remote_addr, vpr::SocketTypes::DATAGRAM)
00066    {
00067       /* Do nothing. */ ;
00068    }


Member Function Documentation

vpr::ReturnStatus vpr::SocketDatagramImplSIM::recvfrom void *    msg,
const vpr::Uint32    length,
const int    flags,
vpr::InetAddr   from,
vpr::Uint32   bytes_read,
const vpr::Interval    timeout = vpr::Interval::NoTimeout
 

Definition at line 55 of file SocketDatagramImplSIM.cpp.

References vpr::SocketImplSIM::mArrivedQueue, vpr::SocketImplSIM::mArrivedQueueMutex, vpr::SocketImplSIM::mBound, vpr::ReturnStatus::setCode, vprASSERT, and vpr::ReturnStatus::WouldBlock.

00061 {
00062    vpr::ReturnStatus status;
00063    vprASSERT(mBound && "Can recvfrom if we are not bound so they can send to us");
00064 
00065    vpr::Guard<vpr::Mutex> guard(mArrivedQueueMutex);
00066 
00067    if ( ! mArrivedQueue.empty() )
00068    {
00069       vpr::sim::MessagePtr msg_ptr = mArrivedQueue.front();
00070       vpr::Uint32 msg_size, copy_len;
00071 
00072       msg_size = msg_ptr->getSize();
00073 
00074       // Use the smaller of length and msg_size for the actual amount of
00075       // data to copy.
00076       copy_len = (length > msg_size) ? msg_size : length;
00077 
00078       // Complete the read operation.
00079       memcpy(msg, msg_ptr->getBody(), copy_len);
00080       bytes_read = copy_len;
00081 
00082       from = msg_ptr->getSourceSocket()->getLocalAddr();
00083 
00084       if ( msg_ptr->resize(copy_len) == 0 )
00085       {
00086          mArrivedQueue.pop_front();
00087       }
00088    }
00089    else
00090    {
00091       status.setCode(vpr::ReturnStatus::WouldBlock);
00092       bytes_read = 0;
00093    }
00094 
00095    return status;
00096 }

vpr::ReturnStatus vpr::SocketDatagramImplSIM::sendto const void *    msg,
const vpr::Uint32    length,
const int    flags,
const vpr::InetAddr   to,
vpr::Uint32   bytes_sent,
const vpr::Interval    timeout = vpr::Interval::NoTimeout
 

Definition at line 98 of file SocketDatagramImplSIM.cpp.

References vpr::SocketImplSIM::bind, vpr::sim::Controller::instance, vpr::SocketImplSIM::mBound, vpr::sim::SocketManager::sendMessageTo, and vprASSERT.

00104 {
00105    vpr::ReturnStatus status;
00106    vpr::sim::SocketManager& sock_mgr =
00107       vpr::sim::Controller::instance()->getSocketManager();
00108 
00109    if ( ! mBound )
00110    {
00111       bind();      
00112    }
00113 
00114    vprASSERT( mBound && "Must be bound before sending");
00115 
00116    bytes_sent = length;
00117    vpr::sim::MessagePtr net_msg(new vpr::sim::Message(msg, length));
00118    sock_mgr.sendMessageTo(net_msg, this, to);
00119 
00120    return status;
00121 }

vpr::ReturnStatus vpr::SocketDatagramImplSIM::isReadReady   const [virtual]
 

Tests if this socket can read without blocking.

Postcondition:
Depending on the state of the socket, the caller is informed if a read will block or not.
Returns:
vpr::ReturnStatus::Succeed is returned if this socket can read without blocking. That is, there is data waiting to be read from its arrival queue.
vpr::ReturnStatus::Timeout is returned if this socket did not become ready for reading within the timeout period.
vpr::ReturnStatus::Fail is returned if this socket is not ready for reading. This can happen if the socket is not open, not connected, or without any received data.

Implements vpr::SocketImplSIM.

Definition at line 123 of file SocketDatagramImplSIM.cpp.

References vpr::ReturnStatus::Fail, vpr::SocketImplSIM::mArrivedQueue, vpr::SocketImplSIM::mOpen, and vpr::ReturnStatus::setCode.

00124 {
00125    vpr::ReturnStatus status;
00126 
00127    if ( ! mOpen || mArrivedQueue.empty() )
00128    {
00129       status.setCode(vpr::ReturnStatus::Fail);
00130    }
00131 
00132    return status;
00133 }

vpr::ReturnStatus vpr::SocketDatagramImplSIM::isWriteReady   const [virtual]
 

Tests if this socket can write without blocking.

Postcondition:
Depending on the state of the socket, the caller is informed if a write will succeed or not.
Returns:
vpr::ReturnStatus::Succeed is returned if this socket can write without blocking. That is, this socket is in a connected state, and data can be sent to its peer right away.
vpr::ReturnStatus::Timeout is returned if this socket did not become ready for writing within the timeout period.
vpr::ReturnStatus::Fail is returned if this socket is not ready for writing. This can happen if the socket is not open or not connected.

Implements vpr::SocketImplSIM.

Definition at line 135 of file SocketDatagramImplSIM.cpp.

References vpr::ReturnStatus::Fail, vpr::SocketImplSIM::mOpen, and vpr::ReturnStatus::setCode.

00136 {
00137    vpr::ReturnStatus status;
00138 
00139    if ( ! mOpen )
00140    {
00141       status.setCode(vpr::ReturnStatus::Fail);
00142    }
00143 
00144    return status;
00145 }


The documentation for this class was generated from the following files:
Generated on Sun May 2 14:47:07 2004 for VR Juggler Portable Runtime by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002