"Fossies" - the Fresh Open Source Software Archive

Member "openlitespeed-1.6.6/src/edio/aiooutputstream.h" (22 Jan 2020, 3839 Bytes) of package /linux/www/openlitespeed-1.6.6.src.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "aiooutputstream.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.6.5_vs_1.6.6.

    1 /*****************************************************************************
    2 *    Open LiteSpeed is an open source HTTP server.                           *
    3 *    Copyright (C) 2013 - 2020  LiteSpeed Technologies, Inc.                 *
    4 *                                                                            *
    5 *    This program is free software: you can redistribute it and/or modify    *
    6 *    it under the terms of the GNU General Public License as published by    *
    7 *    the Free Software Foundation, either version 3 of the License, or       *
    8 *    (at your option) any later version.                                     *
    9 *                                                                            *
   10 *    This program is distributed in the hope that it will be useful,         *
   11 *    but WITHOUT ANY WARRANTY; without even the implied warranty of          *
   12 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
   13 *    GNU General Public License for more details.                            *
   14 *                                                                            *
   15 *    You should have received a copy of the GNU General Public License       *
   16 *    along with this program. If not, see http://www.gnu.org/licenses/.      *
   17 *****************************************************************************/
   18 #ifndef AIOOUTPUTSTREAM_H
   19 #define AIOOUTPUTSTREAM_H
   20 
   21 #include <lsdef.h>
   22 #include <edio/eventhandler.h>
   23 
   24 #include <aio.h>
   25 #include <sys/types.h>
   26 
   27 #include <signal.h>
   28 
   29 
   30 #ifdef LS_AIO_USE_KQ
   31 #include <sys/event.h>
   32 #endif
   33 
   34 class AutoBuf;
   35 
   36 class AioReq
   37 {
   38     static int      s_rtsigNo;
   39     struct aiocb    m_aiocb;
   40 
   41 private:
   42     void setcb(int fildes, void *buf, size_t nbytes, int off, void *handler);
   43 
   44 public:
   45     AioReq();
   46 
   47     void *getBuf()
   48     {
   49         void *p = (void *)m_aiocb.aio_buf;
   50         m_aiocb.aio_buf = NULL;
   51         return p;
   52     }
   53 
   54     off_t getOffset()
   55     {   return m_aiocb.aio_offset;  }
   56 
   57     int getError()
   58     {   return aio_error(&m_aiocb);   }
   59 
   60     //NOTICE: If the error is EINPROGRESS, the result of this is undefined.
   61     int getReturn()
   62     {   return aio_return(&m_aiocb);  }
   63 
   64     int read(int fildes, void *buf, int nbytes, int offset,
   65              EventHandler *pHandler)
   66     {
   67         setcb(fildes, buf, nbytes, offset, pHandler);
   68         return aio_read(&m_aiocb);
   69     }
   70     int write(int fildes, void *buf, int nbytes, int offset,
   71               EventHandler *pHandler)
   72     {
   73         setcb(fildes, buf, nbytes, offset, pHandler);
   74         return aio_write(&m_aiocb);
   75     }
   76 
   77     static void setSigNo(int signo)     {   s_rtsigNo = signo;  }
   78 
   79     LS_NO_COPY_ASSIGN(AioReq);
   80 };
   81 
   82 class AioOutputStream : public EventHandler, private AioReq
   83 {
   84     int             m_fd;
   85     char            m_async;
   86     char            m_flushRequested;
   87     char            m_closeRequested;
   88     char            m_iFlock;
   89     AutoBuf        *m_pRecv;
   90     AutoBuf        *m_pSend;
   91 
   92 private:
   93     int syncWrite(const char *pBuf, int len);
   94 
   95 public:
   96 
   97     AioOutputStream()
   98         : AioReq()
   99         , m_fd(-1)
  100         , m_async(0)
  101         , m_flushRequested(0)
  102         , m_closeRequested(0)
  103         , m_iFlock(0)
  104         , m_pRecv(NULL)
  105         , m_pSend(NULL)
  106     {
  107     }
  108     virtual ~AioOutputStream() {};
  109 
  110     int getfd() const               {   return m_fd;            }
  111     void setfd(int fd)            {   m_fd = fd;              }
  112     int open(const char *pathname, int flags, mode_t mode);
  113     int close();
  114     bool isAsync() const            {   return m_async == 1;    }
  115 
  116     void setFlock(int l)           {   m_iFlock = l;           }
  117 
  118     void setAsync()
  119     {
  120 #ifdef LS_AIO_USE_AIO
  121         m_async = 1;
  122 #endif
  123     }
  124 
  125     int append(const char *pBuf, int len);
  126     virtual int onEvent();
  127     int flush();
  128     LS_NO_COPY_ASSIGN(AioOutputStream);
  129 };
  130 
  131 
  132 
  133 #endif //AIOOUTPUTSTREAM_H