Skip to content

Commit

Permalink
[XrdCl] Add Socket::ReadV method.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichal authored and gganis committed Nov 23, 2021
1 parent f2cdc6c commit afad44d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/XrdCl/XrdClSocket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,27 @@ namespace XrdCl
return XRootDStatus();
}

//----------------------------------------------------------------------------
// ReadV helper for raw socket
//----------------------------------------------------------------------------
XRootDStatus Socket::ReadV( iovec *iov, int iocnt, int &bytesRead )
{
if( pTls ) return XRootDStatus( stError, errNotSupported );

int status = ::readv( pSocket, iov, iocnt );

// if the server shut down the socket declare a socket error (it
// will trigger a re-connect)
if( status == 0 )
return XRootDStatus( stError, errSocketError, errno );

if( status < 0 )
return ClassifyErrno( errno );

bytesRead = status;
return XRootDStatus();
}

//------------------------------------------------------------------------
// Cork the underlying socket
//------------------------------------------------------------------------
Expand Down
13 changes: 13 additions & 0 deletions src/XrdCl/XrdClSocket.hh
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,19 @@ namespace XrdCl
//----------------------------------------------------------------------------
XRootDStatus Read( char *buffer, size_t size, int &bytesRead );

//----------------------------------------------------------------------------
//! ReadV helper for raw socket
//!
//! @param iov : the buffers for the data
//! @param iocnt : number of buffers
//! @param bytesRead : number of bytes actually written into the sink
//! @return : success : ( stOK )
//! EAGAIN : ( stOK, suRetry )
//! EWOULDBLOCK : ( stOK, suRetry )
//! other error : ( stError, errSocketError )
//----------------------------------------------------------------------------
XRootDStatus ReadV( iovec *iov, int iocnt, int &bytesRead );

//------------------------------------------------------------------------
//! Get the file descriptor
//------------------------------------------------------------------------
Expand Down
19 changes: 19 additions & 0 deletions src/XrdCl/XrdClTls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,25 @@ namespace XrdCl
return status;
}

//------------------------------------------------------------------------
//! (Fake) ReadV through the TLS layer from the socket
//! If necessary, will establish a TLS/SSL session.
//------------------------------------------------------------------------
XRootDStatus Tls::ReadV( iovec *iov, int iocnt, int &bytesRead )
{
bytesRead = 0;
for( int i = 0; i < iocnt; ++i )
{
int btsread = 0;
auto st = Read( static_cast<char*>( iov[i].iov_base ),
iov[i].iov_len, btsread );
if( !st.IsOK() ) return st;
bytesRead += btsread;
if( st.code == suRetry ) return st;
}
return XRootDStatus();
}

XRootDStatus Tls::Send( const char *buffer, size_t size, int &bytesWritten )
{
//--------------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions src/XrdCl/XrdClTls.hh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ namespace XrdCl
//------------------------------------------------------------------------
XRootDStatus Read( char *buffer, size_t size, int &bytesRead );

//------------------------------------------------------------------------
//! (Fake) ReadV through the TLS layer from the socket
//! If necessary, will establish a TLS/SSL session.
//------------------------------------------------------------------------
XRootDStatus ReadV( iovec *iov, int iocnt, int &bytesRead );

//------------------------------------------------------------------------
//! Write through the TLS layer to the socket
//! If necessary, will establish a TLS/SSL session.
Expand Down

0 comments on commit afad44d

Please sign in to comment.