* but in previous frame of stack, m_receive_trans has not finished reading,
*/
Transaction _tran;
- _tran = m_receive_trans;
+ _tran.deep_copy (m_receive_trans);
m_continue_mark = STATUS_NONE;
socket_receive_callback (&m_socket_server, socket_client);
- m_receive_trans = _tran;
+ m_receive_trans.deep_copy (_tran);
ContinueMark status = get_continue_mark ();
if (status == STATUS_DISCONNECT)
return false;
cont = true;
while (true) {
Transaction _tran;
- _tran = m_receive_trans;
+ _tran.deep_copy (m_receive_trans);
m_continue_mark = STATUS_NONE;
socket_receive_callback (&m_socket_server, socket_client);
- m_receive_trans = _tran;
+ m_receive_trans.deep_copy (_tran);
ContinueMark status = get_continue_mark ();
if (status == STATUS_DISCONNECT)
return false;
{
mutable int m_ref;
+ TransactionHolder (const TransactionHolder &);
+ TransactionHolder & operator = (const TransactionHolder &);
+
public:
size_t m_buffer_size;
size_t m_write_pos;
throw Exception ("TransactionHolder::TransactionHolder() Out of memory");
}
- TransactionHolder (TransactionHolder &other)
- : m_ref (other.m_ref),
- m_buffer_size (other.m_buffer_size),
- m_write_pos (other.m_write_pos),
- m_buffer ((unsigned char*) malloc (other.m_buffer_size)) {
- if (!m_buffer)
- throw Exception ("TransactionHolder::TransactionHolder() Out of memory");
-
- if (m_buffer_size && m_buffer)
- memcpy (m_buffer, other.m_buffer, m_buffer_size);
- }
-
~TransactionHolder () {
free (m_buffer);
}
- TransactionHolder & operator = (const TransactionHolder &other) {
- m_ref = other.m_ref;
- m_buffer_size = other.m_buffer_size;
- m_write_pos = other.m_write_pos;
- if (m_buffer)
- free (m_buffer);
-
- m_buffer = (unsigned char*) malloc (other.m_buffer_size);
- if (!m_buffer)
- throw Exception ("TransactionHolder::TransactionHolder() Out of memory");
-
- if (m_buffer_size && m_buffer)
- memcpy (m_buffer, other.m_buffer, m_buffer_size);
-
- return *this;
- }
-
bool valid () const {
return m_buffer && m_buffer_size;
}
m_reader->attach (*this);
}
-Transaction &
-Transaction::operator = (const Transaction & _tran)
+void
+Transaction::deep_copy(const Transaction & _tran)
{
- m_holder->request_buffer_size (_tran.get_size());
- _tran.write_to_buffer (m_holder->m_buffer,_tran.get_size());
+ m_reader->detach ();
+ m_holder->unref ();
+ m_holder = new TransactionHolder (_tran.get_size ());
+ m_holder->ref ();
+ m_reader->attach (*this);
+
+ m_holder->request_buffer_size (_tran.get_size ());
+ _tran.write_to_buffer (m_holder->m_buffer,_tran.get_size ());
m_holder->m_write_pos = _tran.get_size ();
m_reader->set_position (_tran.m_reader->get_position ());
- return *this;
}
Transaction::~Transaction ()
TransactionReader * m_reader;
Transaction (const Transaction &);
+ Transaction & operator = (const Transaction &);
public:
/**
* @brief Constructor.
*/
~Transaction ();
- Transaction & operator = (const Transaction &);
+ /**
+ * @brief Copy the transaction in a new data holder.
+ */
+ void deep_copy(const Transaction &);
/**
* @brief Check if the transaction is valid.