certi-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

certi libCERTI/MessageBuffer.cc libCERTI/Messag...


From: certi-cvs
Subject: certi libCERTI/MessageBuffer.cc libCERTI/Messag...
Date: Tue, 26 Feb 2008 09:58:35 +0000

CVSROOT:        /sources/certi
Module name:    certi
Changes by:     Eric NOULARD <erk>      08/02/26 09:58:34

Modified files:
        libCERTI       : MessageBuffer.cc MessageBuffer.hh 
        test/utility   : CertiUtilTests.cc 

Log message:
        MessageBuffer should be ready to use for NetworkMessage

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/MessageBuffer.cc?cvsroot=certi&r1=3.4&r2=3.5
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/MessageBuffer.hh?cvsroot=certi&r1=3.3&r2=3.4
http://cvs.savannah.gnu.org/viewcvs/certi/test/utility/CertiUtilTests.cc?cvsroot=certi&r1=1.5&r2=1.6

Patches:
Index: libCERTI/MessageBuffer.cc
===================================================================
RCS file: /sources/certi/certi/libCERTI/MessageBuffer.cc,v
retrieving revision 3.4
retrieving revision 3.5
diff -u -b -r3.4 -r3.5
--- libCERTI/MessageBuffer.cc   15 Feb 2008 15:24:03 -0000      3.4
+++ libCERTI/MessageBuffer.cc   26 Feb 2008 09:58:34 -0000      3.5
@@ -131,6 +131,22 @@
        readOffset            = 0;
 } /* MessageBuffer::resetBuffer() */
 
+uint32_t MessageBuffer::resize(uint32_t newSize) {
+       reallocate(newSize);
+}
+void MessageBuffer::assumeSize(uint32_t size) {
+       /* this is done in order to overflow 
+        * buffer max size but this may well be
+        * an error (FIXME should throw an exception ?) 
+        */
+       if (size <= bufferMaxSize) {
+               writeOffset       = size;
+       } else {
+           writeOffset       = bufferMaxSize;
+       }
+       readOffset            = 0;
+}
+
 int32_t MessageBuffer::write_uint8s(const uint8_t* data, uint32_t n) {
 
        if (n >= (bufferMaxSize - writeOffset)) {

Index: libCERTI/MessageBuffer.hh
===================================================================
RCS file: /sources/certi/certi/libCERTI/MessageBuffer.hh,v
retrieving revision 3.3
retrieving revision 3.4
diff -u -b -r3.3 -r3.4
--- libCERTI/MessageBuffer.hh   15 Feb 2008 13:24:07 -0000      3.3
+++ libCERTI/MessageBuffer.hh   26 Feb 2008 09:58:34 -0000      3.4
@@ -110,6 +110,24 @@
   void 
   resetBuffer();
   
+       /**
+        * Resize the current maximum buffer size (in bytes).
+        * This is the size of the allocated buffer.
+        * @param[in] the new buffer maximum size
+        * @return the new buffer maximum size
+        */
+       uint32_t resize(uint32_t newSize);
+
+       /**
+        * Assume that the underlying buffer has 
+        * the specified size.
+        * This may be used after ones get raw pointer 
+        * to the underlying buffer and has written to the buffer
+        * using memcpy/recv.
+        * @param[in] size the assumed size
+        */
+       void assumeSize(uint32_t size);
+
 #define DECLARE_SIGNED(type)                           \
   int32_t                                              \
   write_##type##s(const type##_t* data, uint32_t n) {          \
@@ -249,4 +267,3 @@
 } // certi
 
 #endif // LIBCERTI_MESSAGE_BUFFER_HH
-

Index: test/utility/CertiUtilTests.cc
===================================================================
RCS file: /sources/certi/certi/test/utility/CertiUtilTests.cc,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- test/utility/CertiUtilTests.cc      15 Feb 2008 14:34:27 -0000      1.5
+++ test/utility/CertiUtilTests.cc      26 Feb 2008 09:58:34 -0000      1.6
@@ -153,6 +153,7 @@
        
        cout << "    Trying to overload the buffer..." <<endl;
        cout << "    Current (Default) MessageBuffer MaxSize               = 
"<< MsgBuf.maxSize() <<endl;
+       MsgBuf.resetBuffer();
        u32 = MsgBuf.maxSize()*2;
        vstr = new char[u32+1];
        vstr[u32]='\0';
@@ -160,10 +161,20 @@
        MsgBuf.write_uint32(u32);
        MsgBuf.write_chars(vstr,u32);   
        cout << "    Written char* is " << vstr << endl;
+       u32 = MsgBuf.size();
        delete[] vstr;
        cout << "    Current           MessageBuffer MaxSize               = 
"<< MsgBuf.maxSize() <<endl;
        vstdstr = MsgBuf.read_string();
        cout << "    Read String is   " << vstdstr << endl;
+       cout << "    Forcibly resize the buffer to "<< MsgBuf.maxSize()*2 << 
endl;
+       MsgBuf.resize(MsgBuf.maxSize()*2);
+       cout << "    Current           MessageBuffer MaxSize               = 
"<< MsgBuf.maxSize() <<endl;
+    cout << "    Now reset buffer and assume size is                   = "<< 
u32 << endl;      
+       MsgBuf.resetBuffer();
+       MsgBuf.assumeSize(u32);
+       vstdstr = "";
+       vstdstr = MsgBuf.read_string();
+       cout << "    (re)Read String is   " << vstdstr << endl;
        cout << "Testing MessageBuffer class END."<<endl;
 } /* end of messageBufferTests */
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]