Skip to content

Commit

Permalink
[XrdCl] Move msg writing logic to Socket.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichal authored and gganis committed Nov 23, 2021
1 parent 9322679 commit 10942d8
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 74 deletions.
38 changes: 1 addition & 37 deletions src/XrdCl/XrdClAsyncHSWriter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace XrdCl
{
case WriteRequest:
{
XRootDStatus st = WriteCurrentMessage( *outmsg );
XRootDStatus st = socket.Send( *outmsg, strmname );
if( !st.IsOK() || st.code == suRetry ) return st;
//----------------------------------------------------------------
// The next step is to write the signature
Expand Down Expand Up @@ -115,42 +115,6 @@ namespace XrdCl

private:


XRootDStatus WriteCurrentMessage( Message &msg )
{
Log *log = DefaultEnv::GetLog();
//----------------------------------------------------------------------
// Try to write down the current message
//----------------------------------------------------------------------
size_t btsleft = msg.GetSize() - msg.GetCursor();
if( !btsleft ) return XRootDStatus();

while( btsleft )
{
int wrtcnt = 0;
XRootDStatus st = socket.Send( msg.GetBufferAtCursor(), btsleft, wrtcnt );

if( !st.IsOK() )
{
msg.SetCursor( 0 );
return st;
}

if( st.code == suRetry ) return st;

msg.AdvanceCursor( wrtcnt );
btsleft -= wrtcnt;
}

//----------------------------------------------------------------------
// We have written the message successfully
//----------------------------------------------------------------------
log->Dump( AsyncSockMsg, "[%s] Wrote a message: %s (0x%x), %d bytes",
strmname.c_str(), msg.GetDescription().c_str(),
&msg, msg.GetSize() );
return XRootDStatus();
}

//------------------------------------------------------------------------
//! Stages of reading out a response from the socket
//------------------------------------------------------------------------
Expand Down
39 changes: 2 additions & 37 deletions src/XrdCl/XrdClAsyncMsgWriter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ namespace XrdCl
//----------------------------------------------------------------
if( outsign )
{
XRootDStatus st = WriteCurrentMessage( *outsign );
XRootDStatus st = socket.Send( *outsign, strmname );
if( !st.IsOK() || st.code == suRetry ) return st;
}
//----------------------------------------------------------------
Expand All @@ -141,7 +141,7 @@ namespace XrdCl
//------------------------------------------------------------------
case WriteRequest:
{
XRootDStatus st = WriteCurrentMessage( *outmsg );
XRootDStatus st = socket.Send( *outmsg, strmname );
if( !st.IsOK() || st.code == suRetry ) return st;
//----------------------------------------------------------------
// The next step is to write the signature
Expand Down Expand Up @@ -200,41 +200,6 @@ namespace XrdCl

private:

XRootDStatus WriteCurrentMessage( Message &msg )
{
Log *log = DefaultEnv::GetLog();
//----------------------------------------------------------------------
// Try to write down the current message
//----------------------------------------------------------------------
size_t btsleft = msg.GetSize() - msg.GetCursor();
if( !btsleft ) return XRootDStatus();

while( btsleft )
{
int wrtcnt = 0;
XRootDStatus st = socket.Send( msg.GetBufferAtCursor(), btsleft, wrtcnt );

if( !st.IsOK() )
{
msg.SetCursor( 0 );
return st;
}

if( st.code == suRetry ) return st;

msg.AdvanceCursor( wrtcnt );
btsleft -= wrtcnt;
}

//----------------------------------------------------------------------
// We have written the message successfully
//----------------------------------------------------------------------
log->Dump( AsyncSockMsg, "[%s] Wrote a message: %s (0x%x), %d bytes",
strmname.c_str(), msg.GetDescription().c_str(),
&msg, msg.GetSize() );
return XRootDStatus();
}

//------------------------------------------------------------------------
//! Stages of reading out a response from the socket
//------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/XrdCl/XrdClAsyncSocketHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ namespace XrdCl
delete pHandShakeData;
pHandShakeData = nullptr;
hswriter.reset();
hsreader.reset();
XRootDStatus st;
if( !(st = EnableUplink()).IsOK() )
{
Expand Down
38 changes: 38 additions & 0 deletions src/XrdCl/XrdClSocket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,44 @@ namespace XrdCl
return XRootDStatus();
}

//------------------------------------------------------------------------
// Write message to the socket
//------------------------------------------------------------------------
XRootDStatus Socket::Send( Message &msg, const std::string &strmname )
{
//----------------------------------------------------------------------
// Try to write down the current message
//----------------------------------------------------------------------
size_t btsleft = msg.GetSize() - msg.GetCursor();
if( !btsleft ) return XRootDStatus();

while( btsleft )
{
int wrtcnt = 0;
XRootDStatus st = Send( msg.GetBufferAtCursor(), btsleft, wrtcnt );

if( !st.IsOK() )
{
msg.SetCursor( 0 );
return st;
}

if( st.code == suRetry ) return st;

msg.AdvanceCursor( wrtcnt );
btsleft -= wrtcnt;
}

//----------------------------------------------------------------------
// We have written the message successfully
//----------------------------------------------------------------------
Log *log = DefaultEnv::GetLog();
log->Dump( AsyncSockMsg, "[%s] Wrote a message: %s (0x%x), %d bytes",
strmname.c_str(), msg.GetDescription().c_str(),
&msg, msg.GetSize() );
return XRootDStatus();
}

//----------------------------------------------------------------------------
// Poll the descriptor
//----------------------------------------------------------------------------
Expand Down
10 changes: 10 additions & 0 deletions src/XrdCl/XrdClSocket.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace XrdCl
class AnyObject;
class Tls;
class AsyncSocketHandler;
class Message;

//----------------------------------------------------------------------------
//! A network socket
Expand Down Expand Up @@ -173,6 +174,15 @@ namespace XrdCl
//------------------------------------------------------------------------
XRootDStatus Send( XrdSys::KernelBuffer &kbuff, int &bytesWritten );

//------------------------------------------------------------------------
//! Write message to the socket
//!
//! @param msg : message (request) to be sent
//! @param strmname : stream name (for logging purposes)
//! @return : the amount of data actually written
//------------------------------------------------------------------------
XRootDStatus Send( Message &msg, const std::string &strmname );

//----------------------------------------------------------------------------
//! Read helper for raw socket
//!
Expand Down

0 comments on commit 10942d8

Please sign in to comment.