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


Public Methods | |
| SocketStreamImplSIM (void) | |
| Default constructor. More... | |
| SocketStreamImplSIM (const vpr::InetAddr &local_addr, const vpr::InetAddr &remote_addr) | |
| Constructor. More... | |
| virtual | ~SocketStreamImplSIM (void) |
| Destructor. More... | |
| vpr::ReturnStatus | listen (const int backlog=5) |
| Puts this socket into the listening state where it listens for incoming connection requests. More... | |
| vpr::ReturnStatus | accept (SocketStreamImplSIM &client_sock, vpr::Interval timeout=vpr::Interval::NoTimeout) |
| Accepts an incoming connection request and return the connected socket to the caller in the given socket object reference. More... | |
| vpr::ReturnStatus | setNoDelay (bool setting) |
| Sets the current no-delay status for this socket. More... | |
| vpr::ReturnStatus | addConnector (vpr::SocketImplSIM *peerSock) |
| vpr::Uint32 | getConnectorCount (void) const |
| Gets the current number of connectors waiting to connect to this socket. More... | |
| 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... | |
Protected Attributes | |
| std::queue< SocketStreamImplSIM * > | mConnectorQueue |
| < Queue of pending connection requests.This is a list of the requesting connectors. More... | |
| vpr::Mutex | mConnectorQueueMutex |
| Mutex for connector queue. More... | |
| bool | mNoDelay |
Definition at line 65 of file SocketStreamImplSIM.h.
|
|
Default constructor. This initializes the member variables. Definition at line 75 of file SocketStreamImplSIM.h. References vpr::SocketTypes::STREAM. Referenced by accept, and addConnector.
00076 : SocketImplSIM(vpr::SocketTypes::STREAM), mNoDelay(false) 00077 { 00078 /* Do nothing. */ ; 00079 } |
|
||||||||||||
|
Constructor. This initializes the member variables. In particular, the local and remote addresses for this socket are initialized using the given addresses.
Definition at line 94 of file SocketStreamImplSIM.h. References vpr::SocketTypes::STREAM.
00096 : SocketImplSIM(local_addr, remote_addr, vpr::SocketTypes::STREAM), 00097 mNoDelay( false ) 00098 { 00099 mLocalAddr = local_addr; 00100 mRemoteAddr = remote_addr; 00101 } |
|
|
Destructor. This currently does nothing but act as a placeholder. Definition at line 106 of file SocketStreamImplSIM.h.
00107 {
00108 /* Do nothing. */ ;
00109 }
|
|
|
Puts this socket into the listening state where it listens for incoming connection requests.
Definition at line 55 of file SocketStreamImplSIM.cpp. References vpr::sim::Controller::instance.
00056 {
00057 return vpr::sim::Controller::instance()->getSocketManager().listen(this, backlog);
00058 }
|
|
||||||||||||
|
Accepts an incoming connection request and return the connected socket to the caller in the given socket object reference.
Definition at line 60 of file SocketStreamImplSIM.cpp. References vpr::MutexPosix::acquire, vpr::sim::Controller::addConnectionCompletionEvent, vpr::sim::SocketManager::findRoute, vpr::sim::Controller::getClock, vpr::sim::Clock::getCurrentTime, vpr::sim::Controller::getSocketManager, vpr::sim::Controller::instance, vpr::SocketImplSIM::mBlocking, mConnectorQueue, mConnectorQueueMutex, vpr::SocketImplSIM::mLocalAddr, vpr::MutexPosix::release, vpr::ReturnStatus::setCode, vpr::InetAddrBSD::setPort, SocketStreamImplSIM, vprASSERT, vprDBG_ALL, vprDBG_STATE_LVL, vprDEBUG, vprDEBUG_FLUSH, and vpr::ReturnStatus::WouldBlock.
00062 {
00063 vpr::ReturnStatus status;
00064
00065 mConnectorQueueMutex.acquire();
00066
00067 if ( ! mConnectorQueue.empty() )
00068 {
00069 SocketStreamImplSIM* peer_ptr = mConnectorQueue.front(); // The peer requesting the connection
00070 mConnectorQueue.pop();
00071
00072 mConnectorQueueMutex.release();
00073
00074 vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL)
00075 << "SocketStreamImplSIM::accept() [" << mLocalAddr
00076 << "]: Got pending connector from " << peer_ptr->getLocalAddr()
00077 << "\n" << vprDEBUG_FLUSH;
00078
00079 // -- Set known properties of the next socket
00080 client_sock.mRemoteAddr = peer_ptr->mLocalAddr; // Get the remote node's address (it must have called bind, so this is final)
00081 client_sock.mOpen = true;
00082 client_sock.mBlocking = mBlocking;
00083 client_sock.setConnectState(peer_ptr);
00084
00085 // Get an address for the new socket, bind it, and attach the socket to
00086 // the correct node.
00087 vpr::sim::Controller* controller = vpr::sim::Controller::instance();
00088 vpr::sim::SocketManager& sock_mgr = controller->getSocketManager();
00089 client_sock.mLocalAddr = mLocalAddr; // Start with local socket's address
00090 client_sock.mLocalAddr.setPort(0); // Clear port so that we get a unique one
00091 client_sock.bind(); // Bind to a port (and assign to net node)
00092
00093 // Now define the route for messages between the two sockets.
00094 // - Sets the path inside both sockets (path to the other socket)
00095 sock_mgr.findRoute(peer_ptr, client_sock.getHandle());
00096
00097 peer_ptr->completeConnection( client_sock.getHandle() );
00098
00099 controller->addConnectionCompletionEvent(controller->getClock().getCurrentTime(),
00100 peer_ptr);
00101
00102 // Make sure the peer's remote address has the right address.
00103 // Prior to this point, it has the port of the accepting socket.
00104 vprASSERT(peer_ptr->mRemoteAddr == client_sock.mLocalAddr && "Connector doesn't know peer's IP address");
00105 }
00106 else
00107 {
00108 mConnectorQueueMutex.release();
00109 status.setCode(vpr::ReturnStatus::WouldBlock);
00110 }
00111
00112 return status;
00113 }
|
|
|
Sets the current no-delay status for this socket. If no-delay is true, then the Nagel algorithm will be disabled. Of course, there is no Nagel algorithm for sim sockets.
Definition at line 161 of file SocketStreamImplSIM.h.
00162 {
00163 mNoDelay = setting;
00164 return vpr::ReturnStatus();
00165 }
|
|
|
Definition at line 115 of file SocketStreamImplSIM.cpp. References vpr::MutexPosix::acquire, vpr::SocketImplSIM::getLocalAddr, vpr::ReturnStatus::InProgress, mConnectorQueue, mConnectorQueueMutex, vpr::SocketImplSIM::mLocalAddr, vpr::MutexPosix::release, SocketStreamImplSIM, vprASSERT, vprDBG_ALL, vprDBG_STATE_LVL, vprDEBUG, and vprDEBUG_FLUSH. Referenced by vpr::sim::SocketManager::connect.
00116 {
00117 SocketStreamImplSIM* stream_remote;
00118
00119 vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL)
00120 << "SocketStreamImplSIM::addConnector() [" << mLocalAddr
00121 << "]: Adding connector from " << peerSock->getLocalAddr() << "\n"
00122 << vprDEBUG_FLUSH;
00123
00124 stream_remote = dynamic_cast<SocketStreamImplSIM*>(peerSock);
00125
00126 vprASSERT(NULL != stream_remote && "Tried to connect to a non-stream socket!");
00127
00128 mConnectorQueueMutex.acquire();
00129 {
00130 mConnectorQueue.push(stream_remote);
00131 }
00132 mConnectorQueueMutex.release();
00133
00134 return vpr::ReturnStatus(vpr::ReturnStatus::InProgress);
00135 }
|
|
|
Gets the current number of connectors waiting to connect to this socket.
Definition at line 176 of file SocketStreamImplSIM.h. Referenced by isReadReady.
00177 {
00178 return mConnectorQueue.size();
00179 }
|
|
|
Tests if this socket can read without blocking.
Implements vpr::SocketImplSIM. Definition at line 137 of file SocketStreamImplSIM.cpp. References vpr::ReturnStatus::Fail, getConnectorCount, vpr::SocketImplSIM::isConnected, vpr::SocketImplSIM::isOpen, vpr::SocketImplSIM::mArrivedQueue, vpr::ReturnStatus::setCode, and vpr::ReturnStatus::Succeed.
00138 {
00139 vpr::ReturnStatus status(vpr::ReturnStatus::Fail);
00140
00141 // To be able to read, we must be open, connected, and have a non-empty
00142 // queue of arrived messages.
00143 if ( isOpen() && isConnected() && (! mArrivedQueue.empty()) )
00144 {
00145 status.setCode(vpr::ReturnStatus::Succeed);
00146 }
00147
00148 if ( isOpen() && getConnectorCount() > 0 )
00149 {
00150 status.setCode(vpr::ReturnStatus::Succeed);
00151 }
00152
00153 return status;
00154 }
|
|
|
Tests if this socket can write without blocking.
Implements vpr::SocketImplSIM. Definition at line 156 of file SocketStreamImplSIM.cpp. References vpr::ReturnStatus::Fail, vpr::SocketImplSIM::isConnected, vpr::SocketImplSIM::isOpen, and vpr::ReturnStatus::setCode.
00157 {
00158 vpr::ReturnStatus status;
00159
00160 // We cannot write if we are not open or we not are connected.
00161 if ( ! isOpen() || ! isConnected() )
00162 {
00163 status.setCode(vpr::ReturnStatus::Fail);
00164 }
00165
00166 return status;
00167 }
|
|
|
< Queue of pending connection requests.This is a list of the requesting connectors.
Definition at line 187 of file SocketStreamImplSIM.h. Referenced by accept, and addConnector. |
|
|
Mutex for connector queue.
Definition at line 188 of file SocketStreamImplSIM.h. Referenced by accept, and addConnector. |
|
|
Definition at line 190 of file SocketStreamImplSIM.h. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002