Changeset 1389:aa5091977955
- Timestamp:
- 11/05/09 17:52:12 (2 years ago)
- Branch:
- default
- Location:
- src
- Files:
-
- 50 edited
-
examples/image/test.cc (modified) (1 diff)
-
examples/iofile_toolsfilesystem/test.cc (modified) (1 diff)
-
examples/iomemory/test.cc (modified) (1 diff)
-
examples/ionetwork_pcthreads/test.cc (modified) (1 diff)
-
examples/ionetworkclient/test.cc (modified) (1 diff)
-
examples/ionetworkserver/test.cc (modified) (1 diff)
-
examples/ionetworksslclient/test.cc (modified) (1 diff)
-
examples/ionetworksslserver/test.cc (modified) (2 diffs)
-
examples/iopipe_iofilefifo_pcthread/test.cc (modified) (3 diffs)
-
examples/iostdio/test.cc (modified) (4 diffs)
-
examples/rpcjsoncgiserver/test.cc (modified) (1 diff)
-
examples/rpcjsonhttpclient/test.cc (modified) (1 diff)
-
examples/rpcxmlcgiserver/test.cc (modified) (1 diff)
-
examples/rpcxmlhttpclient/test.cc (modified) (1 diff)
-
examples/xexec/test.cc (modified) (1 diff)
-
include/libdodo/cgiFastExchange.h (modified) (1 diff)
-
include/libdodo/cgiFastExchangeEx.h (modified) (1 diff)
-
include/libdodo/ioBlockChannel.h (modified) (2 diffs)
-
include/libdodo/ioChannel.h (modified) (2 diffs)
-
include/libdodo/ioFileFifo.h (modified) (2 diffs)
-
include/libdodo/ioFileFifoEx.h (modified) (1 diff)
-
include/libdodo/ioFileRegular.h (modified) (4 diffs)
-
include/libdodo/ioFileRegularEx.h (modified) (3 diffs)
-
include/libdodo/ioFileTemp.h (modified) (4 diffs)
-
include/libdodo/ioFileTempEx.h (modified) (1 diff)
-
include/libdodo/ioMemory.h (modified) (1 diff)
-
include/libdodo/ioMemoryEx.h (modified) (1 diff)
-
include/libdodo/ioNetworkExchange.h (modified) (2 diffs)
-
include/libdodo/ioNetworkExchangeEx.h (modified) (1 diff)
-
include/libdodo/ioNetworkSslExchange.h (modified) (1 diff)
-
include/libdodo/ioNetworkSslExchangeEx.h (modified) (1 diff)
-
include/libdodo/ioPipe.h (modified) (1 diff)
-
include/libdodo/ioPipeEx.h (modified) (1 diff)
-
include/libdodo/ioStdio.h (modified) (1 diff)
-
include/libdodo/ioStreamChannel.h (modified) (1 diff)
-
src/cgiDialogue.cc (modified) (2 diffs)
-
src/cgiFastExchange.cc (modified) (2 diffs)
-
src/ioBlockChannel.cc (modified) (8 diffs)
-
src/ioChannel.cc (modified) (1 diff)
-
src/ioFileFifo.cc (modified) (9 diffs)
-
src/ioFileRegular.cc (modified) (9 diffs)
-
src/ioFileTemp.cc (modified) (8 diffs)
-
src/ioMemory.cc (modified) (8 diffs)
-
src/ioNetworkExchange.cc (modified) (12 diffs)
-
src/ioNetworkHttpClient.cc (modified) (15 diffs)
-
src/ioNetworkSslExchange.cc (modified) (11 diffs)
-
src/ioPipe.cc (modified) (9 diffs)
-
src/ioStdio.cc (modified) (1 diff)
-
src/ioStreamChannel.cc (modified) (7 diffs)
-
src/toolsCode.cc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/examples/image/test.cc
r1386 r1389 78 78 file::regular io; 79 79 io.open("my.png", file::regular::OPEN_MODE_READ_WRITE_TRUNCATE); 80 io.b lockSize= img.size();80 io.bs = img.size(); 81 81 io.write(img); 82 82 -
src/examples/iofile_toolsfilesystem/test.cc
r1386 r1389 71 71 72 72 io1.pos = 1; 73 io1.b lockSize= 14;73 io1.bs = 14; 74 74 io1.block = true; 75 75 io1.write("!12345890$!~@\n"); -
src/examples/iomemory/test.cc
r1386 r1389 31 31 32 32 io1.pos = 1; 33 io1.b lockSize= 14;33 io1.bs = 14; 34 34 io1.write("!12345890$!~@\n"); 35 35 -
src/examples/ionetwork_pcthreads/test.cc
r1386 r1389 40 40 ex->setOutBufferSize(1); 41 41 42 ex->b lockSize= 7;42 ex->bs = 7; 43 43 ex->writeString("test\n"); 44 44 45 45 dodoString str = ""; 46 46 try { 47 ex->b lockSize= 4;47 ex->bs = 4; 48 48 str = ex->read(); 49 49 -
src/examples/ionetworkclient/test.cc
r1386 r1389 31 31 32 32 str = "GET / HTTP/1.1\r\n"; 33 ex.b lockSize= str.size();33 ex.bs = str.size(); 34 34 ex.write(str); 35 35 36 36 str = "Host: " + host + "\r\n"; 37 ex.b lockSize= str.size();37 ex.bs = str.size(); 38 38 ex.write(str); 39 39 40 40 str = "Connection: Close\r\n"; 41 ex.b lockSize= str.size();41 ex.bs = str.size(); 42 42 ex.write(str); 43 43 44 44 str = "User-Agent: " PACKAGE_NAME "/" PACKAGE_VERSION "\r\n\r\n"; 45 ex.b lockSize= str.size();45 ex.bs = str.size(); 46 46 ex.write(str); 47 47 48 ex.b lockSize= 512;48 ex.bs = 512; 49 49 str = ex.readString(); 50 50 -
src/examples/ionetworkserver/test.cc
r1386 r1389 29 29 ex.setOutBufferSize(1); 30 30 31 ex.b lockSize= 7;31 ex.bs = 7; 32 32 ex.writeString("test\n"); 33 33 34 34 dodoString str = ""; 35 35 try { 36 ex.b lockSize= 4;36 ex.bs = 4; 37 37 str = ex.read(); 38 38 -
src/examples/ionetworksslclient/test.cc
r1386 r1389 46 46 47 47 str = "GET / HTTP/1.1\r\n"; 48 ex.b lockSize= str.size();48 ex.bs = str.size(); 49 49 ex.write(str); 50 50 51 51 str = "Host: " + host + "\r\n"; 52 ex.b lockSize= str.size();52 ex.bs = str.size(); 53 53 ex.write(str); 54 54 55 55 str = "Connection: Close\r\n"; 56 ex.b lockSize= str.size();56 ex.bs = str.size(); 57 57 ex.write(str); 58 58 59 59 str = "User-Agent: " PACKAGE_NAME "/" PACKAGE_VERSION "\r\n\r\n"; 60 ex.b lockSize= str.size();60 ex.bs = str.size(); 61 61 ex.write(str); 62 62 63 ex.b lockSize= 4096;63 ex.bs = 4096; 64 64 str = ex.readString(); 65 65 -
src/examples/ionetworksslserver/test.cc
r1386 r1389 41 41 ex.setOutBufferSize(1); 42 42 43 ex.b lockSize= 7;43 ex.bs = 7; 44 44 ex.writeString("test\n"); 45 45 … … 49 49 dodoString str = ""; 50 50 try { 51 ex.b lockSize= 4;51 ex.bs = 4; 52 52 str = ex.read(); 53 53 -
src/examples/iopipe_iofilefifo_pcthread/test.cc
r1386 r1389 33 33 cout.flush(); 34 34 35 pipe->b lockSize= tools::string::stringToUL(str);35 pipe->bs = tools::string::stringToUL(str); 36 36 str = pipe->read(); 37 37 cout << "%MD5: " << tools::code::MD5Hex(str) << "%\n"; … … 66 66 pipe->flush(); 67 67 68 pipe->b lockSize= str.size();68 pipe->bs = str.size(); 69 69 pipe->write(str); 70 70 pipe->flush(); … … 103 103 104 104 cout << "\n~~using original cloned pipe for one thread and copy for the second~~\n"; 105 pipe1.b lockSize= 4096;105 pipe1.bs = 4096; 106 106 107 107 io::pipe pipe2 = pipe1; -
src/examples/iostdio/test.cc
r1386 r1389 25 25 stdio *io = dynamic_cast<stdio *>(st->executor); 26 26 dodoString buffer = st->buffer; 27 io->b lockSize= 100;27 io->bs = 100; 28 28 io->writeString("\nhook\n"); 29 29 30 30 dodoString str = ">" + buffer + "<\n"; 31 31 32 io->b lockSize= str.size();32 io->bs = str.size(); 33 33 st->buffer.assign(str); 34 34 } … … 48 48 #endif 49 49 50 st.b lockSize= sizeof("write");50 st.bs = sizeof("write"); 51 51 st.write("write"); 52 52 st.flush(); … … 57 57 dodoString o; 58 58 59 st.b lockSize= 33;59 st.bs = 33; 60 60 61 61 o = st.read(); … … 64 64 cout << o << "\n"; 65 65 66 st.b lockSize= 4;66 st.bs = 4; 67 67 st.write("1234567890"); 68 68 st.writeString("\n"); 69 69 70 st.b lockSize= 40;70 st.bs = 40; 71 71 st.writeString(o); 72 72 st.writeString("\nexiting\n"); -
src/examples/rpcjsoncgiserver/test.cc
r1386 r1389 38 38 39 39 if (size != 0) { 40 if (size > b lockSize)41 size = b lockSize;40 if (size > bs) 41 size = bs; 42 42 43 43 memcpy(data, provider.content.data(), size); 44 if (size < b lockSize)45 memset(data + size, 0x0, b lockSize- size);44 if (size < bs) 45 memset(data + size, 0x0, bs - size); 46 46 } 47 47 -
src/examples/rpcjsonhttpclient/test.cc
r1386 r1389 46 46 size = response->data.size(); 47 47 if (size != 0) { 48 if (size > b lockSize)49 size = b lockSize;48 if (size > bs) 49 size = bs; 50 50 51 51 memcpy(data, response->data.data(), size); 52 if (size < b lockSize)53 memset(data + size, 0x0, b lockSize- size);52 if (size < bs) 53 memset(data + size, 0x0, bs - size); 54 54 } 55 55 -
src/examples/rpcxmlcgiserver/test.cc
r1386 r1389 38 38 39 39 if (size != 0) { 40 if (size > b lockSize)41 size = b lockSize;40 if (size > bs) 41 size = bs; 42 42 43 43 memcpy(data, provider.content.data(), size); 44 if (size < b lockSize)45 memset(data + size, 0x0, b lockSize- size);44 if (size < bs) 45 memset(data + size, 0x0, bs - size); 46 46 } 47 47 -
src/examples/rpcxmlhttpclient/test.cc
r1386 r1389 47 47 size = response->data.size(); 48 48 if (size != 0) { 49 if (size > b lockSize)50 size = b lockSize;49 if (size > bs) 50 size = bs; 51 51 52 52 memcpy(data, response->data.data(), size); 53 if (size < b lockSize)54 memset(data + size, 0x0, b lockSize- size);53 if (size < bs) 54 memset(data + size, 0x0, bs - size); 55 55 } 56 56 -
src/examples/xexec/test.cc
r1386 r1389 34 34 #endif 35 35 36 io.b lockSize= sizeof("xexec") - 1;36 io.bs = sizeof("xexec") - 1; 37 37 io.write("xexec"); 38 38 io.flush(); -
src/include/libdodo/cgiFastExchange.h
r1386 r1389 94 94 95 95 /** 96 * read97 * @param data is filled with read data98 * if blockSize bigger than buffer size - reads with few iterations96 * @return successfully read bytes 97 * @param data defines buffer that will be filled 98 * @note not more then bs(including null) 99 99 */ 100 virtual void_read(char * const data) const;100 virtual unsigned long _read(char * const data) const; 101 101 102 102 /** 103 * read from stream - '\0' or '\n' - terminated string 103 * read null- or newline- terminated string 104 * @return successfully read bytes 104 105 * @param data defines buffer that will be filled 105 * @note not more then b lockSize(including '\0')106 * @note not more then bs(including null) 106 107 */ 107 108 virtual unsigned long _readString(char * const data) const; 108 109 109 110 /** 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 113 113 */ 114 virtual void_write(const char * const data) const;114 virtual unsigned long _write(const char * const data) const; 115 115 116 116 /** 117 * write to stream - '\0' - terminated string 117 * write null- terminated string 118 * @return successfully written bytes 118 119 * @param data defines data that will be written 120 * @note puts extra null in the end of the string 119 121 */ 120 virtual void_writeString(const char * const data) const;122 virtual unsigned long _writeString(const char * const data) const; 121 123 122 124 private: -
src/include/libdodo/cgiFastExchangeEx.h
r1386 r1389 60 60 FASTEXCHANGEEX_FLUSH, 61 61 FASTEXCHANGEEX__WRITE, 62 FASTEXCHANGEEX__WRITESTRING, 62 63 FASTEXCHANGEEX_INDESCRIPTOR, 63 64 FASTEXCHANGEEX_OUTDESCRIPTOR, -
src/include/libdodo/ioBlockChannel.h
r1386 r1389 42 42 * @class channel 43 43 * @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*blockSize47 * offset for read is calculated as pos*blockSize48 * 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)50 44 */ 51 45 class channel : public io::channel { … … 65 59 /** 66 60 * @return read data 67 * @note not more then b lockSize61 * @note not more then bs 68 62 */ 69 63 virtual dodoString read() const; 70 64 71 65 /** 66 * @return successfully written bytes 72 67 * @param data defines data that will be written 73 * @note not more then b lockSize68 * @note not more then bs 74 69 */ 75 virtual voidwrite(const dodoString &data) const;70 virtual unsigned long write(const dodoString &data) const; 76 71 77 72 /** 78 * read from streamnull- or newline- terminated string73 * read null- or newline- terminated string 79 74 * @return read data 80 * @note not more then b lockSize75 * @note not more then bs 81 76 */ 82 77 virtual dodoString readString() const; 83 78 84 79 /** 85 * write to stream null- terminated string 80 * write null- terminated string 81 * @return successfully written bytes 86 82 * @param data defines data that will be written 87 * @note not more then b lockSize83 * @note not more then bs 88 84 */ 89 virtual voidwriteString(const dodoString &data) const;85 virtual unsigned long writeString(const dodoString &data) const; 90 86 91 87 mutable unsigned long pos; ///< read/write/erase position; incremented on read/write/erase[0 by default] 92 88 93 bool block; ///< use block I/O[false by default]94 89 bool append; ///< append to the end[false by default] 95 90 }; -
src/include/libdodo/ioChannel.h
r1386 r1389 123 123 /** 124 124 * @return read data 125 * @note not more then b lockSize125 * @note not more then bs 126 126 */ 127 127 virtual dodoString read() const = 0; 128 128 129 129 /** 130 * @return successfully written bytes 130 131 * @param data defines data that will be written 131 * @note not more then b lockSize132 * @note not more then bs 132 133 */ 133 virtual voidwrite(const dodoString &data) const = 0;134 virtual unsigned long write(const dodoString &data) const = 0; 134 135 135 136 /** 136 * read from streamnull- or newline- terminated string137 * read null- or newline- terminated string 137 138 * @return read data 138 * @note not more then b lockSize139 * @note not more then bs 139 140 */ 140 141 virtual dodoString readString() const = 0; 141 142 142 143 /** 143 * write to stream null- terminated string 144 * write null- terminated string 145 * @return successfully written bytes 144 146 * @param data defines data that will be written 145 * @note not more then b lockSize147 * @note not more then bs 146 148 */ 147 virtual voidwriteString(const dodoString &data) const = 0;149 virtual unsigned long writeString(const dodoString &data) const = 0; 148 150 149 151 /** … … 152 154 virtual void flush() const = 0; 153 155 154 mutable unsigned long b lockSize; ///< size of data block for read/write operations156 mutable unsigned long bs; ///< size of data block for read/write operations 155 157 156 158 protected: 157 159 158 160 /** 161 * @return successfully read bytes 159 162 * @param data defines buffer that will be filled 160 * @note not more then b lockSize(including null)163 * @note not more then bs(including null) 161 164 */ 162 virtual void_read(char * const data) const = 0;165 virtual unsigned long _read(char * const data) const = 0; 163 166 164 167 /** 165 * read from stream null- or newline- terminated string 168 * read null- or newline- terminated string 169 * @return successfully read bytes 166 170 * @param data defines buffer that will be filled 167 * @note not more then b lockSize(including null)171 * @note not more then bs(including null) 168 172 */ 169 173 virtual unsigned long _readString(char * const data) const = 0; 170 174 171 175 /** 176 * @return successfully written bytes 172 177 * @param data defines data that will be written 173 * @note not more then b lockSize(including null)178 * @note not more then bs(including null) 174 179 */ 175 virtual void_write(const char * const data) const = 0;180 virtual unsigned long _write(const char * const data) const = 0; 176 181 177 182 /** 178 * write to stream null- terminated string 183 * write null- terminated string 184 * @return successfully written bytes 179 185 * @param data defines data that will be written 180 * @note not more then b lockSize(including null)186 * @note not more then bs(including null) 181 187 */ 182 virtual void_writeString(const char * const data) const = 0;188 virtual unsigned long _writeString(const char * const data) const = 0; 183 189 184 190 pc::sync::protector *keeper; ///< section locker -
src/include/libdodo/ioFileFifo.h
r1386 r1389 45 45 * @class fifo 46 46 * @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 manually48 47 */ 49 48 class fifo : virtual public stream::channel { … … 145 144 146 145 /** 146 * @return successfully read bytes 147 147 * @param data defines buffer that will be filled 148 * @note not more then b lockSize(including null)148 * @note not more then bs(including null) 149 149 */ 150 virtual void_read(char * const data) const;150 virtual unsigned long _read(char * const data) const; 151 151 152 152 /** 153 * read from stream null- or newline- terminated string 153 * read null- or newline- terminated string 154 * @return successfully read bytes 154 155 * @param data defines buffer that will be filled 155 * @note not more then b lockSize(including null)156 * @note not more then bs(including null) 156 157 */ 157 158 virtual unsigned long _readString(char * const data) const; 158 159 159 160 /** 161 * @return successfully written bytes 160 162 * @param data defines data that will be written 161 163 */ 162 virtual void_write(const char * const data) const;164 virtual unsigned long _write(const char * const data) const; 163 165 164 166 /** 165 * write to stream null- terminated string 167 * write null- terminated string 168 * @return successfully written bytes 166 169 * @param data defines data that will be written 167 170 * @note puts extra newline- to the end of the string 168 171 */ 169 virtual void_writeString(const char * const data) const;172 virtual unsigned long _writeString(const char * const data) const; 170 173 171 174 private: -
src/include/libdodo/ioFileFifoEx.h
r1386 r1389 62 62 FIFOEX__READ, 63 63 FIFOEX__WRITE, 64 FIFOEX__READSTR EAM,65 FIFOEX__WRITESTR EAM,64 FIFOEX__READSTRING, 65 FIFOEX__WRITESTRING, 66 66 FIFOEX_FLUSH, 67 67 FIFOEX_BLOCK, -
src/include/libdodo/ioFileRegular.h
r1386 r1389 42 42 43 43 namespace file { 44 class temp; 45 44 46 /** 45 47 * @class regular … … 47 49 */ 48 50 class regular : virtual public block::channel { 51 friend class file::temp; 52 49 53 public: 50 54 … … 107 111 * @param mode defines mode to open file, @see file::regular::openModeEnum 108 112 */ 109 v irtual void open(const dodoString &path,110 short mode);113 void open(const dodoString &path, 114 short mode); 111 115 112 116 /** … … 138 142 139 143 /** 144 * @return successfully read bytes 140 145 * @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) 143 147 */ 144 virtual void_read(char * const data) const;148 virtual unsigned long _read(char * const data) const; 145 149 146 150 /** 147 * read from stream null- or newline- terminated string 151 * read null- or newline- terminated string 152 * @return successfully read bytes 148 153 * @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) 151 155 */ 152 156 virtual unsigned long _readString(char * const data) const; 153 157 154 158 /** 159 * @return successfully written bytes 155 160 * @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 beginning157 161 */ 158 virtual void_write(const char * const data) const;162 virtual unsigned long _write(const char * const data) const; 159 163 160 164 /** 161 * write to stream null- terminated string 165 * write null- terminated string 166 * @return successfully written bytes 162 167 * @param data defines data that will be written 163 168 * @note write only to the end of the file(append) 164 169 */ 165 virtual void_writeString(const char * const data) const;170 virtual unsigned long _writeString(const char * const data) const; 166 171 167 172 private: -
src/include/libdodo/ioFileRegularEx.h
r1386 r1389 43 43 enum regularExR { 44 44 REGULAREX_WRONGFILENAME, 45 REGULAREX_FILEISSHORTERTHANGIVENPOSITION,46 45 REGULAREX_NOTOPENED 47 46 }; … … 51 50 */ 52 51 #define IOFILEREGULAREX_WRONGFILENAME_STR "Wrong filename" 53 #define IOFILEREGULAREX_FILEISSHORTERTHANGIVENPOSITION_STR "Access data out of bounds"54 52 #define IOFILEREGULAREX_NOTOPENED_STR "File not opened" 55 53 … … 64 62 REGULAREX__READ, 65 63 REGULAREX__WRITE, 66 REGULAREX__READSTR EAM,67 REGULAREX__WRITESTR EAM,64 REGULAREX__READSTRING, 65 REGULAREX__WRITESTRING, 68 66 REGULAREX_FLUSH, 69 67 REGULAREX_INDESCRIPTOR, -
src/include/libdodo/ioFileTemp.h
r1386 r1389 35 35 #include <libdodo/ioChannel.h> 36 36 #include <libdodo/ioBlockChannel.h> 37 #include <libdodo/ioFileRegular.h> 37 38 38 39 namespace dodo { … … 44 45 * @class temp 45 46 * @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*blockSize49 * read offset for read, read is calculated as pos*blockSize50 * read offset for readString, readString is calculated as pos*'# of \n terminated strings'51 47 */ 52 class temp : virtual public block::channel { 48 class temp : virtual public block::channel, 49 public regular { 53 50 public: 54 51 … … 59 56 enum operationEnum { 60 57 OPERATION_OPEN = 128, 61 OPERATION_CLOSE62 58 }; 63 59 #endif … … 84 80 /** 85 81 * clone file object 86 * @param f ddefines object to clone82 * @param file defines object to clone 87 83 * @note xexec object is not copied 88 84 */ 89 void clone(const temp &fd); 85 void clone(const temp &file); 86 90 87 91 88 /** 92 89 * open file 93 90 */ 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(); 159 92 }; 160 93 }; -
src/include/libdodo/ioFileTempEx.h
r1386 r1389 64 64 TEMPEX__READ, 65 65 TEMPEX__WRITE, 66 TEMPEX__READSTR EAM,67 TEMPEX__WRITESTR EAM,66 TEMPEX__READSTRING, 67 TEMPEX__WRITESTRING, 68 68 TEMPEX_FLUSH, 69 69 TEMPEX_INDESCRIPTOR, -
src/include/libdodo/ioMemory.h
r1386 r1389 132 132 133 133 /** 134 * @return successfully read bytes 134 135 * @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) 137 137 */ 138 virtual void_read(char * const data) const;138 virtual unsigned long _read(char * const data) const; 139 139 140 140 /** 141 * read from stream null- or newline- terminated memory 141 * read null- or newline- terminated memory 142 * @return successfully read bytes 142 143 * @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) 145 145 */ 146 146 virtual unsigned long _readString(char * const data) const; 147 147 148 148 /** 149 * @return successfully written bytes 149 150 * @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 beginning151 151 */ 152 virtual void_write(const char * const data) const;152 virtual unsigned long _write(const char * const data) const; 153 153 154 154 /** 155 * write to stream null- terminated memory 155 * write null- terminated memory 156 * @return successfully written bytes 156 157 * @param data defines data that will be written 157 158 * @note write only to the end of the file(append) 158 159 */ 159 virtual void_writeString(const char * const data) const;160 virtual unsigned long _writeString(const char * const data) const; 160 161 161 162 protected: -
src/include/libdodo/ioMemoryEx.h
r1386 r1389 63 63 MEMORYEX__READ, 64 64 MEMORYEX__WRITE, 65 MEMORYEX__WRITESTR EAM,65 MEMORYEX__WRITESTRING, 66 66 MEMORYEX_ERASE, 67 67 MEMORYEX_INDESCRIPTOR, -
src/include/libdodo/ioNetworkExchange.h
r1386 r1389 48 48 * @class exchange 49 49 * @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 sessions51 * writesStream* put extra null in the end of the string52 50 */ 53 51 class exchange : public connection, … … 169 167 170 168 /** 169 * @return successfully read bytes 171 170 * @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 178 178 * @param data defines buffer that will be filled 179 * @note not more then b lockSize(including null)179 * @note not more then bs(including null) 180 180 */ 181 181 virtual unsigned long _readString(char * const data) const; 182 182 183 183 /** 184 * @return successfully written bytes 184 185 * @param data defines data that will be written 185 186 */ 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 190 192 * @param data defines data that will be written 191 193 * @note puts extra null in the end of the string 192 194 */ 193 virtual void_writeString(const char * const data) const;195 virtual unsigned long _writeString(const char * const data) const; 194 196 }; 195 197 }; -
src/include/libdodo/ioNetworkExchangeEx.h
r1386 r1389 56 56 EXCHANGEEX__WRITE, 57 57 EXCHANGEEX__READ, 58 EXCHANGEEX__READSTR EAM,58 EXCHANGEEX__READSTRING, 59 59 }; 60 60 }; -
src/include/libdodo/ioNetworkSslExchange.h
r1386 r1389 153 153 154 154 /** 155 * @return successfully read bytes 155 156 * @param data defines buffer that will be filled 156 * @note not more then b lockSize(including null)157 * @note not more then bs(including null) 157 158 */ 158 virtual void_read(char * const data) const;159 virtual unsigned long _read(char * const data) const; 159 160 160 161 /** 161 * read from stream null or newline terminated string 162 * read null- or newline- terminated string 163 * @return successfully read bytes 162 164 * @param data defines buffer that will be filled 163 * @note not more then b lockSize(including null)165 * @note not more then bs(including null) 164 166 */ 165 167 virtual unsigned long _readString(char * const data) const; 166 168 167 169 /** 170 * @return successfully written bytes 168 171 * @param data defines data that will be written 169 172 */ 170 virtual void_write(const char * const data) const;173 virtual unsigned long _write(const char * const data) const; 171 174 }; 172 175 }; -
src/include/libdodo/ioNetworkSslExchangeEx.h
r1386 r1389 57 57 EXCHANGEEX__WRITE, 58 58 EXCHANGEEX__READ, 59 EXCHANGEEX__READSTR EAM,59 EXCHANGEEX__READSTRING, 60 60 EXCHANGEEX__CLOSE, 61 61 }; -
src/include/libdodo/ioPipe.h
r1386 r1389 128 128 129 129 /** 130 * @return successfully read bytes 130 131 * @param data defines buffer that will be filled 131 * @note not more then b lockSize(including null)132 * @note not more then bs(including null) 132 133 */ 133 virtual void_read(char * const data) const;134 virtual unsigned long _read(char * const data) const; 134 135 135 136 /** 136 * read from stream null or newline terminated string 137 * read null- or newline- terminated string 138 * @return successfully read bytes 137 139 * @param data defines buffer that will be filled 138 * @note not more then b lockSize(including null)140 * @note not more then bs(including null) 139 141 */ 140 142 virtual unsigned long _readString(char * const data) const; 141 143 142 144 /** 145 * @return successfully written bytes 143 146 * @param data defines data that will be written 144 147 */ 145 virtual void_write(const char * const data) const;148 virtual unsigned long _write(const char * const data) const; 146 149 147 150 /** 148 * write to stream null terminated string 151 * write null- terminated string 152 * @return successfully written bytes 149 153 * @param data defines data that will be written 150 154 * @note puts extra newline to the end of the string 151 155 */ 152 virtual void_writeString(const char * const data) const;156 virtual unsigned long _writeString(const char * const data) const; 153 157 154 158 __file__ *in; ///< input stream descriptor -
src/include/libdodo/ioPipeEx.h
r1386 r1389 59 59 PIPEEX__READ, 60 60 PIPEEX__WRITE, 61 PIPEEX__READSTR EAM,62 PIPEEX__WRITESTR EAM,61 PIPEEX__READSTRING, 62 PIPEEX__WRITESTRING, 63 63 PIPEEX_FLUSH, 64 64 PIPEEX_PEERINFO, -
src/include/libdodo/ioStdio.h
r1386 r1389 78 78 79 79 /** 80 * write to stream null terminated string 80 * write null- terminated string 81 * @return successfully written bytes 81 82 * @param data defines data that will be written 82 83 */ 83 virtual void_writeString(const char * const data) const;84 virtual unsigned long _writeString(const char * const data) const; 84 85 85 86 private: -
src/include/libdodo/ioStreamChannel.h
r1386 r1389 59 59 /** 60 60 * @return read data 61 * @note not more then b lockSize61 * @note not more then bs 62 62 */ 63 63 virtual dodoString read() const; 64 64 65 65 /** 66 * @return successfully written bytes 66 67 * @param data defines data that will be written 67 * @note not more then b lockSize68 * @note not more then bs 68 69 */ 69 virtual voidwrite(const dodoString &data) const;70 virtual unsigned long write(const dodoString &data) const; 70 71 71 72 /** 72 * read from stream null or newlineterminated string73 * read null- or newline- terminated string 73 74 * @return read data 74 * @note not more then b lockSize75 * @note not more then bs 75 76 */ 76 77 virtual dodoString readString() const; 77 78 78 79 /** 79 * write to stream null terminated string 80 * write null- terminated string 81 * @return successfully written bytes 80 82 * @param data defines data that will be written 81 * @note not more then b lockSize83 * @note not more then bs 82 84 */ 83 virtual voidwriteString(const dodoString &data) const;85 virtual unsigned long writeString(const dodoString &data) const; 84 86 }; 85 87 }; -
src/src/cgiDialogue.cc
r1386 r1389 287 287 printHeaders(); 288 288 289 unsigned long b lockSizeOrig = io.blockSize;;290 291 io.b lockSize= buf.size();289 unsigned long bsOrig = io.bs;; 290 291 io.bs = buf.size(); 292 292 io.write(buf); 293 293 294 io.b lockSize = blockSizeOrig;294 io.bs = bsOrig; 295 295 } 296 296 … … 596 596 dialogue::makeContent(unsigned long postSize) 597 597 { 598 unsigned long b lockSize= tools::string::stringToUL(ENVIRONMENT[ENVIRONMENT_CONTENTLENGTH]);599 unsigned long b lockSizeOrig;600 601 if (b lockSize<= 0)598 unsigned long bs = tools::string::stringToUL(ENVIRONMENT[ENVIRONMENT_CONTENTLENGTH]); 599 unsigned long bsOrig; 600 601 if (bs <= 0) 602 602 return ; 603 603 604 if (b lockSize> postSize)605 b lockSize= postSize;606 607 b lockSizeOrig = io.blockSize;608 io.b lockSize = blockSize;604 if (bs > postSize) 605 bs = postSize; 606 607 bsOrig = io.bs; 608 io.bs = bs; 609 609 610 610 content = io.read(); 611 611 612 io.b lockSize = blockSizeOrig;612 io.bs = bsOrig; 613 613 } 614 614 -
src/src/cgiFastExchange.cc
r1386 r1389 105 105 //------------------------------------------------------------------- 106 106 107 void 108 exchange::_read(char * const a_data) const107 unsigned long 108 exchange::_read(char * const data) const 109 109 { 110 FCGX_GetStr(a_data, blockSize, request->request->in);110 return FCGX_GetStr(data, bs, request->request->in); 111 111 } 112 112 113 113 //------------------------------------------------------------------- 114 114 115 void 116 exchange::_write(const char *const buf) const115 unsigned long 116 exchange::_write(const char *const data) const 117 117 { 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) 119 121 throw exception::basic(exception::MODULE_CGIFASTEXCHANGE, FASTEXCHANGEEX__WRITE, exception::ERRNO_LIBDODO, FASTEXCHANGEEX_FAILEDTOPRINTSTRING, CGIFASTEXCHANGEEX_FAILEDTOPRINTSTRING_STR, __LINE__, __FILE__); 122 123 return n; 120 124 } 121 125 122 126 //------------------------------------------------------------------- 123 127 124 void 128 unsigned long 125 129 exchange::_writeString(const char * const data) const 126 130 { 127 unsigned long _blockSize = blockSize;131 long n; 128 132 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__); 131 135 132 _write(data); 133 134 blockSize = _blockSize; 135 } catch (...) { 136 blockSize = _blockSize; 137 138 throw; 139 } 136 return n; 140 137 } 141 138 … … 145 142 exchange::_readString(char * const data) const 146 143 { 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); 154 145 } 155 146 #endif -
src/src/ioBlockChannel.cc
r1386 r1389 42 42 channel::channel(short protection) : io::channel(protection), 43 43 pos(0), 44 block(false),45 44 append(false) 46 45 { … … 60 59 pc::sync::stack pg(keeper); 61 60 62 dodoString a_str; 61 dodoString data; 62 unsigned long n; 63 63 64 64 #ifndef IO_WO_XEXEC 65 65 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(); 76 74 77 75 #ifndef IO_WO_XEXEC … … 83 81 84 82 #ifndef IO_WO_XEXEC 85 collectedData.buffer = a_str;83 collectedData.buffer = data; 86 84 87 85 performPostExec(OPERATION_READ); 88 86 89 a_str= collectedData.buffer;87 data = collectedData.buffer; 90 88 91 89 collectedData.buffer.clear(); … … 93 91 #endif 94 92 95 pos += blockSize;96 97 return a_str;93 pos += n; 94 95 return data; 98 96 } 99 97 … … 105 103 pc::sync::stack pg(keeper); 106 104 107 dodoString a_str; 105 dodoString data; 106 unsigned long n; 108 107 109 108 #ifndef IO_WO_XEXEC … … 111 110 #endif 112 111 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 140 unsigned long 141 channel::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 (...) { 129 155 collectedData.buffer.clear(); 130 156 131 performPostExec(OPERATION_READSTRING); 132 133 a_str = collectedData.buffer; 134 135 collectedData.buffer.clear(); 157 throw; 158 } 136 159 #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 176 unsigned long 177 channel::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()); 160 190 } catch (...) { 161 191 collectedData.buffer.clear(); … … 163 193 throw; 164 194 } 195 196 pos += n; 165 197 #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; 203 201 #endif 204 202 … … 208 206 collectedData.buffer.clear(); 209 207 #endif 210 } 211 212 //------------------------------------------------------------------- 213 208 209 return n; 210 } 211 212 //------------------------------------------------------------------- 213 -
src/src/ioChannel.cc
r1386 r1389 48 48 //------------------------------------------------------------------- 49 49 50 channel::channel(short protection) : b lockSize(IO_BLOCKSIZE),50 channel::channel(short protection) : bs(IO_BLOCKSIZE), 51 51 keeper(NULL), 52 52 protection(protection) -
src/src/ioFileFifo.cc
r1386 r1389 161 161 #endif 162 162 163 b lockSize = fd.blockSize;163 bs = fd.bs; 164 164 165 165 if (fd.handle->file != NULL) { … … 254 254 path = fd.path; 255 255 mode = fd.mode; 256 b lockSize = fd.blockSize;256 bs = fd.bs; 257 257 258 258 if (fd.handle->file != NULL) { … … 438 438 //------------------------------------------------------------------- 439 439 440 void 441 fifo::_read(char * const a_data) const440 unsigned long 441 fifo::_read(char * const data) const 442 442 { 443 443 if (handle->file == NULL) 444 444 throw exception::basic(exception::MODULE_IOFILEFIFO, FIFOEX__READ, exception::ERRNO_LIBDODO, FIFOEX_NOTOPENED, IOFILEFIFOEX_NOTOPENED_STR, __LINE__, __FILE__, path); 445 445 446 char * data = a_data;447 448 unsigned long batch = b lockSize, n;449 450 while (batch >0) {446 char *s = data; 447 448 unsigned long batch = bs, n; 449 450 while (batch != 0) { 451 451 while (true) { 452 if ((n = fread( data, 1, batch, handle->file)) == 0) {452 if ((n = fread(s, 1, batch, handle->file)) == 0) { 453 453 if (feof(handle->file) != 0 || errno == EAGAIN) 454 break;454 return bs - batch; 455 455 456 456 if (errno == EINTR) … … 465 465 466 466 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 475 unsigned long 476 fifo::_write(const char *const data) const 475 477 { 476 478 if (handle->file == NULL) 477 479 throw exception::basic(exception::MODULE_IOFILEFIFO, FIFOEX__WRITE, exception::ERRNO_LIBDODO, FIFOEX_NOTOPENED, IOFILEFIFOEX_NOTOPENED_STR, __LINE__, __FILE__, path); 478 480 479 const char * data = a_data;480 481 unsigned long batch = b lockSize, n;482 483 while (batch >0) {481 const char *s = data; 482 483 unsigned long batch = bs, n; 484 485 while (batch != 0) { 484 486 while (true) { 485 if ((n = fwrite( data, 1, batch, handle->file)) == 0) {487 if ((n = fwrite(s, 1, batch, handle->file)) == 0) { 486 488 if (errno == EINTR) 487 489 continue; 488 490 489 491 if (errno == EAGAIN) 490 break;492 return bs - batch; 491 493 492 494 if (ferror(handle->file) != 0) … … 498 500 499 501 batch -= n; 500 data += n; 501 } 502 s += n; 503 } 504 505 return bs; 502 506 } 503 507 … … 519 523 520 524 unsigned 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); 525 fifo::_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; 529 531 530 532 while (true) { 531 if (fgets( a_data, readSize, handle->file) == NULL) {533 if (fgets(data, readSize, handle->file) == NULL) { 532 534 if (errno == EINTR) 533 535 continue; 534 536 535 537 if (errno == EAGAIN) 536 break;538 return 0; 537 539 538 540 if (ferror(handle->file) != 0) 539 throw exception::basic(exception::MODULE_IOFILEFIFO, FIFOEX__READSTR EAM, 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__); 540 542 } 541 543 … … 543 545 } 544 546 545 return strlen( a_data);546 } 547 548 //------------------------------------------------------------------- 549 550 void 547 return strlen(data); 548 } 549 550 //------------------------------------------------------------------- 551 552 unsigned long 551 553 fifo::_writeString(const char *const data) const 552 554 { 553 unsigned long _blockSize = blockSize; 555 unsigned long _bs = bs; 556 unsigned long written; 554 557 555 558 try { 556 b lockSize = strnlen(data, blockSize);557 558 _write(data);559 560 if (data[b lockSize- 1] != '\n') {559 bs = strnlen(data, bs); 560 561 written = _write(data); 562 563 if (data[bs - 1] != '\n') { 561 564 while (true) { 562 565 if (fputc('\n', handle->file) == EOF) { … … 568 571 569 572 if (ferror(handle->file) != 0) 570 throw exception::basic(exception::MODULE_IOFILEFIFO, FIFOEX__WRITESTR EAM, 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__); 571 574 } 572 575 … … 575 578 } 576 579 577 b lockSize = _blockSize;580 bs = _bs; 578 581 } catch (...) { 579 b lockSize = _blockSize;582 bs = _bs; 580 583 581 584 throw; 582 585 } 583 } 584 585 //------------------------------------------------------------------- 586 587 return written; 588 } 589 590 //------------------------------------------------------------------- -
src/src/ioFileRegular.cc
r1386 r1389 84 84 throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX_REGULAR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 85 85 } 86 } else 86 } else { 87 87 exists = true; 88 } 88 89 89 90 if (exists && !S_ISREG(st.st_mode) && !S_ISBLK(st.st_mode)) { … … 144 145 #endif 145 146 146 block = fd.block;147 147 append = fd.append; 148 148 pos = fd.pos; 149 b lockSize = fd.blockSize;149 bs = fd.bs; 150 150 151 151 if (fd.handle->file != NULL) { … … 241 241 mode = fd.mode; 242 242 pos = fd.pos; 243 block = fd.block;244 243 append = fd.append; 245 b lockSize = fd.blockSize;244 bs = fd.bs; 246 245 247 246 if (fd.handle->file != NULL) { … … 371 370 //------------------------------------------------------------------- 372 371 373 void 374 regular::_read(char * const a_data) const372 unsigned long 373 regular::_read(char * const data) const 375 374 { 376 375 if (handle->file == NULL) 377 376 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;380 377 381 378 if (fseek(handle->file, pos, SEEK_SET) == -1) 382 379 throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__READ, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 383 380 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 410 unsigned long 411 regular::_write(const char *const data) const 404 412 { 405 413 if (handle->file == NULL) … … 410 418 throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 411 419 } else { 412 unsigned long pos = block ? this->pos * blockSize : this->pos;413 414 420 if (fseek(handle->file, pos, SEEK_SET) == -1) 415 421 throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 416 422 } 417 423 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; 432 449 } 433 450 … … 439 456 pc::sync::stack pg(keeper); 440 457 441 char *empty = new char[b lockSize];442 443 memset(empty, 0, b lockSize);458 char *empty = new char[bs]; 459 460 memset(empty, 0, bs); 444 461 try { 445 462 _write(empty); … … 470 487 471 488 unsigned 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); 489 regular::_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); 503 498 504 499 while (true) { 505 if (fgets( a_data, readSize, handle->file) == NULL) {500 if (fgets(data, readSize, handle->file) == NULL) { 506 501 if (errno == EINTR) 507 502 continue; … … 511 506 512 507 if (ferror(handle->file) != 0) 513 throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__READSTR EAM, 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__); 514 509 } 515 510 … … 517 512 } 518 513 519 return strlen( a_data);520 } 521 522 //------------------------------------------------------------------- 523 524 void 525 regular::_writeString(const char *const a_data) const526 { 527 if (handle->file == NULL) 528 throw exception::basic(exception::MODULE_IOFILEREGULAR, REGULAREX__WRITESTR EAM, exception::ERRNO_LIBDODO, REGULAREX_NOTOPENED, IOFILEREGULAREX_NOTOPENED_STR, __LINE__, __FILE__, path);514 return strlen(data); 515 } 516 517 //------------------------------------------------------------------- 518 519 unsigned long 520 regular::_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); 529 524 530 525 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 40 40 #include <libdodo/ioFileTemp.h> 41 41 #include <libdodo/ioFileTempEx.h> 42 #include <libdodo/ioFileRegular.h> 42 43 #include <libdodo/types.h> 43 44 #include <libdodo/ioChannel.h> … … 49 50 temp::temp(bool open, 50 51 short protection) : block::channel(protection), 51 block(true), 52 append(false), 53 overwrite(false), 54 handle(new io::__file__) 52 regular(protection) 55 53 { 56 54 #ifndef IO_WO_XEXEC … … 71 69 72 70 temp::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) 78 72 { 79 73 #ifndef IO_WO_XEXEC … … 81 75 #endif 82 76 77 handle = new io::__file__; 78 79 append = fd.append; 83 80 pos = fd.pos; 84 b lockSize = fd.blockSize;81 bs = fd.bs; 85 82 86 83 if (fd.handle->file != NULL) { … … 123 120 //------------------------------------------------------------------- 124 121 125 int126 temp::inDescriptor() const127 {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 int139 temp::outDescriptor() const140 {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 151 122 void 152 123 temp::clone(const temp &fd) … … 161 132 } 162 133 163 overwrite = fd.overwrite;164 134 pos = fd.pos; 165 block = fd.block;166 135 append = fd.append; 167 b lockSize = fd.blockSize;136 bs = fd.bs; 168 137 169 138 if (fd.handle->file != NULL) { … … 183 152 throw exception::basic(exception::MODULE_IOFILETEMP, TEMPEX_CLONE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 184 153 } 185 }186 187 //-------------------------------------------------------------------188 189 void190 temp::close()191 {192 pc::sync::stack pg(keeper);193 194 #ifndef IO_WO_XEXEC195 performPreExec(OPERATION_CLOSE);196 #endif197 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_XEXEC206 performPostExec(OPERATION_CLOSE);207 #endif208 154 } 209 155 … … 237 183 //------------------------------------------------------------------- 238 184 239 void240 temp::_read(char * const a_data) const241 {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 void269 temp::_write(const char *const a_data) const270 {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 void316 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 void345 temp::flush() const346 {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 long359 temp::_readString(char * const a_data) const360 {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 void412 temp::_writeString(const char *const a_data) const413 {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 100 100 } 101 101 102 block = fd.block;103 102 append = fd.append; 104 103 pos = fd.pos; 105 b lockSize = fd.blockSize;104 bs = fd.bs; 106 105 } 107 106 … … 182 181 183 182 pos = fd.pos; 184 block = fd.block;185 183 append = fd.append; 186 b lockSize = fd.blockSize;184 bs = fd.bs; 187 185 flags = fd.flags; 188 186 size = fd.size; … … 197 195 //------------------------------------------------------------------- 198 196 199 void 197 unsigned long 200 198 memory::_read(char * const a_data) const 201 199 { 202 unsigned long pos = block ? this->pos * blockSize : this->pos; 203 204 if ((pos + blockSize) > size) 200 if (pos + bs > size) 205 201 throw exception::basic(exception::MODULE_IOMEMORY, MEMORYEX__READ, exception::ERRNO_LIBDODO, MEMORYEX_OUTOFBOUNDS, IOMEMORYEX_OUTOFBOUNDS_STR, __LINE__, __FILE__); 206 202 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 210 unsigned long 213 211 memory::_write(const char *const a_data) const 214 212 { 215 213 if (append) { 216 if (flags & FLAGS_FIXED_LENGTH) 214 if (flags & FLAGS_FIXED_LENGTH) { 217 215 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 + b lockSize];216 } else { 217 char *newData = new char[size + bs]; 220 218 memcpy(newData, data, size); 221 memcpy(newData + size, a_data, b lockSize);222 size += b lockSize;219 memcpy(newData + size, a_data, bs); 220 size += bs; 223 221 delete [] data; 224 222 data = newData; 225 223 } 226 224 } else { 227 unsigned long pos = block ? this->pos * blockSize : this->pos; 228 229 unsigned long shift = pos + blockSize; 225 unsigned long shift = pos + bs; 230 226 if (shift > size) { 231 if (flags & FLAGS_FIXED_LENGTH) 227 if (flags & FLAGS_FIXED_LENGTH) { 232 228 throw exception::basic(exception::MODULE_IOMEMORY, MEMORYEX__WRITE, exception::ERRNO_LIBDODO, MEMORYEX_EXTENDFIXED, IOMEMORYEX_EXTENDFIXED_STR, __LINE__, __FILE__); 233 else {229 } else { 234 230 shift -= size; 235 231 char *newData = new char[size + shift]; … … 242 238 } 243 239 244 memcpy(data + pos, a_data, blockSize); 245 } 240 memcpy(data + pos, a_data, bs); 241 } 242 243 return bs; 246 244 } 247 245 … … 253 251 pc::sync::stack pg(keeper); 254 252 255 unsigned long pos = block ? this->pos * blockSize : this->pos; 256 257 unsigned long shift = pos + blockSize; 253 unsigned long shift = pos + bs; 258 254 if (shift > size) { 259 if (flags & FLAGS_FIXED_LENGTH) 255 if (flags & FLAGS_FIXED_LENGTH) { 260 256 throw exception::basic(exception::MODULE_IOMEMORY, MEMORYEX_ERASE, exception::ERRNO_LIBDODO, MEMORYEX_EXTENDFIXED, IOMEMORYEX_EXTENDFIXED_STR, __LINE__, __FILE__); 261 else {257 } else { 262 258 shift -= size; 263 259 char *newData = new char[size + shift]; … … 270 266 } 271 267 272 memset(data + pos, 0x0, b lockSize);268 memset(data + pos, 0x0, bs); 273 269 } 274 270 … … 278 274 memory::_readString(char * const a_data) const 279 275 { 280 unsigned long readSize = blockSize + 1; 281 282 memset(a_data, '\0', readSize); 276 unsigned long readSize = bs + 1; 283 277 284 278 unsigned long read = 0; 285 279 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; 317 287 } 318 288 … … 322 292 //------------------------------------------------------------------- 323 293 324 void 294 unsigned long 325 295 memory::_writeString(const char *const a_data) const 326 296 { 327 297 if (flags & FLAGS_FIXED_LENGTH) 328 throw exception::basic(exception::MODULE_IOMEMORY, MEMORYEX__WRITESTR EAM, exception::ERRNO_LIBDODO, MEMORYEX_EXTENDFIXED, IOMEMORYEX_EXTENDFIXED_STR, __LINE__, __FILE__);329 330 unsigned long _b lockSize = strnlen(a_data, blockSize);331 332 char *newData = new char[size + _b lockSize+ 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]; 333 303 memcpy(newData, data, size); 334 memcpy(newData + size, a_data, _b lockSize);335 size += _b lockSize;304 memcpy(newData + size, a_data, _bs); 305 size += _bs; 336 306 newData[size] = '\0'; 337 307 delete [] data; 338 308 data = newData; 339 309 nullEnd = true; 340 } 341 342 //------------------------------------------------------------------- 343 310 311 return _bs; 312 } 313 314 //------------------------------------------------------------------- 315 -
src/src/ioNetworkExchange.cc
r1386 r1389 127 127 128 128 void 129 exchange::init(int a_socket,129 exchange::init(int dataocket, 130 130 bool a_blocked, 131 131 bool blockInherited) … … 140 140 141 141 blocked = a_blocked; 142 socket = a_socket;142 socket = dataocket; 143 143 144 144 setInBufferSize(inSocketBufferSize); … … 186 186 //------------------------------------------------------------------- 187 187 188 void 189 exchange::_write(const char * const a_data) const188 unsigned long 189 exchange::_write(const char * const data) const 190 190 { 191 191 if (socket == -1) 192 192 throw exception::basic(exception::MODULE_IONETWORKEXCHANGE, EXCHANGEEX__WRITE, exception::ERRNO_LIBDODO, EXCHANGEEX_NOCONNECTION, IONETWORKEXCHANGEEX_NOCONNECTION_STR, __LINE__, __FILE__); 193 193 194 unsigned long iter = b lockSize/ outSocketBufferSize;195 unsigned long rest = b lockSize% 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; 198 198 199 199 long batch, n; … … 203 203 while (batch > 0) { 204 204 while (true) { 205 if ((n = ::send(socket, data, batch, 0)) == -1) {205 if ((n = ::send(socket, s, batch, 0)) == -1) { 206 206 if (errno == EINTR) 207 207 continue; 208 208 209 209 if (errno == EAGAIN) 210 break;210 return s - data; 211 211 212 212 throw exception::basic(exception::MODULE_IONETWORKEXCHANGE, EXCHANGEEX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 217 217 218 218 batch -= n; 219 data+= n;219 s += n; 220 220 } 221 221 } … … 225 225 while (batch > 0) { 226 226 while (true) { 227 if ((n = ::send(socket, data, batch, 0)) == -1) {227 if ((n = ::send(socket, s, batch, 0)) == -1) { 228 228 if (errno == EINTR) 229 229 continue; 230 230 231 231 if (errno == EAGAIN) 232 break;232 return s - data; 233 233 234 234 throw exception::basic(exception::MODULE_IONETWORKEXCHANGE, EXCHANGEEX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 239 239 240 240 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 250 unsigned long 251 exchange::_read(char * const data) const 250 252 { 251 253 if (socket == -1) 252 254 throw exception::basic(exception::MODULE_IONETWORKEXCHANGE, EXCHANGEEX__READ, exception::ERRNO_LIBDODO, EXCHANGEEX_NOCONNECTION, IONETWORKEXCHANGEEX_NOCONNECTION_STR, __LINE__, __FILE__); 253 255
