Skip to content

Commit

Permalink
Change the ClientInterface to cache the URI, rather than calculating …
Browse files Browse the repository at this point in the history
…it on the fly. See #165
  • Loading branch information
awr01 authored and tswilliams committed Dec 1, 2019
1 parent dce7d1d commit 0e83dba
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 43 deletions.
5 changes: 5 additions & 0 deletions uhal/grammars/include/uhal/grammars/URI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ namespace uhal
};

std::ostream& operator<< ( std::ostream& aStr , const uhal::URI& aURI );


std::string ToString( const URI& aURI );


}


Expand Down
45 changes: 45 additions & 0 deletions uhal/grammars/src/common/URI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@


#include <iostream>
#include <sstream>


namespace uhal {
Expand All @@ -56,4 +57,48 @@ namespace uhal {
return aStr;
}


std::string ToString( const uhal::URI& aURI )
{
std::stringstream lReturn;
// url is always of the form "protocol://hostname:port"
lReturn << aURI.mProtocol << "://" << aURI.mHostname;
if ( !aURI.mPort.empty() )
lReturn << ":" << aURI.mPort;

// there is sometimes a path
if ( aURI.mPath != "" )
{
lReturn << "/" << aURI.mPath;
}

// there is sometimes a filename extension
if ( aURI.mExtension != "" )
{
lReturn << "." << aURI.mExtension;
}

// there are sometimes arguments
if ( aURI.mArguments.size() )
{
lReturn << "?";
uhal::NameValuePairVectorType::const_iterator lIt = aURI.mArguments.begin();

while ( true )
{
lReturn << lIt->first << "=" << lIt->second;

if ( ++lIt == aURI.mArguments.end() )
{
break;
}

lReturn << "&";
}
}

return lReturn.str();
}


}
4 changes: 3 additions & 1 deletion uhal/uhal/include/uhal/ClientInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ namespace uhal
Return the url of the target for this client
@return the url of the target for this client
*/
std::string uri() const;
const std::string& uri() const;

//! Method to dispatch all queued transactions, and wait until all corresponding responses have been received
void dispatch ();
Expand Down Expand Up @@ -410,6 +410,8 @@ namespace uhal
//! a struct containing the full URI of the target for this client
URI mUri;

std::string mUriString;

/**
Function which checks the available space in the currently filling buffer against requested send and receive sizes and, if there is insufficient space in the currently filling buffer, then dispatch it and create a new buffer
@param aSendSize the amount of data that the current instruction wishes to send
Expand Down
51 changes: 9 additions & 42 deletions uhal/uhal/src/common/ClientInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ namespace uhal
#endif
mId ( aId ),
mTimeoutPeriod ( aTimeoutPeriod ),
mUri ( aUri )
mUri ( aUri ),
mUriString( ToString(aUri) )
{
}

Expand All @@ -67,7 +68,8 @@ namespace uhal
#endif
mId ( ),
mTimeoutPeriod ( boost::posix_time::pos_infin ),
mUri ( )
mUri ( ),
mUriString( "" )
{
}

Expand All @@ -79,7 +81,8 @@ namespace uhal
#endif
mId ( aClientInterface.mId ),
mTimeoutPeriod ( aClientInterface.mTimeoutPeriod ),
mUri ( aClientInterface.mUri )
mUri ( aClientInterface.mUri ),
mUriString( aClientInterface.mUriString )
{
}

Expand All @@ -89,6 +92,7 @@ namespace uhal
deleteBuffers();
mId = aClientInterface.mId;
mUri = aClientInterface.mUri;
mUriString = aClientInterface.mUriString;
mTimeoutPeriod = aClientInterface.mTimeoutPeriod;
return *this;
}
Expand Down Expand Up @@ -131,46 +135,9 @@ namespace uhal
// }


std::string ClientInterface::uri() const
const std::string& ClientInterface::uri() const
{
std::stringstream lReturn;
// url is always of the form "protocol://hostname:port"
lReturn << mUri.mProtocol << "://" << mUri.mHostname;
if ( !mUri.mPort.empty() )
lReturn << ":" << mUri.mPort;

// there is sometimes a path
if ( mUri.mPath != "" )
{
lReturn << "/" << mUri.mPath;
}

// there is sometimes a filename extension
if ( mUri.mExtension != "" )
{
lReturn << "." << mUri.mExtension;
}

// there are sometimes arguments
if ( mUri.mArguments.size() )
{
lReturn << "?";
uhal::NameValuePairVectorType::const_iterator lIt = mUri.mArguments.begin();

while ( true )
{
lReturn << lIt->first << "=" << lIt->second;

if ( ++lIt == mUri.mArguments.end() )
{
break;
}

lReturn << "&";
}
}

return lReturn.str();
return mUriString;
}


Expand Down

0 comments on commit 0e83dba

Please sign in to comment.