Changeset 1389:aa5091977955


Ignore:
Timestamp:
11/05/09 17:52:12 (2 years ago)
Author:
niam
Branch:
default
Message:

io: read*/write* methods return amount of successfully read/written bytes

Location:
src
Files:
50 edited

Legend:

Unmodified
Added
Removed
  • src/examples/image/test.cc

    r1386 r1389  
    7878        file::regular io; 
    7979        io.open("my.png", file::regular::OPEN_MODE_READ_WRITE_TRUNCATE); 
    80         io.blockSize = img.size(); 
     80        io.bs = img.size(); 
    8181        io.write(img); 
    8282 
  • src/examples/iofile_toolsfilesystem/test.cc

    r1386 r1389  
    7171 
    7272        io1.pos = 1; 
    73         io1.blockSize = 14; 
     73        io1.bs = 14; 
    7474        io1.block = true; 
    7575        io1.write("!12345890$!~@\n"); 
  • src/examples/iomemory/test.cc

    r1386 r1389  
    3131 
    3232        io1.pos = 1; 
    33         io1.blockSize = 14; 
     33        io1.bs = 14; 
    3434        io1.write("!12345890$!~@\n"); 
    3535 
  • src/examples/ionetwork_pcthreads/test.cc

    r1386 r1389  
    4040        ex->setOutBufferSize(1); 
    4141 
    42         ex->blockSize = 7; 
     42        ex->bs = 7; 
    4343        ex->writeString("test\n"); 
    4444 
    4545        dodoString str = ""; 
    4646        try { 
    47             ex->blockSize = 4; 
     47            ex->bs = 4; 
    4848            str = ex->read(); 
    4949 
  • src/examples/ionetworkclient/test.cc

    r1386 r1389  
    3131 
    3232        str = "GET / HTTP/1.1\r\n"; 
    33         ex.blockSize = str.size(); 
     33        ex.bs = str.size(); 
    3434        ex.write(str); 
    3535 
    3636        str = "Host: " + host + "\r\n"; 
    37         ex.blockSize = str.size(); 
     37        ex.bs = str.size(); 
    3838        ex.write(str); 
    3939 
    4040        str = "Connection: Close\r\n"; 
    41         ex.blockSize = str.size(); 
     41        ex.bs = str.size(); 
    4242        ex.write(str); 
    4343 
    4444        str = "User-Agent: " PACKAGE_NAME "/" PACKAGE_VERSION "\r\n\r\n"; 
    45         ex.blockSize = str.size(); 
     45        ex.bs = str.size(); 
    4646        ex.write(str); 
    4747 
    48         ex.blockSize = 512; 
     48        ex.bs = 512; 
    4949        str = ex.readString(); 
    5050 
  • src/examples/ionetworkserver/test.cc

    r1386 r1389  
    2929    ex.setOutBufferSize(1); 
    3030 
    31     ex.blockSize = 7; 
     31    ex.bs = 7; 
    3232    ex.writeString("test\n"); 
    3333 
    3434    dodoString str = ""; 
    3535    try { 
    36         ex.blockSize = 4; 
     36        ex.bs = 4; 
    3737        str = ex.read(); 
    3838 
  • src/examples/ionetworksslclient/test.cc

    r1386 r1389  
    4646 
    4747        str = "GET / HTTP/1.1\r\n"; 
    48         ex.blockSize = str.size(); 
     48        ex.bs = str.size(); 
    4949        ex.write(str); 
    5050 
    5151        str = "Host: " + host + "\r\n"; 
    52         ex.blockSize = str.size(); 
     52        ex.bs = str.size(); 
    5353        ex.write(str); 
    5454 
    5555        str = "Connection: Close\r\n"; 
    56         ex.blockSize = str.size(); 
     56        ex.bs = str.size(); 
    5757        ex.write(str); 
    5858 
    5959        str = "User-Agent: " PACKAGE_NAME "/" PACKAGE_VERSION "\r\n\r\n"; 
    60         ex.blockSize = str.size(); 
     60        ex.bs = str.size(); 
    6161        ex.write(str); 
    6262 
    63         ex.blockSize = 4096; 
     63        ex.bs = 4096; 
    6464        str = ex.readString(); 
    6565 
  • src/examples/ionetworksslserver/test.cc

    r1386 r1389  
    4141    ex.setOutBufferSize(1); 
    4242 
    43     ex.blockSize = 7; 
     43    ex.bs = 7; 
    4444    ex.writeString("test\n"); 
    4545 
     
    4949    dodoString str = ""; 
    5050    try { 
    51         ex.blockSize = 4; 
     51        ex.bs = 4; 
    5252        str = ex.read(); 
    5353 
  • src/examples/iopipe_iofilefifo_pcthread/test.cc

    r1386 r1389  
    3333        cout.flush(); 
    3434 
    35         pipe->blockSize = tools::string::stringToUL(str); 
     35        pipe->bs = tools::string::stringToUL(str); 
    3636        str = pipe->read(); 
    3737        cout << "%MD5: " << tools::code::MD5Hex(str) << "%\n"; 
     
    6666        pipe->flush(); 
    6767 
    68         pipe->blockSize = str.size(); 
     68        pipe->bs = str.size(); 
    6969        pipe->write(str); 
    7070        pipe->flush(); 
     
    103103 
    104104        cout << "\n~~using original cloned pipe for one thread and copy for the second~~\n"; 
    105         pipe1.blockSize = 4096; 
     105        pipe1.bs = 4096; 
    106106 
    107107        io::pipe pipe2 = pipe1; 
  • src/examples/iostdio/test.cc

    r1386 r1389  
    2525        stdio *io = dynamic_cast<stdio *>(st->executor); 
    2626        dodoString buffer = st->buffer; 
    27         io->blockSize = 100; 
     27        io->bs = 100; 
    2828        io->writeString("\nhook\n"); 
    2929 
    3030        dodoString str = ">" + buffer + "<\n"; 
    3131 
    32         io->blockSize = str.size(); 
     32        io->bs = str.size(); 
    3333        st->buffer.assign(str); 
    3434    } 
     
    4848#endif 
    4949 
    50         st.blockSize = sizeof("write"); 
     50        st.bs = sizeof("write"); 
    5151        st.write("write"); 
    5252        st.flush(); 
     
    5757        dodoString o; 
    5858 
    59         st.blockSize = 33; 
     59        st.bs = 33; 
    6060 
    6161        o = st.read(); 
     
    6464        cout << o << "\n"; 
    6565 
    66         st.blockSize = 4; 
     66        st.bs = 4; 
    6767        st.write("1234567890"); 
    6868        st.writeString("\n"); 
    6969 
    70         st.blockSize = 40; 
     70        st.bs = 40; 
    7171        st.writeString(o); 
    7272        st.writeString("\nexiting\n"); 
  • src/examples/rpcjsoncgiserver/test.cc

    r1386 r1389  
    3838 
    3939        if (size != 0) { 
    40             if (size > blockSize) 
    41                 size = blockSize; 
     40            if (size > bs) 
     41                size = bs; 
    4242 
    4343            memcpy(data, provider.content.data(), size); 
    44             if (size < blockSize) 
    45                 memset(data + size, 0x0, blockSize - size); 
     44            if (size < bs) 
     45                memset(data + size, 0x0, bs - size); 
    4646        } 
    4747 
  • src/examples/rpcjsonhttpclient/test.cc

    r1386 r1389  
    4646            size = response->data.size(); 
    4747            if (size != 0) { 
    48                 if (size > blockSize) 
    49                     size = blockSize; 
     48                if (size > bs) 
     49                    size = bs; 
    5050 
    5151                memcpy(data, response->data.data(), size); 
    52                 if (size < blockSize) 
    53                     memset(data + size, 0x0, blockSize - size); 
     52                if (size < bs) 
     53                    memset(data + size, 0x0, bs - size); 
    5454            } 
    5555 
  • src/examples/rpcxmlcgiserver/test.cc

    r1386 r1389  
    3838 
    3939        if (size != 0) { 
    40             if (size > blockSize) 
    41                 size = blockSize; 
     40            if (size > bs) 
     41                size = bs; 
    4242 
    4343            memcpy(data, provider.content.data(), size); 
    44             if (size < blockSize) 
    45                 memset(data + size, 0x0, blockSize - size); 
     44            if (size < bs) 
     45                memset(data + size, 0x0, bs - size); 
    4646        } 
    4747 
  • src/examples/rpcxmlhttpclient/test.cc

    r1386 r1389  
    4747            size = response->data.size(); 
    4848            if (size != 0) { 
    49                 if (size > blockSize) 
    50                     size = blockSize; 
     49                if (size > bs) 
     50                    size = bs; 
    5151 
    5252                memcpy(data, response->data.data(), size); 
    53                 if (size < blockSize) 
    54                     memset(data + size, 0x0, blockSize - size); 
     53                if (size < bs) 
     54                    memset(data + size, 0x0, bs - size); 
    5555            } 
    5656 
  • src/examples/xexec/test.cc

    r1386 r1389  
    3434#endif 
    3535 
    36         io.blockSize = sizeof("xexec") - 1; 
     36        io.bs = sizeof("xexec") - 1; 
    3737        io.write("xexec"); 
    3838        io.flush(); 
  • src/include/libdodo/cgiFastExchange.h

    r1386 r1389  
    9494 
    9595                /** 
    96                  * read 
    97                  * @param data is filled with read data 
    98                  * if blockSize bigger than buffer size - reads with few iterations 
     96                 * @return successfully read bytes 
     97                 * @param data defines buffer that will be filled 
     98                 * @note not more then bs(including null) 
    9999                 */ 
    100                 virtual void _read(char * const data) const; 
     100                virtual unsigned long _read(char * const data) const; 
    101101 
    102102                /** 
    103                  * read from stream - '\0' or '\n' - terminated string 
     103                 * read null- or newline- terminated string 
     104                 * @return successfully read bytes 
    104105                 * @param data defines buffer that will be filled 
    105                  * @note not more then blockSize(including '\0') 
     106                 * @note not more then bs(including null) 
    106107                 */ 
    107108                virtual unsigned long _readString(char * const data) const; 
    108109 
    109110                /** 
    110                  * write 
    111                  * @param data is data that will be written 
    112                  * if blockSize bigger than buffer size - writes with few iterations 
     111                 * @return successfully written bytes 
     112                 * @param data defines data that will be written 
    113113                 */ 
    114                 virtual void _write(const char * const data) const; 
     114                virtual unsigned long _write(const char * const data) const; 
    115115 
    116116                /** 
    117                  * write to stream - '\0' - terminated string 
     117                 * write null- terminated string 
     118                 * @return successfully written bytes 
    118119                 * @param data defines data that will be written 
     120                 * @note puts extra null in the end of the string 
    119121                 */ 
    120                 virtual void _writeString(const char * const data) const; 
     122                virtual unsigned long _writeString(const char * const data) const; 
    121123 
    122124              private: 
  • src/include/libdodo/cgiFastExchangeEx.h

    r1386 r1389  
    6060                FASTEXCHANGEEX_FLUSH, 
    6161                FASTEXCHANGEEX__WRITE, 
     62                FASTEXCHANGEEX__WRITESTRING, 
    6263                FASTEXCHANGEEX_INDESCRIPTOR, 
    6364                FASTEXCHANGEEX_OUTDESCRIPTOR, 
  • src/include/libdodo/ioBlockChannel.h

    r1386 r1389  
    4242             * @class channel 
    4343             * @brief implements an interface for I/O operations on block sources 
    44              * @note if block is false then read/write position is amount of bytes from the beginning, 
    45              * if block is true then: 
    46              *  offset for write is calculated as pos*blockSize 
    47              *  offset for read is calculated as pos*blockSize 
    48              *  offset for readString is calculated as pos*(amount of null- or newline- terminated strings) 
    49              *  offset for writeString is calculated as pos*(amount of null- or newline- terminated strings) 
    5044             */ 
    5145            class channel : public io::channel { 
     
    6559                /** 
    6660                 * @return read data 
    67                  * @note not more then blockSize 
     61                 * @note not more then bs 
    6862                 */ 
    6963                virtual dodoString read() const; 
    7064 
    7165                /** 
     66                 * @return successfully written bytes 
    7267                 * @param data defines data that will be written 
    73                  * @note not more then blockSize 
     68                 * @note not more then bs 
    7469                 */ 
    75                 virtual void write(const dodoString &data) const; 
     70                virtual unsigned long write(const dodoString &data) const; 
    7671 
    7772                /** 
    78                  * read from stream null- or newline- terminated string 
     73                 * read null- or newline- terminated string 
    7974                 * @return read data 
    80                  * @note not more then blockSize 
     75                 * @note not more then bs 
    8176                 */ 
    8277                virtual dodoString readString() const; 
    8378 
    8479                /** 
    85                  * write to stream null- terminated string 
     80                 * write null- terminated string 
     81                 * @return successfully written bytes 
    8682                 * @param data defines data that will be written 
    87                  * @note not more then blockSize 
     83                 * @note not more then bs 
    8884                 */ 
    89                 virtual void writeString(const dodoString &data) const; 
     85                virtual unsigned long writeString(const dodoString &data) const; 
    9086 
    9187                mutable unsigned long pos;  ///< read/write/erase position; incremented on read/write/erase[0 by default] 
    9288 
    93                 bool block;                 ///< use block I/O[false by default] 
    9489                bool append;                ///< append to the end[false by default] 
    9590            }; 
  • src/include/libdodo/ioChannel.h

    r1386 r1389  
    123123            /** 
    124124             * @return read data 
    125              * @note not more then blockSize 
     125             * @note not more then bs 
    126126             */ 
    127127            virtual dodoString read() const = 0; 
    128128 
    129129            /** 
     130             * @return successfully written bytes 
    130131             * @param data defines data that will be written 
    131              * @note not more then blockSize 
     132             * @note not more then bs 
    132133             */ 
    133             virtual void write(const dodoString &data) const = 0; 
     134            virtual unsigned long write(const dodoString &data) const = 0; 
    134135 
    135136            /** 
    136              * read from stream null- or newline- terminated string 
     137             * read null- or newline- terminated string 
    137138             * @return read data 
    138              * @note not more then blockSize 
     139             * @note not more then bs 
    139140             */ 
    140141            virtual dodoString readString() const = 0; 
    141142 
    142143            /** 
    143              * write to stream null- terminated string 
     144             * write null- terminated string 
     145             * @return successfully written bytes 
    144146             * @param data defines data that will be written 
    145              * @note not more then blockSize 
     147             * @note not more then bs 
    146148             */ 
    147             virtual void writeString(const dodoString &data) const = 0; 
     149            virtual unsigned long writeString(const dodoString &data) const = 0; 
    148150 
    149151            /** 
     
    152154            virtual void flush() const = 0; 
    153155 
    154             mutable unsigned long blockSize;   ///< size of data block for read/write operations 
     156            mutable unsigned long bs;   ///< size of data block for read/write operations 
    155157 
    156158          protected: 
    157159 
    158160            /** 
     161             * @return successfully read bytes 
    159162             * @param data defines buffer that will be filled 
    160              * @note not more then blockSize(including null) 
     163             * @note not more then bs(including null) 
    161164             */ 
    162             virtual void _read(char * const data) const = 0; 
     165            virtual unsigned long _read(char * const data) const = 0; 
    163166 
    164167            /** 
    165              * read from stream null- or newline- terminated string 
     168             * read null- or newline- terminated string 
     169             * @return successfully read bytes 
    166170             * @param data defines buffer that will be filled 
    167              * @note not more then blockSize(including null) 
     171             * @note not more then bs(including null) 
    168172             */ 
    169173            virtual unsigned long _readString(char * const data) const = 0; 
    170174 
    171175            /** 
     176             * @return successfully written bytes 
    172177             * @param data defines data that will be written 
    173              * @note not more then blockSize(including null) 
     178             * @note not more then bs(including null) 
    174179             */ 
    175             virtual void _write(const char * const data) const = 0; 
     180            virtual unsigned long _write(const char * const data) const = 0; 
    176181 
    177182            /** 
    178              * write to stream null- terminated string 
     183             * write null- terminated string 
     184             * @return successfully written bytes 
    179185             * @param data defines data that will be written 
    180              * @note not more then blockSize(including null) 
     186             * @note not more then bs(including null) 
    181187             */ 
    182             virtual void _writeString(const char * const data) const = 0; 
     188            virtual unsigned long _writeString(const char * const data) const = 0; 
    183189 
    184190            pc::sync::protector *keeper;                                    ///< section locker 
  • src/include/libdodo/ioFileFifo.h

    r1386 r1389  
    4545             * @class fifo 
    4646             * @brief provides I/O manipulations with fifo files 
    47              * @note writeString* put extra newline- to the end of the string, so no need to add it manually 
    4847             */ 
    4948            class fifo : virtual public stream::channel { 
     
    145144 
    146145                /** 
     146                 * @return successfully read bytes 
    147147                 * @param data defines buffer that will be filled 
    148                  * @note not more then blockSize(including null) 
     148                 * @note not more then bs(including null) 
    149149                 */ 
    150                 virtual void _read(char * const data) const; 
     150                virtual unsigned long _read(char * const data) const; 
    151151 
    152152                /** 
    153                  * read from stream null- or newline- terminated string 
     153                 * read null- or newline- terminated string 
     154                 * @return successfully read bytes 
    154155                 * @param data defines buffer that will be filled 
    155                  * @note not more then blockSize(including null) 
     156                 * @note not more then bs(including null) 
    156157                 */ 
    157158                virtual unsigned long _readString(char * const data) const; 
    158159 
    159160                /** 
     161                 * @return successfully written bytes 
    160162                 * @param data defines data that will be written 
    161163                 */ 
    162                 virtual void _write(const char * const data) const; 
     164                virtual unsigned long _write(const char * const data) const; 
    163165 
    164166                /** 
    165                  * write to stream null- terminated string 
     167                 * write null- terminated string 
     168                 * @return successfully written bytes 
    166169                 * @param data defines data that will be written 
    167170                 * @note puts extra newline- to the end of the string 
    168171                 */ 
    169                 virtual void _writeString(const char * const data) const; 
     172                virtual unsigned long _writeString(const char * const data) const; 
    170173 
    171174              private: 
  • src/include/libdodo/ioFileFifoEx.h

    r1386 r1389  
    6262                FIFOEX__READ, 
    6363                FIFOEX__WRITE, 
    64                 FIFOEX__READSTREAM, 
    65                 FIFOEX__WRITESTREAM, 
     64                FIFOEX__READSTRING, 
     65                FIFOEX__WRITESTRING, 
    6666                FIFOEX_FLUSH, 
    6767                FIFOEX_BLOCK, 
  • src/include/libdodo/ioFileRegular.h

    r1386 r1389  
    4242 
    4343        namespace file { 
     44            class temp; 
     45 
    4446            /** 
    4547             * @class regular 
     
    4749             */ 
    4850            class regular : virtual public block::channel { 
     51                friend class file::temp; 
     52 
    4953              public: 
    5054 
     
    107111                 * @param mode defines mode to open file, @see file::regular::openModeEnum 
    108112                 */ 
    109                 virtual void open(const dodoString &path, 
    110                                   short            mode); 
     113                void open(const dodoString &path, 
     114                          short            mode); 
    111115 
    112116                /** 
     
    138142 
    139143                /** 
     144                 * @return successfully read bytes 
    140145                 * @param data defines buffer that will be filled 
    141                  * @note not more then blockSize(including null) 
    142                  * if block is true read offset is calculated as pos*blockSize otherwise offset it taken pos bytes from the beginning 
     146                 * @note not more then bs(including null) 
    143147                 */ 
    144                 virtual void _read(char * const data) const; 
     148                virtual unsigned long _read(char * const data) const; 
    145149 
    146150                /** 
    147                  * read from stream null- or newline- terminated string 
     151                 * read null- or newline- terminated string 
     152                 * @return successfully read bytes 
    148153                 * @param data defines buffer that will be filled 
    149                  * @note not more then blockSize(including null) 
    150                  * if block is true read offset is calculated as pos*'# of \n terminated strings' otherwise offset it taken pos bytes from the beginning 
     154                 * @note not more then bs(including null) 
    151155                 */ 
    152156                virtual unsigned long _readString(char * const data) const; 
    153157 
    154158                /** 
     159                 * @return successfully written bytes 
    155160                 * @param data defines data that will be written 
    156                  * @note if block is true write offset is calculated as pos*blockSize otherwise offset it taken pos bytes from the beginning 
    157161                 */ 
    158                 virtual void _write(const char * const data) const; 
     162                virtual unsigned long _write(const char * const data) const; 
    159163 
    160164                /** 
    161                  * write to stream null- terminated string 
     165                 * write null- terminated string 
     166                 * @return successfully written bytes 
    162167                 * @param data defines data that will be written 
    163168                 * @note write only to the end of the file(append) 
    164169                 */ 
    165                 virtual void _writeString(const char * const data) const; 
     170                virtual unsigned long _writeString(const char * const data) const; 
    166171 
    167172              private: 
  • src/include/libdodo/ioFileRegularEx.h

    r1386 r1389  
    4343            enum regularExR { 
    4444                REGULAREX_WRONGFILENAME, 
    45                 REGULAREX_FILEISSHORTERTHANGIVENPOSITION, 
    4645                REGULAREX_NOTOPENED 
    4746            }; 
     
    5150             */ 
    5251#define IOFILEREGULAREX_WRONGFILENAME_STR                  "Wrong filename" 
    53 #define IOFILEREGULAREX_FILEISSHORTERTHANGIVENPOSITION_STR "Access data out of bounds" 
    5452#define IOFILEREGULAREX_NOTOPENED_STR                       "File not opened" 
    5553 
     
    6462                REGULAREX__READ, 
    6563                REGULAREX__WRITE, 
    66                 REGULAREX__READSTREAM, 
    67                 REGULAREX__WRITESTREAM, 
     64                REGULAREX__READSTRING, 
     65                REGULAREX__WRITESTRING, 
    6866                REGULAREX_FLUSH, 
    6967                REGULAREX_INDESCRIPTOR, 
  • src/include/libdodo/ioFileTemp.h

    r1386 r1389  
    3535#include <libdodo/ioChannel.h> 
    3636#include <libdodo/ioBlockChannel.h> 
     37#include <libdodo/ioFileRegular.h> 
    3738 
    3839namespace dodo { 
     
    4445             * @class temp 
    4546             * @brief provides I/O manipulations with temporary file 
    46              * @note  if block is false then read/write position is amount of bytes from the beginning, if true then: 
    47              * writeString, writeString write only to the end of the file(append) 
    48              * write offset for write, write is calculated as pos*blockSize 
    49              * read offset for read, read is calculated as pos*blockSize 
    50              * read offset for readString, readString is calculated as pos*'# of \n terminated strings' 
    5147             */ 
    52             class temp : virtual public block::channel { 
     48            class temp : virtual public block::channel, 
     49                         public regular { 
    5350              public: 
    5451 
     
    5956                enum operationEnum { 
    6057                    OPERATION_OPEN = 128, 
    61                     OPERATION_CLOSE 
    6258                }; 
    6359#endif 
     
    8480                /** 
    8581                 * clone file object 
    86                  * @param fd defines object to clone 
     82                 * @param file defines object to clone 
    8783                 * @note xexec object is not copied 
    8884                 */ 
    89                 void clone(const temp &fd); 
     85                void clone(const temp &file); 
     86 
    9087 
    9188                /** 
    9289                 * open file 
    9390                 */ 
    94                 virtual void open(); 
    95  
    96                 /** 
    97                  * close file 
    98                  */ 
    99                 virtual void close(); 
    100  
    101                 /** 
    102                  * flush output 
    103                  */ 
    104                 virtual void flush() const; 
    105  
    106                 /** 
    107                  * erase node on position 
    108                  */ 
    109                 virtual void erase(); 
    110  
    111                 bool block;         ///<  if block is false then read/write position is amount of bytes from the beginning, if true then read/write position calculated by defined rules[false by default] 
    112                 bool append;        ///< append to the end[false by default] 
    113  
    114                 bool overwrite;     ///< if true block will be overwritten; for regular and temp files only[false by default] 
    115  
    116               protected: 
    117  
    118                 /** 
    119                  * @return descriptor of the input stream 
    120                  */ 
    121                 virtual int inDescriptor() const; 
    122  
    123                 /** 
    124                  * @return descriptor of the output stream 
    125                  */ 
    126                 virtual int outDescriptor() const; 
    127  
    128                 /** 
    129                  * @param data defines buffer that will be filled 
    130                  * @note not more then blockSize(including null) 
    131                  * if block is true read offset is calculated as pos*blockSize otherwise offset it taken pos bytes from the beginning 
    132                  */ 
    133                 virtual void _read(char * const data) const; 
    134  
    135                 /** 
    136                  * read from stream null- or newline- terminated string 
    137                  * @param data defines buffer that will be filled 
    138                  * @note not more then blockSize(including null) 
    139                  * if block is true read offset is calculated as pos*'# of \n terminated strings' otherwise offset it taken pos bytes from the beginning 
    140                  */ 
    141                 virtual unsigned long _readString(char * const data) const; 
    142  
    143                 /** 
    144                  * @param data defines data that will be written 
    145                  * @note if block is true write offset is calculated as pos*blockSize otherwise offset it taken pos bytes from the beginning 
    146                  */ 
    147                 virtual void _write(const char * const data) const; 
    148  
    149                 /** 
    150                  * write to stream null- terminated string 
    151                  * @param data defines data that will be written 
    152                  * @note write only to the end of the file(append) 
    153                  */ 
    154                 virtual void _writeString(const char * const data) const; 
    155  
    156               private: 
    157  
    158                 __file__ *handle; ///< file handle 
     91                void open(); 
    15992            }; 
    16093        }; 
  • src/include/libdodo/ioFileTempEx.h

    r1386 r1389  
    6464                TEMPEX__READ, 
    6565                TEMPEX__WRITE, 
    66                 TEMPEX__READSTREAM, 
    67                 TEMPEX__WRITESTREAM, 
     66                TEMPEX__READSTRING, 
     67                TEMPEX__WRITESTRING, 
    6868                TEMPEX_FLUSH, 
    6969                TEMPEX_INDESCRIPTOR, 
  • src/include/libdodo/ioMemory.h

    r1386 r1389  
    132132 
    133133            /** 
     134             * @return successfully read bytes 
    134135             * @param data defines buffer that will be filled 
    135              * @note not more then blockSize(including null) 
    136              * if block is true read offset is calculated as pos*blockSize otherwise offset it taken pos bytes from the beginning 
     136             * @note not more then bs(including null) 
    137137             */ 
    138             virtual void _read(char * const data) const; 
     138            virtual unsigned long _read(char * const data) const; 
    139139 
    140140            /** 
    141              * read from stream null- or newline- terminated memory 
     141             * read null- or newline- terminated memory 
     142             * @return successfully read bytes 
    142143             * @param data defines buffer that will be filled 
    143              * @note not more then blockSize(including null) 
    144              * if block is true read offset is calculated as pos*'# of \n terminated memorys' otherwise offset it taken pos bytes from the beginning 
     144             * @note not more then bs(including null) 
    145145             */ 
    146146            virtual unsigned long _readString(char * const data) const; 
    147147 
    148148            /** 
     149             * @return successfully written bytes 
    149150             * @param data defines data that will be written 
    150              * @note if block is true write offset is calculated as pos*blockSize otherwise offset it taken pos bytes from the beginning 
    151151             */ 
    152             virtual void _write(const char * const data) const; 
     152            virtual unsigned long _write(const char * const data) const; 
    153153 
    154154            /** 
    155              * write to stream null- terminated memory 
     155             * write null- terminated memory 
     156             * @return successfully written bytes 
    156157             * @param data defines data that will be written 
    157158             * @note write only to the end of the file(append) 
    158159             */ 
    159             virtual void _writeString(const char * const data) const; 
     160            virtual unsigned long _writeString(const char * const data) const; 
    160161 
    161162          protected: 
  • src/include/libdodo/ioMemoryEx.h

    r1386 r1389  
    6363            MEMORYEX__READ, 
    6464            MEMORYEX__WRITE, 
    65             MEMORYEX__WRITESTREAM, 
     65            MEMORYEX__WRITESTRING, 
    6666            MEMORYEX_ERASE, 
    6767            MEMORYEX_INDESCRIPTOR, 
  • src/include/libdodo/ioNetworkExchange.h

    r1386 r1389  
    4848             * @class exchange 
    4949             * @brief provides communication interface[send/receive data] 
    50              * @note readString*: if length of read data is blockSize, data will contain exact blockSize, no null will be set in the end this is specific only for network sessions 
    51              * writesStream* put extra null in the end of the string 
    5250             */ 
    5351            class exchange : public connection, 
     
    169167 
    170168                /** 
     169                 * @return successfully read bytes 
    171170                 * @param data defines buffer that will be filled 
    172                  * @note not more then blockSize(including null) 
    173                  */ 
    174                 virtual void _read(char * const data) const; 
    175  
    176                 /** 
    177                  * read from stream null or newline terminated string 
     171                 * @note not more then bs(including null) 
     172                 */ 
     173                virtual unsigned long _read(char * const data) const; 
     174 
     175                /** 
     176                 * read null- or newline- terminated string 
     177                 * @return successfully read bytes 
    178178                 * @param data defines buffer that will be filled 
    179                  * @note not more then blockSize(including null) 
     179                 * @note not more then bs(including null) 
    180180                 */ 
    181181                virtual unsigned long _readString(char * const data) const; 
    182182 
    183183                /** 
     184                 * @return successfully written bytes 
    184185                 * @param data defines data that will be written 
    185186                 */ 
    186                 virtual void _write(const char * const data) const; 
    187  
    188                 /** 
    189                  * write to stream null terminated string 
     187                virtual unsigned long _write(const char * const data) const; 
     188 
     189                /** 
     190                 * write null- terminated string 
     191                 * @return successfully written bytes 
    190192                 * @param data defines data that will be written 
    191193                 * @note puts extra null in the end of the string 
    192194                 */ 
    193                 virtual void _writeString(const char * const data) const; 
     195                virtual unsigned long _writeString(const char * const data) const; 
    194196            }; 
    195197        }; 
  • src/include/libdodo/ioNetworkExchangeEx.h

    r1386 r1389  
    5656                EXCHANGEEX__WRITE, 
    5757                EXCHANGEEX__READ, 
    58                 EXCHANGEEX__READSTREAM, 
     58                EXCHANGEEX__READSTRING, 
    5959            }; 
    6060        }; 
  • src/include/libdodo/ioNetworkSslExchange.h

    r1386 r1389  
    153153 
    154154                    /** 
     155                     * @return successfully read bytes 
    155156                     * @param data defines buffer that will be filled 
    156                      * @note not more then blockSize(including null) 
     157                     * @note not more then bs(including null) 
    157158                     */ 
    158                     virtual void _read(char * const data) const; 
     159                    virtual unsigned long _read(char * const data) const; 
    159160 
    160161                    /** 
    161                      * read from stream null or newline terminated string 
     162                     * read null- or newline- terminated string 
     163                     * @return successfully read bytes 
    162164                     * @param data defines buffer that will be filled 
    163                      * @note not more then blockSize(including null) 
     165                     * @note not more then bs(including null) 
    164166                     */ 
    165167                    virtual unsigned long _readString(char * const data) const; 
    166168 
    167169                    /** 
     170                     * @return successfully written bytes 
    168171                     * @param data defines data that will be written 
    169172                     */ 
    170                     virtual void _write(const char * const data) const; 
     173                    virtual unsigned long _write(const char * const data) const; 
    171174                }; 
    172175            }; 
  • src/include/libdodo/ioNetworkSslExchangeEx.h

    r1386 r1389  
    5757                    EXCHANGEEX__WRITE, 
    5858                    EXCHANGEEX__READ, 
    59                     EXCHANGEEX__READSTREAM, 
     59                    EXCHANGEEX__READSTRING, 
    6060                    EXCHANGEEX__CLOSE, 
    6161                }; 
  • src/include/libdodo/ioPipe.h

    r1386 r1389  
    128128 
    129129            /** 
     130             * @return successfully read bytes 
    130131             * @param data defines buffer that will be filled 
    131              * @note not more then blockSize(including null) 
     132             * @note not more then bs(including null) 
    132133             */ 
    133             virtual void _read(char * const data) const; 
     134            virtual unsigned long _read(char * const data) const; 
    134135 
    135136            /** 
    136              * read from stream null or newline terminated string 
     137             * read null- or newline- terminated string 
     138             * @return successfully read bytes 
    137139             * @param data defines buffer that will be filled 
    138              * @note not more then blockSize(including null) 
     140             * @note not more then bs(including null) 
    139141             */ 
    140142            virtual unsigned long _readString(char * const data) const; 
    141143 
    142144            /** 
     145             * @return successfully written bytes 
    143146             * @param data defines data that will be written 
    144147             */ 
    145             virtual void _write(const char * const data) const; 
     148            virtual unsigned long _write(const char * const data) const; 
    146149 
    147150            /** 
    148              * write to stream null terminated string 
     151             * write null- terminated string 
     152             * @return successfully written bytes 
    149153             * @param data defines data that will be written 
    150154             * @note puts extra newline to the end of the string 
    151155             */ 
    152             virtual void _writeString(const char * const data) const; 
     156            virtual unsigned long _writeString(const char * const data) const; 
    153157 
    154158            __file__ *in;       ///< input stream descriptor 
  • src/include/libdodo/ioPipeEx.h

    r1386 r1389  
    5959            PIPEEX__READ, 
    6060            PIPEEX__WRITE, 
    61             PIPEEX__READSTREAM, 
    62             PIPEEX__WRITESTREAM, 
     61            PIPEEX__READSTRING, 
     62            PIPEEX__WRITESTRING, 
    6363            PIPEEX_FLUSH, 
    6464            PIPEEX_PEERINFO, 
  • src/include/libdodo/ioStdio.h

    r1386 r1389  
    7878 
    7979            /** 
    80              * write to stream null terminated string 
     80             * write null- terminated string 
     81             * @return successfully written bytes 
    8182             * @param data defines data that will be written 
    8283             */ 
    83             virtual void _writeString(const char * const data) const; 
     84            virtual unsigned long _writeString(const char * const data) const; 
    8485 
    8586          private: 
  • src/include/libdodo/ioStreamChannel.h

    r1386 r1389  
    5959                /** 
    6060                 * @return read data 
    61                  * @note not more then blockSize 
     61                 * @note not more then bs 
    6262                 */ 
    6363                virtual dodoString read() const; 
    6464 
    6565                /** 
     66                 * @return successfully written bytes 
    6667                 * @param data defines data that will be written 
    67                  * @note not more then blockSize 
     68                 * @note not more then bs 
    6869                 */ 
    69                 virtual void write(const dodoString &data) const; 
     70                virtual unsigned long write(const dodoString &data) const; 
    7071 
    7172                /** 
    72                  * read from stream null or newline terminated string 
     73                 * read null- or newline- terminated string 
    7374                 * @return read data 
    74                  * @note not more then blockSize 
     75                 * @note not more then bs 
    7576                 */ 
    7677                virtual dodoString readString() const; 
    7778 
    7879                /** 
    79                  * write to stream null terminated string 
     80                 * write null- terminated string 
     81                 * @return successfully written bytes 
    8082                 * @param data defines data that will be written 
    81                  * @note not more then blockSize 
     83                 * @note not more then bs 
    8284                 */ 
    83                 virtual void writeString(const dodoString &data) const; 
     85                virtual unsigned long writeString(const dodoString &data) const; 
    8486            }; 
    8587        }; 
  • src/src/cgiDialogue.cc

    r1386 r1389  
    287287    printHeaders(); 
    288288 
    289     unsigned long blockSizeOrig = io.blockSize;; 
    290  
    291     io.blockSize = buf.size(); 
     289    unsigned long bsOrig = io.bs;; 
     290 
     291    io.bs = buf.size(); 
    292292    io.write(buf); 
    293293 
    294     io.blockSize = blockSizeOrig; 
     294    io.bs = bsOrig; 
    295295} 
    296296 
     
    596596dialogue::makeContent(unsigned long postSize) 
    597597{ 
    598     unsigned long blockSize = tools::string::stringToUL(ENVIRONMENT[ENVIRONMENT_CONTENTLENGTH]); 
    599     unsigned long blockSizeOrig; 
    600  
    601     if (blockSize <= 0) 
     598    unsigned long bs = tools::string::stringToUL(ENVIRONMENT[ENVIRONMENT_CONTENTLENGTH]); 
     599    unsigned long bsOrig; 
     600 
     601    if (bs <= 0) 
    602602        return ; 
    603603 
    604     if (blockSize > postSize) 
    605         blockSize = postSize; 
    606  
    607     blockSizeOrig = io.blockSize; 
    608     io.blockSize = blockSize; 
     604    if (bs > postSize) 
     605        bs = postSize; 
     606 
     607    bsOrig = io.bs; 
     608    io.bs = bs; 
    609609 
    610610    content = io.read(); 
    611611 
    612     io.blockSize = blockSizeOrig; 
     612    io.bs = bsOrig; 
    613613} 
    614614 
  • src/src/cgiFastExchange.cc

    r1386 r1389  
    105105//------------------------------------------------------------------- 
    106106 
    107 void 
    108 exchange::_read(char * const a_data) const 
     107unsigned long 
     108exchange::_read(char * const data) const 
    109109{ 
    110     FCGX_GetStr(a_data, blockSize, request->request->in); 
     110    return FCGX_GetStr(data, bs, request->request->in); 
    111111} 
    112112 
    113113//------------------------------------------------------------------- 
    114114 
    115 void 
    116 exchange::_write(const char *const buf) const 
     115unsigned long 
     116exchange::_write(const char *const data) const 
    117117{ 
    118     if (FCGX_PutStr(buf, blockSize, request->request->out) == -1) 
     118    long n; 
     119 
     120    if ((n = FCGX_PutStr(data, bs, request->request->out)) == -1) 
    119121        throw exception::basic(exception::MODULE_CGIFASTEXCHANGE, FASTEXCHANGEEX__WRITE, exception::ERRNO_LIBDODO, FASTEXCHANGEEX_FAILEDTOPRINTSTRING, CGIFASTEXCHANGEEX_FAILEDTOPRINTSTRING_STR, __LINE__, __FILE__); 
     122 
     123    return n; 
    120124} 
    121125 
    122126//------------------------------------------------------------------- 
    123127 
    124 void 
     128unsigned long 
    125129exchange::_writeString(const char * const data) const 
    126130{ 
    127     unsigned long _blockSize = blockSize; 
     131    long n; 
    128132 
    129     try { 
    130         blockSize = strnlen(data, blockSize); 
     133    if ((n = FCGX_PutStr(data, strnlen(data, bs), request->request->out)) == -1) 
     134        throw exception::basic(exception::MODULE_CGIFASTEXCHANGE, FASTEXCHANGEEX__WRITESTRING, exception::ERRNO_LIBDODO, FASTEXCHANGEEX_FAILEDTOPRINTSTRING, CGIFASTEXCHANGEEX_FAILEDTOPRINTSTRING_STR, __LINE__, __FILE__); 
    131135 
    132         _write(data); 
    133  
    134         blockSize = _blockSize; 
    135     } catch (...) { 
    136         blockSize = _blockSize; 
    137  
    138         throw; 
    139     } 
     136    return n; 
    140137} 
    141138 
     
    145142exchange::_readString(char * const data) const 
    146143{ 
    147     unsigned long _blockSize = blockSize++; 
    148  
    149     _read(data); 
    150  
    151     blockSize = _blockSize; 
    152  
    153     return strlen(data); 
     144    return FCGX_GetStr(data, bs+1, request->request->in); 
    154145} 
    155146#endif 
  • src/src/ioBlockChannel.cc

    r1386 r1389  
    4242channel::channel(short protection) : io::channel(protection), 
    4343                                     pos(0), 
    44                                      block(false), 
    4544                                     append(false) 
    4645{ 
     
    6059    pc::sync::stack pg(keeper); 
    6160 
    62     dodoString a_str; 
     61    dodoString data; 
     62    unsigned long n; 
    6363 
    6464#ifndef IO_WO_XEXEC 
    6565    performPreExec(OPERATION_READ); 
    66  
    67     collectedData.buffer.reserve(blockSize); 
    68 #endif 
    69  
    70     a_str.assign(blockSize, '\0'); 
    71  
    72     try { 
    73         _read((char *)a_str.data()); 
    74     } catch (...) { 
    75         a_str.clear(); 
     66#endif 
     67 
     68    data.assign(bs, '\0'); 
     69 
     70    try { 
     71        n = _read((char *)data.data()); 
     72    } catch (...) { 
     73        data.clear(); 
    7674 
    7775#ifndef IO_WO_XEXEC 
     
    8381 
    8482#ifndef IO_WO_XEXEC 
    85     collectedData.buffer = a_str; 
     83    collectedData.buffer = data; 
    8684 
    8785    performPostExec(OPERATION_READ); 
    8886 
    89     a_str = collectedData.buffer; 
     87    data = collectedData.buffer; 
    9088 
    9189    collectedData.buffer.clear(); 
     
    9391#endif 
    9492 
    95     pos += blockSize; 
    96  
    97     return a_str; 
     93    pos += n; 
     94 
     95    return data; 
    9896} 
    9997 
     
    105103    pc::sync::stack pg(keeper); 
    106104 
    107     dodoString a_str; 
     105    dodoString data; 
     106    unsigned long n; 
    108107 
    109108#ifndef IO_WO_XEXEC 
     
    111110#endif 
    112111 
    113     a_str.assign(blockSize, '\0'); 
    114     unsigned long n = 0; 
    115  
    116     try { 
    117         n = _readString((char *)a_str.data()); 
    118         a_str.resize(n); 
    119     } catch (...) { 
    120         a_str.clear(); 
    121  
    122         throw; 
    123     } 
    124  
    125 #ifndef IO_WO_XEXEC 
    126     if (n > 0) 
    127         collectedData.buffer = a_str; 
    128     else 
     112    data.assign(bs, '\0'); 
     113 
     114    try { 
     115        n = _readString((char *)data.data()); 
     116        data.resize(n); 
     117    } catch (...) { 
     118        data.clear(); 
     119 
     120        throw; 
     121    } 
     122 
     123#ifndef IO_WO_XEXEC 
     124    collectedData.buffer = data; 
     125 
     126    performPostExec(OPERATION_READSTRING); 
     127 
     128    data = collectedData.buffer; 
     129 
     130    collectedData.buffer.clear(); 
     131#endif 
     132 
     133    pos += n; 
     134 
     135    return data; 
     136} 
     137 
     138//------------------------------------------------------------------- 
     139 
     140unsigned long 
     141channel::write(const dodoString &data) const 
     142{ 
     143    pc::sync::stack pg(keeper); 
     144 
     145    unsigned long n; 
     146 
     147#ifndef IO_WO_XEXEC 
     148    collectedData.buffer.assign(data, 0, bs); 
     149 
     150    performPreExec(OPERATION_WRITE); 
     151 
     152    try { 
     153        n = _write(collectedData.buffer.data()); 
     154    } catch (...) { 
    129155        collectedData.buffer.clear(); 
    130156 
    131     performPostExec(OPERATION_READSTRING); 
    132  
    133     a_str = collectedData.buffer; 
    134  
    135     collectedData.buffer.clear(); 
     157        throw; 
     158    } 
    136159#else 
    137     if (n == 0) 
    138         a_str.clear(); 
    139 #endif 
    140  
    141     pos += n; 
    142  
    143     return a_str; 
    144 } 
    145  
    146 //------------------------------------------------------------------- 
    147  
    148 void 
    149 channel::write(const dodoString &a_data) const 
    150 { 
    151     pc::sync::stack pg(keeper); 
    152  
    153 #ifndef IO_WO_XEXEC 
    154     collectedData.buffer.assign(a_data, 0, blockSize); 
    155  
    156     performPreExec(OPERATION_WRITE); 
    157  
    158     try { 
    159         _write(collectedData.buffer.data()); 
     160    n = _write(data.data()); 
     161#endif 
     162 
     163#ifndef IO_WO_XEXEC 
     164    performPostExec(OPERATION_WRITE); 
     165 
     166    collectedData.buffer.clear(); 
     167#endif 
     168 
     169    pos += n; 
     170 
     171    return n; 
     172} 
     173 
     174//------------------------------------------------------------------- 
     175 
     176unsigned long 
     177channel::writeString(const dodoString &data) const 
     178{ 
     179    pc::sync::stack pg(keeper); 
     180 
     181    unsigned long n; 
     182 
     183#ifndef IO_WO_XEXEC 
     184    collectedData.buffer = data; 
     185 
     186    performPreExec(OPERATION_WRITESTRING); 
     187 
     188    try { 
     189        n = _writeString(collectedData.buffer.data()); 
    160190    } catch (...) { 
    161191        collectedData.buffer.clear(); 
     
    163193        throw; 
    164194    } 
     195 
     196    pos += n; 
    165197#else 
    166     _write(a_data.data()); 
    167 #endif 
    168  
    169 #ifndef IO_WO_XEXEC 
    170     performPostExec(OPERATION_WRITE); 
    171  
    172     collectedData.buffer.clear(); 
    173 #endif 
    174  
    175     pos += blockSize; 
    176 } 
    177  
    178 //------------------------------------------------------------------- 
    179  
    180 void 
    181 channel::writeString(const dodoString &a_data) const 
    182 { 
    183     pc::sync::stack pg(keeper); 
    184  
    185 #ifndef IO_WO_XEXEC 
    186     collectedData.buffer = a_data; 
    187  
    188     performPreExec(OPERATION_WRITESTRING); 
    189  
    190     try { 
    191         _writeString(collectedData.buffer.data()); 
    192     } catch (...) { 
    193         collectedData.buffer.clear(); 
    194  
    195         throw; 
    196     } 
    197  
    198     pos += collectedData.buffer.size(); 
    199 #else 
    200     _writeString(a_data.data()); 
    201  
    202     pos += a_data.size(); 
     198    n = _writeString(data.data()); 
     199 
     200    pos += n; 
    203201#endif 
    204202 
     
    208206    collectedData.buffer.clear(); 
    209207#endif 
    210 } 
    211  
    212 //------------------------------------------------------------------- 
    213  
     208 
     209    return n; 
     210} 
     211 
     212//------------------------------------------------------------------- 
     213 
  • src/src/ioChannel.cc

    r1386 r1389  
    4848//------------------------------------------------------------------- 
    4949 
    50 channel::channel(short protection) : blockSize(IO_BLOCKSIZE), 
     50channel::channel(short protection) : bs(IO_BLOCKSIZE), 
    5151                                     keeper(NULL), 
    5252                                     protection(protection) 
  • src/src/ioFileFifo.cc

    r1386 r1389  
    161161#endif 
    162162 
    163     blockSize = fd.blockSize; 
     163    bs = fd.bs; 
    164164 
    165165    if (fd.handle->file != NULL) { 
     
    254254    path = fd.path; 
    255255    mode = fd.mode; 
    256     blockSize = fd.blockSize; 
     256    bs = fd.bs; 
    257257 
    258258    if (fd.handle->file != NULL) { 
     
    438438//------------------------------------------------------------------- 
    439439 
    440 void 
    441 fifo::_read(char * const a_data) const 
     440unsigned long 
     441fifo::_read(char * const data) const 
    442442{ 
    443443    if (handle->file == NULL) 
    444444        throw exception::basic(exception::MODULE_IOFILEFIFO, FIFOEX__READ, exception::ERRNO_LIBDODO, FIFOEX_NOTOPENED, IOFILEFIFOEX_NOTOPENED_STR, __LINE__, __FILE__, path); 
    445445 
    446     char *data = a_data; 
    447  
    448     unsigned long batch = blockSize, n; 
    449  
    450     while (batch > 0) { 
     446    char *s = data; 
     447 
     448    unsigned long batch = bs, n; 
     449 
     450    while (batch != 0) { 
    451451        while (true) { 
    452             if ((n = fread(data, 1, batch, handle->file)) == 0) { 
     452            if ((n = fread(s, 1, batch, handle->file)) == 0) { 
    453453                if (feof(handle->file) != 0 || errno == EAGAIN) 
    454                     break; 
     454                    return bs - batch; 
    455455 
    456456                if (errno == EINTR) 
     
    465465 
    466466        batch -= n; 
    467         data += n; 
    468     } 
    469 } 
    470  
    471 //------------------------------------------------------------------- 
    472  
    473 void 
    474 fifo::_write(const char *const a_data) const 
     467        s += n; 
     468    } 
     469 
     470    return bs - batch; 
     471} 
     472 
     473//------------------------------------------------------------------- 
     474 
     475unsigned long 
     476fifo::_write(const char *const data) const 
    475477{ 
    476478    if (handle->file == NULL) 
    477479        throw exception::basic(exception::MODULE_IOFILEFIFO, FIFOEX__WRITE, exception::ERRNO_LIBDODO, FIFOEX_NOTOPENED, IOFILEFIFOEX_NOTOPENED_STR, __LINE__, __FILE__, path); 
    478480 
    479     const char *data = a_data; 
    480  
    481     unsigned long batch = blockSize, n; 
    482  
    483     while (batch > 0) { 
     481    const char *s = data; 
     482 
     483    unsigned long batch = bs, n; 
     484 
     485    while (batch != 0) { 
    484486        while (true) { 
    485             if ((n = fwrite(data, 1, batch, handle->file)) == 0) { 
     487            if ((n = fwrite(s, 1, batch, handle->file)) == 0) { 
    486488                if (errno == EINTR) 
    487489                    continue; 
    488490 
    489491                if (errno == EAGAIN) 
    490                     break; 
     492                    return bs - batch; 
    491493 
    492494                if (ferror(handle->file) != 0) 
     
    498500 
    499501        batch -= n; 
    500         data += n; 
    501     } 
     502        s += n; 
     503    } 
     504 
     505    return bs; 
    502506} 
    503507 
     
    519523 
    520524unsigned long 
    521 fifo::_readString(char * const a_data) const 
    522 { 
    523     if (handle->file == NULL) 
    524         throw exception::basic(exception::MODULE_IOFILEFIFO, FIFOEX__READSTREAM, exception::ERRNO_LIBDODO, FIFOEX_NOTOPENED, IOFILEFIFOEX_NOTOPENED_STR, __LINE__, __FILE__, path); 
    525  
    526     unsigned long readSize = blockSize + 1; 
    527  
    528     memset(a_data, '\0', readSize); 
     525fifo::_readString(char * const data) const 
     526{ 
     527    if (handle->file == NULL) 
     528        throw exception::basic(exception::MODULE_IOFILEFIFO, FIFOEX__READSTRING, exception::ERRNO_LIBDODO, FIFOEX_NOTOPENED, IOFILEFIFOEX_NOTOPENED_STR, __LINE__, __FILE__, path); 
     529 
     530    unsigned long readSize = bs + 1; 
    529531 
    530532    while (true) { 
    531         if (fgets(a_data, readSize, handle->file) == NULL) { 
     533        if (fgets(data, readSize, handle->file) == NULL) { 
    532534            if (errno == EINTR) 
    533535                continue; 
    534536 
    535537            if (errno == EAGAIN) 
    536                 break; 
     538                return 0; 
    537539 
    538540            if (ferror(handle->file) != 0) 
    539                 throw exception::basic(exception::MODULE_IOFILEFIFO, FIFOEX__READSTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
     541                throw exception::basic(exception::MODULE_IOFILEFIFO, FIFOEX__READSTRING, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    540542        } 
    541543 
     
    543545    } 
    544546 
    545     return strlen(a_data); 
    546 } 
    547  
    548 //------------------------------------------------------------------- 
    549  
    550 void 
     547    return strlen(data); 
     548} 
     549 
     550//------------------------------------------------------------------- 
     551 
     552unsigned long 
    551553fifo::_writeString(const char *const data) const 
    552554{ 
    553     unsigned long _blockSize = blockSize; 
     555    unsigned long _bs = bs; 
     556    unsigned long written; 
    554557 
    555558    try { 
    556         blockSize = strnlen(data, blockSize); 
    557  
    558         _write(data); 
    559  
    560         if (data[blockSize - 1] != '\n') { 
     559        bs = strnlen(data, bs); 
     560 
     561        written = _write(data); 
     562 
     563        if (data[bs - 1] != '\n') { 
    561564            while (true) { 
    562565                if (fputc('\n', handle->file) == EOF) { 
     
    568571 
    569572                    if (ferror(handle->file) != 0) 
    570                         throw exception::basic(exception::MODULE_IOFILEFIFO, FIFOEX__WRITESTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
     573                        throw exception::basic(exception::MODULE_IOFILEFIFO, FIFOEX__WRITESTRING, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    571574                } 
    572575 
     
    575578        } 
    576579 
    577         blockSize = _blockSize; 
     580        bs = _bs; 
    578581    } catch (...) { 
    579         blockSize = _blockSize; 
     582        bs = _bs; 
    580583 
    581584        throw; 
    582585    } 
    583 } 
    584  
    585 //------------------------------------------------------------------- 
     586 
     587    return written; 
     588} 
     589 
     590//------------------------------------------------------------------- 
  • src/src/ioFileRegular.cc

    r1386 r1389  
    8484                throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX_REGULAR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 
    8585            } 
    86         } else 
     86        } else { 
    8787            exists = true; 
     88        } 
    8889 
    8990        if (exists && !S_ISREG(st.st_mode) && !S_ISBLK(st.st_mode)) { 
     
    144145#endif 
    145146 
    146     block = fd.block; 
    147147    append = fd.append; 
    148148    pos = fd.pos; 
    149     blockSize = fd.blockSize; 
     149    bs = fd.bs; 
    150150 
    151151    if (fd.handle->file !=  NULL) { 
     
    241241    mode = fd.mode; 
    242242    pos = fd.pos; 
    243     block = fd.block; 
    244243    append = fd.append; 
    245     blockSize = fd.blockSize; 
     244    bs = fd.bs; 
    246245 
    247246    if (fd.handle->file !=  NULL) { 
     
    371370//------------------------------------------------------------------- 
    372371 
    373 void 
    374 regular::_read(char * const a_data) const 
     372unsigned long 
     373regular::_read(char * const data) const 
    375374{ 
    376375    if (handle->file == NULL) 
    377376        throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__READ, exception::ERRNO_LIBDODO, REGULAREX_NOTOPENED, IOFILEREGULAREX_NOTOPENED_STR, __LINE__, __FILE__, path); 
    378  
    379     unsigned long pos = block ? this->pos * blockSize : this->pos; 
    380377 
    381378    if (fseek(handle->file, pos, SEEK_SET) == -1) 
    382379        throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__READ, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 
    383380 
    384     while (true) { 
    385         if (fread(a_data, blockSize, 1, handle->file) == 0) { 
    386             if (feof(handle->file) != 0 || errno == EAGAIN) 
    387                 break; 
    388  
    389             if (errno == EINTR) 
    390                 continue; 
    391  
    392             if (ferror(handle->file) != 0) 
    393                 throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__READ, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    394         } 
    395  
    396         break; 
    397     } 
    398 } 
    399  
    400 //------------------------------------------------------------------- 
    401  
    402 void 
    403 regular::_write(const char *const a_data) const 
     381    char *s = data; 
     382 
     383    unsigned long batch = bs, n; 
     384 
     385    while (batch != 0) { 
     386        while (true) { 
     387            if ((n = fread(s, 1, batch, handle->file)) == 0) { 
     388                if (feof(handle->file) != 0 || errno == EAGAIN) 
     389                    return bs - batch; 
     390 
     391                if (errno == EINTR) 
     392                    continue; 
     393 
     394                if (ferror(handle->file) != 0) 
     395                    throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__READ, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
     396            } 
     397 
     398            break; 
     399        } 
     400 
     401        batch -= n; 
     402        s += n; 
     403    } 
     404 
     405    return bs - batch; 
     406} 
     407 
     408//------------------------------------------------------------------- 
     409 
     410unsigned long 
     411regular::_write(const char *const data) const 
    404412{ 
    405413    if (handle->file == NULL) 
     
    410418            throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 
    411419    } else { 
    412         unsigned long pos = block ? this->pos * blockSize : this->pos; 
    413  
    414420        if (fseek(handle->file, pos, SEEK_SET) == -1) 
    415421            throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 
    416422    } 
    417423 
    418     while (true) { 
    419         if (fwrite(a_data, blockSize, 1, handle->file) == 0) { 
    420             if (errno == EINTR) 
    421                 continue; 
    422  
    423             if (errno == EAGAIN) 
    424                 break; 
    425  
    426             if (ferror(handle->file) != 0) 
    427                 throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    428         } 
    429  
    430         break; 
    431     } 
     424    const char *s = data; 
     425 
     426    unsigned long batch = bs, n; 
     427 
     428    while (batch != 0) { 
     429        while (true) { 
     430            if ((n = fwrite(s, 1, batch, handle->file)) == 0) { 
     431                if (errno == EINTR) 
     432                    continue; 
     433 
     434                if (errno == EAGAIN) 
     435                    break; 
     436 
     437                if (ferror(handle->file) != 0) 
     438                    throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
     439            } 
     440 
     441            break; 
     442        } 
     443 
     444        batch -= n; 
     445        s += n; 
     446    } 
     447 
     448    return bs; 
    432449} 
    433450 
     
    439456    pc::sync::stack pg(keeper); 
    440457 
    441     char *empty = new char[blockSize]; 
    442  
    443     memset(empty, 0, blockSize); 
     458    char *empty = new char[bs]; 
     459 
     460    memset(empty, 0, bs); 
    444461    try { 
    445462        _write(empty); 
     
    470487 
    471488unsigned long 
    472 regular::_readString(char * const a_data) const 
    473 { 
    474     if (handle->file == NULL) 
    475         throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__READSTREAM, exception::ERRNO_LIBDODO, REGULAREX_NOTOPENED, IOFILEREGULAREX_NOTOPENED_STR, __LINE__, __FILE__, path); 
    476  
    477     unsigned long readSize = blockSize + 1; 
    478  
    479     if (block) { 
    480         if (fseek(handle->file, 0, SEEK_SET) == -1) 
    481             throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__READSTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 
    482  
    483         for (unsigned long i = 0; i < pos; ++i) { 
    484             if (fgets(a_data, readSize, handle->file) == NULL) { 
    485                 switch (errno) { 
    486                     case EIO: 
    487                     case EINTR: 
    488                     case EBADF: 
    489                     case EOVERFLOW: 
    490                     case ENOMEM: 
    491                     case ENXIO: 
    492  
    493                         throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__READSTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 
    494                 } 
    495  
    496                 throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__READSTREAM, exception::ERRNO_LIBDODO, REGULAREX_FILEISSHORTERTHANGIVENPOSITION, IOFILEREGULAREX_FILEISSHORTERTHANGIVENPOSITION_STR, __LINE__, __FILE__, path); 
    497             } 
    498         } 
    499     } else if (fseek(handle->file, pos, SEEK_SET) == -1) 
    500         throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__READSTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 
    501  
    502     memset(a_data, '\0', readSize); 
     489regular::_readString(char * const data) const 
     490{ 
     491    if (handle->file == NULL) 
     492        throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__READSTRING, exception::ERRNO_LIBDODO, REGULAREX_NOTOPENED, IOFILEREGULAREX_NOTOPENED_STR, __LINE__, __FILE__, path); 
     493 
     494    unsigned long readSize = bs + 1; 
     495 
     496    if (fseek(handle->file, pos, SEEK_SET) == -1) 
     497        throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__READSTRING, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 
    503498 
    504499    while (true) { 
    505         if (fgets(a_data, readSize, handle->file) == NULL) { 
     500        if (fgets(data, readSize, handle->file) == NULL) { 
    506501            if (errno == EINTR) 
    507502                continue; 
     
    511506 
    512507            if (ferror(handle->file) != 0) 
    513                 throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__READSTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
     508                throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__READSTRING, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    514509        } 
    515510 
     
    517512    } 
    518513 
    519     return strlen(a_data); 
    520 } 
    521  
    522 //------------------------------------------------------------------- 
    523  
    524 void 
    525 regular::_writeString(const char *const a_data) const 
    526 { 
    527     if (handle->file == NULL) 
    528         throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__WRITESTREAM, exception::ERRNO_LIBDODO, REGULAREX_NOTOPENED, IOFILEREGULAREX_NOTOPENED_STR, __LINE__, __FILE__, path); 
     514    return strlen(data); 
     515} 
     516 
     517//------------------------------------------------------------------- 
     518 
     519unsigned long 
     520regular::_writeString(const char *const data) const 
     521{ 
     522    if (handle->file == NULL) 
     523        throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__WRITESTRING, exception::ERRNO_LIBDODO, REGULAREX_NOTOPENED, IOFILEREGULAREX_NOTOPENED_STR, __LINE__, __FILE__, path); 
    529524 
    530525    if (fseek(handle->file, 0, SEEK_END) == -1) 
    531         throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__WRITESTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 
    532  
    533     unsigned long _blockSize = strnlen(a_data, blockSize); 
    534  
    535     while (true) { 
    536         if (fwrite(a_data, _blockSize, 1, handle->file) == 0) { 
    537             if (errno == EINTR) 
    538                 continue; 
    539  
    540             if (ferror(handle->file) != 0) 
    541                 throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__WRITESTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    542         } 
    543  
    544         break; 
    545     } 
    546 } 
    547  
    548 //------------------------------------------------------------------- 
    549  
     526        throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__WRITESTRING, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 
     527 
     528    unsigned long _bs = bs; 
     529    unsigned long written; 
     530 
     531    try { 
     532        bs = strnlen(data, bs); 
     533 
     534        written = _write(data); 
     535 
     536        bs = _bs; 
     537    } catch (...) { 
     538        bs = _bs; 
     539 
     540        throw; 
     541    } 
     542 
     543    return written; 
     544} 
     545 
     546//------------------------------------------------------------------- 
     547 
  • src/src/ioFileTemp.cc

    r1386 r1389  
    4040#include <libdodo/ioFileTemp.h> 
    4141#include <libdodo/ioFileTempEx.h> 
     42#include <libdodo/ioFileRegular.h> 
    4243#include <libdodo/types.h> 
    4344#include <libdodo/ioChannel.h> 
     
    4950temp::temp(bool  open, 
    5051           short protection) : block::channel(protection), 
    51                                block(true), 
    52                                append(false), 
    53                                overwrite(false), 
    54                                handle(new io::__file__) 
     52                               regular(protection) 
    5553{ 
    5654#ifndef IO_WO_XEXEC 
     
    7169 
    7270temp::temp(const temp &fd) : block::channel(protection), 
    73                              block(fd.block), 
    74                              append(fd.append), 
    75                              overwrite(fd.overwrite), 
    76                              handle(new io::__file__) 
    77  
     71                             regular(protection) 
    7872{ 
    7973#ifndef IO_WO_XEXEC 
     
    8175#endif 
    8276 
     77    handle = new io::__file__; 
     78 
     79    append = fd.append; 
    8380    pos = fd.pos; 
    84     blockSize = fd.blockSize; 
     81    bs = fd.bs; 
    8582 
    8683    if (fd.handle->file != NULL) { 
     
    123120//------------------------------------------------------------------- 
    124121 
    125 int 
    126 temp::inDescriptor() const 
    127 { 
    128     pc::sync::stack pg(keeper); 
    129  
    130     if (handle->file == NULL) 
    131         throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX_INDESCRIPTOR, exception::ERRNO_LIBDODO, TEMPEX_NOTOPENED, IOFILETEMPEX_NOTOPENED_STR, __LINE__, __FILE__); 
    132  
    133     return fileno(handle->file); 
    134 } 
    135  
    136 //------------------------------------------------------------------- 
    137  
    138 int 
    139 temp::outDescriptor() const 
    140 { 
    141     pc::sync::stack pg(keeper); 
    142  
    143     if (handle->file == NULL) 
    144         throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX_OUTDESCRIPTOR, exception::ERRNO_LIBDODO, TEMPEX_NOTOPENED, IOFILETEMPEX_NOTOPENED_STR, __LINE__, __FILE__); 
    145  
    146     return fileno(handle->file); 
    147 } 
    148  
    149 //------------------------------------------------------------------- 
    150  
    151122void 
    152123temp::clone(const temp &fd) 
     
    161132    } 
    162133 
    163     overwrite = fd.overwrite; 
    164134    pos = fd.pos; 
    165     block = fd.block; 
    166135    append = fd.append; 
    167     blockSize = fd.blockSize; 
     136    bs = fd.bs; 
    168137 
    169138    if (fd.handle->file != NULL) { 
     
    183152            throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX_CLONE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    184153    } 
    185 } 
    186  
    187 //------------------------------------------------------------------- 
    188  
    189 void 
    190 temp::close() 
    191 { 
    192     pc::sync::stack pg(keeper); 
    193  
    194 #ifndef IO_WO_XEXEC 
    195     performPreExec(OPERATION_CLOSE); 
    196 #endif 
    197  
    198     if (handle->file != NULL) { 
    199         if (fclose(handle->file) != 0) 
    200             throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    201  
    202         handle->file = NULL; 
    203     } 
    204  
    205 #ifndef IO_WO_XEXEC 
    206     performPostExec(OPERATION_CLOSE); 
    207 #endif 
    208154} 
    209155 
     
    237183//------------------------------------------------------------------- 
    238184 
    239 void 
    240 temp::_read(char * const a_data) const 
    241 { 
    242     if (handle->file == NULL) 
    243         throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX__READ, exception::ERRNO_LIBDODO, TEMPEX_NOTOPENED, IOFILETEMPEX_NOTOPENED_STR, __LINE__, __FILE__); 
    244  
    245     unsigned long pos = block ? this->pos * blockSize : this->pos; 
    246  
    247     if (fseek(handle->file, pos * blockSize, SEEK_SET) == -1) 
    248         throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX__READ, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    249  
    250     while (true) { 
    251         if (fread(a_data, blockSize, 1, handle->file) == 0) { 
    252             if (feof(handle->file) != 0 || errno == EAGAIN) 
    253                 break; 
    254  
    255             if (errno == EINTR) 
    256                 continue; 
    257  
    258             if (ferror(handle->file) != 0) 
    259                 throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX__READ, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    260         } 
    261  
    262         break; 
    263     } 
    264 } 
    265  
    266 //------------------------------------------------------------------- 
    267  
    268 void 
    269 temp::_write(const char *const a_data) const 
    270 { 
    271     if (handle->file == NULL) 
    272         throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX__WRITE, exception::ERRNO_LIBDODO, TEMPEX_NOTOPENED, IOFILETEMPEX_NOTOPENED_STR, __LINE__, __FILE__); 
    273  
    274     if (append) { 
    275         if (fseek(handle->file, 0, SEEK_END) == -1) 
    276             throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    277     } else { 
    278         unsigned long pos = block ? this->pos * blockSize : this->pos; 
    279         if (!overwrite) { 
    280             if (fseek(handle->file, pos, SEEK_SET) == -1) 
    281                 throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    282  
    283             char *t_buf = new char[blockSize]; 
    284  
    285             size_t read = fread(t_buf, blockSize, 1, handle->file); 
    286  
    287             delete [] t_buf; 
    288  
    289             if (read != 0) 
    290                 throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX__WRITE, exception::ERRNO_LIBDODO, TEMPEX_CANNOTOVEWRITE, IOFILETEMPEX_CANNOTOVEWRITE_STR, __LINE__, __FILE__); 
    291         } 
    292  
    293         if (fseek(handle->file, pos, SEEK_SET) == -1) 
    294             throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    295     } 
    296  
    297     while (true) { 
    298         if (fwrite(a_data, blockSize, 1, handle->file) == 0) { 
    299             if (errno == EINTR) 
    300                 continue; 
    301  
    302             if (errno == EAGAIN) 
    303                 break; 
    304  
    305             if (ferror(handle->file) != 0) 
    306                 throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    307         } 
    308  
    309         break; 
    310     } 
    311 } 
    312  
    313 //------------------------------------------------------------------- 
    314  
    315 void 
    316 temp::erase() 
    317 { 
    318     pc::sync::stack pg(keeper); 
    319  
    320     char *empty = new char[blockSize]; 
    321  
    322     memset(empty, 0, blockSize); 
    323  
    324     bool _overwrite = overwrite; 
    325     overwrite = true; 
    326  
    327     try { 
    328         _write(empty); 
    329  
    330         overwrite = _overwrite; 
    331     } catch (...) { 
    332         overwrite = _overwrite; 
    333  
    334         delete [] empty; 
    335  
    336         throw; 
    337     } 
    338  
    339     delete [] empty; 
    340 } 
    341  
    342 //------------------------------------------------------------------- 
    343  
    344 void 
    345 temp::flush() const 
    346 { 
    347     pc::sync::stack pg(keeper); 
    348  
    349     if (handle->file == NULL) 
    350         throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX_FLUSH, exception::ERRNO_LIBDODO, TEMPEX_NOTOPENED, IOFILETEMPEX_NOTOPENED_STR, __LINE__, __FILE__); 
    351  
    352     if (fflush(handle->file) != 0) 
    353         throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX_FLUSH, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    354 } 
    355  
    356 //------------------------------------------------------------------- 
    357  
    358 unsigned long 
    359 temp::_readString(char * const a_data) const 
    360 { 
    361     if (handle->file == NULL) 
    362         throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX__READSTREAM, exception::ERRNO_LIBDODO, TEMPEX_NOTOPENED, IOFILETEMPEX_NOTOPENED_STR, __LINE__, __FILE__); 
    363  
    364     unsigned long readSize = blockSize + 1; 
    365  
    366     if (block) { 
    367         if (fseek(handle->file, 0, SEEK_SET) == -1) 
    368             throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX__READSTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    369  
    370         for (unsigned long i = 0; i < pos; ++i) { 
    371             if (fgets(a_data, readSize, handle->file) == NULL) { 
    372                 switch (errno) { 
    373                     case EIO: 
    374                     case EINTR: 
    375                     case EBADF: 
    376                     case EOVERFLOW: 
    377                     case ENOMEM: 
    378                     case ENXIO: 
    379  
    380                         throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX__READSTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    381                 } 
    382  
    383                 throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX__READSTREAM, exception::ERRNO_LIBDODO, TEMPEX_FILEISSHORTERTHANGIVENPOSITION, IOFILETEMPEX_FILEISSHORTERTHANGIVENPOSITION_STR, __LINE__, __FILE__); 
    384             } 
    385         } 
    386     } else if (fseek(handle->file, pos, SEEK_SET) == -1) 
    387         throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX__READSTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    388  
    389     memset(a_data, '\0', readSize); 
    390  
    391     while (true) { 
    392         if (fgets(a_data, readSize, handle->file) == NULL) { 
    393             if (errno == EINTR) 
    394                 continue; 
    395  
    396             if (errno == EAGAIN) 
    397                 break; 
    398  
    399             if (ferror(handle->file) != 0) 
    400                 throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX__READSTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    401         } 
    402  
    403         break; 
    404     } 
    405  
    406     return strlen(a_data); 
    407 } 
    408  
    409 //------------------------------------------------------------------- 
    410  
    411 void 
    412 temp::_writeString(const char *const a_data) const 
    413 { 
    414     if (handle->file == NULL) 
    415         throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX__WRITESTREAM, exception::ERRNO_LIBDODO, TEMPEX_NOTOPENED, IOFILETEMPEX_NOTOPENED_STR, __LINE__, __FILE__); 
    416  
    417     if (fseek(handle->file, 0, SEEK_END) == -1) 
    418         throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX__WRITESTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    419  
    420     unsigned long _blockSize = strnlen(a_data, blockSize); 
    421  
    422     while (true) { 
    423         if (fwrite(a_data, _blockSize, 1, handle->file) == 0) { 
    424             if (errno == EINTR) 
    425                 continue; 
    426  
    427             if (ferror(handle->file) != 0) 
    428                 throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX__WRITESTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
    429         } 
    430  
    431         break; 
    432     } 
    433 } 
    434  
    435 //------------------------------------------------------------------- 
    436  
  • src/src/ioMemory.cc

    r1386 r1389  
    100100    } 
    101101 
    102     block = fd.block; 
    103102    append = fd.append; 
    104103    pos = fd.pos; 
    105     blockSize = fd.blockSize; 
     104    bs = fd.bs; 
    106105} 
    107106 
     
    182181 
    183182    pos = fd.pos; 
    184     block = fd.block; 
    185183    append = fd.append; 
    186     blockSize = fd.blockSize; 
     184    bs = fd.bs; 
    187185    flags = fd.flags; 
    188186    size = fd.size; 
     
    197195//------------------------------------------------------------------- 
    198196 
    199 void 
     197unsigned long 
    200198memory::_read(char * const a_data) const 
    201199{ 
    202     unsigned long pos = block ? this->pos * blockSize : this->pos; 
    203  
    204     if ((pos + blockSize) > size) 
     200    if (pos + bs > size) 
    205201        throw exception::basic(exception::MODULE_IOMEMORY, MEMORYEX__READ, exception::ERRNO_LIBDODO, MEMORYEX_OUTOFBOUNDS, IOMEMORYEX_OUTOFBOUNDS_STR, __LINE__, __FILE__); 
    206202 
    207     memcpy(a_data, data + pos, blockSize); 
    208 } 
    209  
    210 //------------------------------------------------------------------- 
    211  
    212 void 
     203    memcpy(a_data, data + pos, bs); 
     204 
     205    return bs; 
     206} 
     207 
     208//------------------------------------------------------------------- 
     209 
     210unsigned long 
    213211memory::_write(const char *const a_data) const 
    214212{ 
    215213    if (append) { 
    216         if (flags & FLAGS_FIXED_LENGTH) 
     214        if (flags & FLAGS_FIXED_LENGTH) { 
    217215            throw exception::basic(exception::MODULE_IOMEMORY, MEMORYEX__WRITE, exception::ERRNO_LIBDODO, MEMORYEX_APPENDTOFIXED, IOMEMORYEX_APPENDTOFIXED_STR, __LINE__, __FILE__); 
    218         else { 
    219             char *newData = new char[size + blockSize]; 
     216        } else { 
     217            char *newData = new char[size + bs]; 
    220218            memcpy(newData, data, size); 
    221             memcpy(newData + size, a_data, blockSize); 
    222             size += blockSize; 
     219            memcpy(newData + size, a_data, bs); 
     220            size += bs; 
    223221            delete [] data; 
    224222            data = newData; 
    225223        } 
    226224    } else { 
    227         unsigned long pos = block ? this->pos * blockSize : this->pos; 
    228  
    229         unsigned long shift = pos + blockSize; 
     225        unsigned long shift = pos + bs; 
    230226        if (shift > size) { 
    231             if (flags & FLAGS_FIXED_LENGTH) 
     227            if (flags & FLAGS_FIXED_LENGTH) { 
    232228                throw exception::basic(exception::MODULE_IOMEMORY, MEMORYEX__WRITE, exception::ERRNO_LIBDODO, MEMORYEX_EXTENDFIXED, IOMEMORYEX_EXTENDFIXED_STR, __LINE__, __FILE__); 
    233             else { 
     229            } else { 
    234230                shift -= size; 
    235231                char *newData = new char[size + shift]; 
     
    242238        } 
    243239 
    244         memcpy(data + pos, a_data, blockSize); 
    245     } 
     240        memcpy(data + pos, a_data, bs); 
     241    } 
     242 
     243    return bs; 
    246244} 
    247245 
     
    253251    pc::sync::stack pg(keeper); 
    254252 
    255     unsigned long pos = block ? this->pos * blockSize : this->pos; 
    256  
    257     unsigned long shift = pos + blockSize; 
     253    unsigned long shift = pos + bs; 
    258254    if (shift > size) { 
    259         if (flags & FLAGS_FIXED_LENGTH) 
     255        if (flags & FLAGS_FIXED_LENGTH) { 
    260256            throw exception::basic(exception::MODULE_IOMEMORY, MEMORYEX_ERASE, exception::ERRNO_LIBDODO, MEMORYEX_EXTENDFIXED, IOMEMORYEX_EXTENDFIXED_STR, __LINE__, __FILE__); 
    261         else { 
     257        } else { 
    262258            shift -= size; 
    263259            char *newData = new char[size + shift]; 
     
    270266    } 
    271267 
    272     memset(data + pos, 0x0, blockSize); 
     268    memset(data + pos, 0x0, bs); 
    273269} 
    274270 
     
    278274memory::_readString(char * const a_data) const 
    279275{ 
    280     unsigned long readSize = blockSize + 1; 
    281  
    282     memset(a_data, '\0', readSize); 
     276    unsigned long readSize = bs + 1; 
    283277 
    284278    unsigned long read = 0; 
    285279 
    286     if (block) { 
    287         unsigned long block = 0; 
    288         unsigned long index = 0; 
    289         for (; index < size; ++index) { 
    290             if (data[index] == '\n' || data[index] == '\0') 
    291                 ++block; 
    292  
    293             if (block == pos) { 
    294                 ++index; 
    295  
    296                 for (unsigned long i = index; i < size && read < readSize; ++i) { 
    297                     a_data[read] = data[i]; 
    298  
    299                     ++read; 
    300  
    301                     if (data[i] == '\n' || data[i] == '\0') 
    302                         break; 
    303                 } 
    304  
    305                 break; 
    306             } 
    307         } 
    308     } else { 
    309         for (unsigned long i = pos; i < size && read < readSize; ++i) { 
    310             a_data[read] = data[i]; 
    311  
    312             ++read; 
    313  
    314             if (data[i] == '\n' || data[i] == '\0') 
    315                 break; 
    316         } 
     280    for (unsigned long i = pos; i < size && read < readSize; ++i) { 
     281        a_data[read] = data[i]; 
     282 
     283        ++read; 
     284 
     285        if (data[i] == '\n' || data[i] == '\0') 
     286            break; 
    317287    } 
    318288 
     
    322292//------------------------------------------------------------------- 
    323293 
    324 void 
     294unsigned long 
    325295memory::_writeString(const char *const a_data) const 
    326296{ 
    327297    if (flags & FLAGS_FIXED_LENGTH) 
    328         throw exception::basic(exception::MODULE_IOMEMORY, MEMORYEX__WRITESTREAM, exception::ERRNO_LIBDODO, MEMORYEX_EXTENDFIXED, IOMEMORYEX_EXTENDFIXED_STR, __LINE__, __FILE__); 
    329  
    330     unsigned long _blockSize = strnlen(a_data, blockSize); 
    331  
    332     char *newData = new char[size + _blockSize + 1]; 
     298        throw exception::basic(exception::MODULE_IOMEMORY, MEMORYEX__WRITESTRING, exception::ERRNO_LIBDODO, MEMORYEX_EXTENDFIXED, IOMEMORYEX_EXTENDFIXED_STR, __LINE__, __FILE__); 
     299 
     300    unsigned long _bs = strnlen(a_data, bs); 
     301 
     302    char *newData = new char[size + _bs + 1]; 
    333303    memcpy(newData, data, size); 
    334     memcpy(newData + size, a_data, _blockSize); 
    335     size += _blockSize; 
     304    memcpy(newData + size, a_data, _bs); 
     305    size += _bs; 
    336306    newData[size] = '\0'; 
    337307    delete [] data; 
    338308    data = newData; 
    339309    nullEnd = true; 
    340 } 
    341  
    342 //------------------------------------------------------------------- 
    343  
     310 
     311    return _bs; 
     312} 
     313 
     314//------------------------------------------------------------------- 
     315 
  • src/src/ioNetworkExchange.cc

    r1386 r1389  
    127127 
    128128void 
    129 exchange::init(int  a_socket, 
     129exchange::init(int  dataocket, 
    130130               bool a_blocked, 
    131131               bool blockInherited) 
     
    140140 
    141141    blocked = a_blocked; 
    142     socket = a_socket; 
     142    socket = dataocket; 
    143143 
    144144    setInBufferSize(inSocketBufferSize); 
     
    186186//------------------------------------------------------------------- 
    187187 
    188 void 
    189 exchange::_write(const char * const a_data) const 
     188unsigned long 
     189exchange::_write(const char * const data) const 
    190190{ 
    191191    if (socket == -1) 
    192192        throw exception::basic(exception::MODULE_IONETWORKEXCHANGE, EXCHANGEEX__WRITE, exception::ERRNO_LIBDODO, EXCHANGEEX_NOCONNECTION, IONETWORKEXCHANGEEX_NOCONNECTION_STR, __LINE__, __FILE__); 
    193193 
    194     unsigned long iter = blockSize / outSocketBufferSize; 
    195     unsigned long rest = blockSize % outSocketBufferSize; 
    196  
    197     const char *data = a_data; 
     194    unsigned long iter = bs / outSocketBufferSize; 
     195    unsigned long rest = bs % outSocketBufferSize; 
     196 
     197    const char *s = data; 
    198198 
    199199    long batch, n; 
     
    203203        while (batch > 0) { 
    204204            while (true) { 
    205                 if ((n = ::send(socket, data, batch, 0)) == -1) { 
     205                if ((n = ::send(socket, s, batch, 0)) == -1) { 
    206206                    if (errno == EINTR) 
    207207                        continue; 
    208208 
    209209                    if (errno == EAGAIN) 
    210                         break; 
     210                        return s - data; 
    211211 
    212212                    throw exception::basic(exception::MODULE_IONETWORKEXCHANGE, EXCHANGEEX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
     
    217217 
    218218            batch -= n; 
    219             data += n; 
     219            s += n; 
    220220        } 
    221221    } 
     
    225225        while (batch > 0) { 
    226226            while (true) { 
    227                 if ((n = ::send(socket, data, batch, 0)) == -1) { 
     227                if ((n = ::send(socket, s, batch, 0)) == -1) { 
    228228                    if (errno == EINTR) 
    229229                        continue; 
    230230 
    231231                    if (errno == EAGAIN) 
    232                         break; 
     232                        return s - data; 
    233233 
    234234                    throw exception::basic(exception::MODULE_IONETWORKEXCHANGE, EXCHANGEEX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
     
    239239 
    240240            batch -= n; 
    241             data += n; 
    242         } 
    243     } 
    244 } 
    245  
    246 //------------------------------------------------------------------- 
    247  
    248 void 
    249 exchange::_read(char * const a_data) const 
     241            s += n; 
     242        } 
     243    } 
     244 
     245    return bs; 
     246} 
     247 
     248//------------------------------------------------------------------- 
     249 
     250unsigned long 
     251exchange::_read(char * const data) const 
    250252{ 
    251253    if (socket == -1) 
    252254        throw exception::basic(exception::MODULE_IONETWORKEXCHANGE, EXCHANGEEX__READ, exception::ERRNO_LIBDODO, EXCHANGEEX_NOCONNECTION, IONETWORKEXCHANGEEX_NOCONNECTION_STR, __LINE__, __FILE__); 
    253255