Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-08 10:33:40

0001 #ifndef __SFS_XIO_H__
0002 #define __SFS_XIO_H__
0003 /******************************************************************************/
0004 /*                                                                            */
0005 /*                          X r d S f s X i o . h h                           */
0006 /*                                                                            */
0007 /* (c) 2013 by the Board of Trustees of the Leland Stanford, Jr., University  */
0008 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
0009 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
0010 /*                                                                            */
0011 /* This file is part of the XRootD software suite.                            */
0012 /*                                                                            */
0013 /* XRootD is free software: you can redistribute it and/or modify it under    */
0014 /* the terms of the GNU Lesser General Public License as published by the     */
0015 /* Free Software Foundation, either version 3 of the License, or (at your     */
0016 /* option) any later version.                                                 */
0017 /*                                                                            */
0018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
0019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
0020 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
0021 /* License for more details.                                                  */
0022 /*                                                                            */
0023 /* You should have received a copy of the GNU Lesser General Public License   */
0024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
0025 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
0026 /*                                                                            */
0027 /* The copyright holder's institutional names and contributor's names may not */
0028 /* be used to endorse or promote products derived from this software without  */
0029 /* specific prior written permission of the institution or contributor.       */
0030 /******************************************************************************/
0031 
0032 //-----------------------------------------------------------------------------
0033 //! XrdSfsXio.hh
0034 //!
0035 //! This class is used to allow file I/O interfaces to perform exchange buffer
0036 //! I/O in order to minimize data copying. When this feature is enabled, the
0037 //! XrdSfsInterface::setXio() method is called on a newly created XrdSfsFile
0038 //! object. Ideally, all oustanding buffers should be be released when the file
0039 //! is closed. Alternatively, the XrdSfsXio::Reclaim() method may be used
0040 //! at any time when it is convenient to do so. For best performance, use
0041 //! XrdSfsXio::Swap() as it provides memory locality and is kind to the cache.
0042 //! Buffer swapping is only supported for common file write operations.
0043 //-----------------------------------------------------------------------------
0044 
0045 //typedef void* XrdSfsXioHandle;
0046 typedef class XrdBuffer* XrdSfsXioHandle;
0047 
0048 class XrdSfsXioImpl;
0049 
0050 /******************************************************************************/
0051 /*                       C l a s s   X r d S f s X i o                        */
0052 /******************************************************************************/
0053   
0054 class XrdSfsXio
0055 {
0056 public:
0057 
0058 //-----------------------------------------------------------------------------
0059 //! Get the address and size of the buffer associated with a handle.
0060 //!
0061 //! @param theHand  - The handle associated with the buffer.
0062 //! @param buffsz   - If not nil, the size of the buffer is returned. The
0063 //!                   size will always be >= to the original data length.
0064 //!
0065 //! @return A pointer to the buffer.
0066 //-----------------------------------------------------------------------------
0067 
0068 static char      *Buffer(XrdSfsXioHandle theHand, int *buffsz=0);
0069 
0070 //-----------------------------------------------------------------------------
0071 //! Claim ownership of the current buffer if it is memory effecient to do so.
0072 //!
0073 //! @param  curBuff - The address of the current buffer. It must match the
0074 //!                   the buffer that was most recently passed to the caller.
0075 //! @param  datasz  - Number of useful bytes in the buffer (i.e. write size).
0076 //! @param  minasz  - Minimum buffer size that would be allocated to copy data.
0077 //!
0078 //! @return !0        The buffer handle of the current buffer is returned along
0079 //!                   with ownership rights.
0080 //! @return =0        Too much memory would be wasted by transferring ownership
0081 //!                   (errno == 0) or an error ocurred (errno != 0). When an
0082 //!                   error see Swap() below for possible types of errors.
0083 //-----------------------------------------------------------------------------
0084 virtual
0085 XrdSfsXioHandle   Claim(const char *curBuff, int datasz, int minasz) = 0;
0086 
0087 //-----------------------------------------------------------------------------
0088 //! Return a buffer previously gotten from a Claim() or Swap() call.
0089 //!
0090 //! @param theHand  - The handle associated with the buffer.
0091 //-----------------------------------------------------------------------------
0092 
0093 static void       Reclaim(XrdSfsXioHandle theHand);
0094 
0095 //-----------------------------------------------------------------------------
0096 //! Swap the current I/O buffer
0097 //!
0098 //! @param  curBuff - The address of the current buffer. It must match the
0099 //!                   the buffer that was most recently passed to the caller.
0100 //! @param  oldHand - The handle associated with a buffer returned by a
0101 //!                   previous call to Swap(). A value of zero indicates that
0102 //!                   the caller is taking control of the buffer but has no
0103 //!                   replacement buffer.
0104 //! @return !0        The buffer handle of the current buffer is returned along
0105 //!                   with ownership rights. If oldHand was not nil, the
0106 //!                   caller's ownership of the associated buffer is reclaimed.
0107 //! @return =0        An error occurred and nothing has changed; errno holds
0108 //!                   the reason for the error. Typically,
0109 //!                   EINVAL  - curBuff doe not match current buffer.
0110 //!                   ENOBUFS - not enough memory to give up buffer.
0111 //!                   ENOTSUP - unsupported context for call.
0112 //-----------------------------------------------------------------------------
0113 virtual
0114 XrdSfsXioHandle   Swap(const char *curBuff, XrdSfsXioHandle oldHand=0) = 0;
0115 
0116 //-----------------------------------------------------------------------------
0117 //! Constructor and destructor
0118 //!
0119 //! @param xioimpl    Reference to static method implementations.
0120 //-----------------------------------------------------------------------------
0121 
0122              XrdSfsXio(XrdSfsXioImpl &xioimpl);
0123 
0124 //-----------------------------------------------------------------------------
0125 //! Constructor and destructor
0126 //-----------------------------------------------------------------------------
0127 
0128 virtual     ~XrdSfsXio() {}
0129 };
0130 #endif