Skip to content

Commit

Permalink
eliminate extra copy
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Jun 26, 2014
1 parent 7a79d49 commit acbe0d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
11 changes: 5 additions & 6 deletions TunnelGateway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,10 @@ namespace tunnel
}
}

const std::vector<I2NPMessage *> TunnelGatewayBuffer::GetTunnelDataMsgs ()
void TunnelGatewayBuffer::ClearTunnelDataMsgs ()
{
CompleteCurrentTunnelDataMessage ();
std::vector<I2NPMessage *> ret = m_TunnelDataMsgs; // TODO: implement it better
m_TunnelDataMsgs.clear ();
return ret;
}
m_TunnelDataMsgs.clear ();
}

void TunnelGatewayBuffer::CreateCurrentTunnelDataMessage ()
{
Expand Down Expand Up @@ -162,6 +159,7 @@ namespace tunnel

void TunnelGateway::SendBuffer ()
{
m_Buffer.CompleteCurrentTunnelDataMessage ();
auto tunnelMsgs = m_Buffer.GetTunnelDataMsgs ();
for (auto tunnelMsg : tunnelMsgs)
{
Expand All @@ -170,6 +168,7 @@ namespace tunnel
i2p::transports.SendMessage (m_Tunnel->GetNextIdentHash (), tunnelMsg);
m_NumSentBytes += TUNNEL_DATA_MSG_SIZE;
}
m_Buffer.ClearTunnelDataMsgs ();
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions TunnelGateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ namespace tunnel
TunnelGatewayBuffer (uint32_t tunnelID): m_TunnelID (tunnelID),
m_CurrentTunnelDataMsg (nullptr), m_RemainingSize (0) {};
void PutI2NPMsg (const TunnelMessageBlock& block);
const std::vector<I2NPMessage *> GetTunnelDataMsgs ();
const std::vector<I2NPMessage *>& GetTunnelDataMsgs () const { return m_TunnelDataMsgs; };
void ClearTunnelDataMsgs ();
void CompleteCurrentTunnelDataMessage ();

private:

void CreateCurrentTunnelDataMessage ();
void CompleteCurrentTunnelDataMessage ();

private:

Expand All @@ -37,11 +38,11 @@ namespace tunnel

TunnelGateway (TunnelBase * tunnel):
m_Tunnel (tunnel), m_Buffer (tunnel->GetNextTunnelID ()), m_NumSentBytes (0) {};
void SendTunnelDataMsg (const TunnelMessageBlock& block);
void PutTunnelDataMsg (const TunnelMessageBlock& block);
void SendBuffer ();
void SendTunnelDataMsg (const TunnelMessageBlock& block);
void PutTunnelDataMsg (const TunnelMessageBlock& block);
void SendBuffer ();
size_t GetNumSentBytes () const { return m_NumSentBytes; };

private:

TunnelBase * m_Tunnel;
Expand Down

0 comments on commit acbe0d8

Please sign in to comment.