#include <SocketDatagramImplSIM.h>
Inheritance diagram for vpr::SocketDatagramImplSIM:


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... | |
|
|
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 } |
|
||||||||||||
|
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 } |
|
||||||||||||||||||||||||||||
|
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 }
|
|
||||||||||||||||||||||||||||
|
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 }
|
|
|
Tests if this socket can read without blocking.
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 }
|
|
|
Tests if this socket can write without blocking.
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 }
|
1.2.14 written by Dimitri van Heesch,
© 1997-2002