예제 #1
0
  int Binlog_file_driver::wait_for_next_event(mysql::Binary_log_event **event)
  {

    assert(m_binlog_file.tellg() >= 4 );
    m_binlog_file.exceptions(ifstream::failbit | ifstream::badbit |
                             ifstream::eofbit);

    try
    {
      if(m_bytes_read < m_binlog_file_size && m_binlog_file.good())
      {
        //Protocol_chunk<uint8_t> prot_marker(m_event_log_header.marker);
        Protocol_chunk<uint32_t> prot_timestamp(m_event_log_header.timestamp);
        Protocol_chunk<uint8_t> prot_type_code(m_event_log_header.type_code);
        Protocol_chunk<uint32_t> prot_server_id(m_event_log_header.server_id);
        Protocol_chunk<uint32_t>
          prot_event_length(m_event_log_header.event_length);
        Protocol_chunk<uint32_t>
          prot_next_position(m_event_log_header.next_position);
        Protocol_chunk<uint16_t> prot_flags(m_event_log_header.flags);

        m_binlog_file >> prot_timestamp
                      >> prot_type_code
                      >> prot_server_id
                      >> prot_event_length
                      >> prot_next_position
                      >> prot_flags;

        /*
        m_binlog_file.read(reinterpret_cast<char*>
                           (&m_event_log_header.timestamp),sizeof(uint32_t));
        m_binlog_file.read(reinterpret_cast<char*>
                           (&m_event_log_header.type_code),sizeof(uint8_t));
        m_binlog_file.read(reinterpret_cast<char*>
                           (&m_event_log_header.server_id),sizeof(uint32_t));
        m_binlog_file.read(reinterpret_cast<char*>
                          (&m_event_log_header.event_length),sizeof(uint32_t));
        m_binlog_file.read(reinterpret_cast<char*>(
                         (&m_event_log_header.next_position),sizeof(uint32_t));
        m_binlog_file.read(reinterpret_cast<char*>(&m_event_log_header.flags),
                           sizeof(uint16_t));
                           */

        *event= parse_event(* static_cast<std::istream*> (&m_binlog_file),
                            &m_event_log_header);

        /*
          Correction.Except for the default case (above), this condition should
          always fail.
        */
        if (m_bytes_read + m_event_log_header.event_length !=
            (size_t)m_binlog_file.tellg())
          m_binlog_file.seekg(m_bytes_read + m_event_log_header.event_length,
                              ios::beg);

        m_bytes_read= m_binlog_file.tellg();

        if(*event)
        {
          if ((*event)->header()->type_code == mysql::FORMAT_DESCRIPTION_EVENT)
          {
            // Check server version and the checksum value
            int ret= check_checksum_value(event);
            return ret; // ret is the error code
          }
        }
        return ERR_OK;
      }
      else
        disconnect();
    } catch(...)
  int Binlog_file_driver::wait_for_next_event(mysql::Binary_log_event **event)
  {

    assert(m_binlog_file.tellg() >= 4 );
    m_binlog_file.exceptions(ifstream::failbit | ifstream::badbit |
                             ifstream::eofbit);

    try
    {
      if(m_bytes_read < m_binlog_file_size && m_binlog_file.good())
      {
        //Protocol_chunk<uint8_t> prot_marker(m_event_log_header.marker);
        Protocol_chunk<uint32_t> prot_timestamp(m_event_log_header.timestamp);
        Protocol_chunk<uint8_t> prot_type_code(m_event_log_header.type_code);
        Protocol_chunk<uint32_t> prot_server_id(m_event_log_header.server_id);
        Protocol_chunk<uint32_t>
          prot_event_length(m_event_log_header.event_length);
        Protocol_chunk<uint32_t>
          prot_next_position(m_event_log_header.next_position);
        Protocol_chunk<uint16_t> prot_flags(m_event_log_header.flags);

        m_binlog_file >> prot_timestamp
                      >> prot_type_code
                      >> prot_server_id
                      >> prot_event_length
                      >> prot_next_position
                      >> prot_flags;

        /*
        m_binlog_file.read(reinterpret_cast<char*>(&m_event_log_header.timestamp),
                           sizeof(uint32_t));
        m_binlog_file.read(reinterpret_cast<char*>(&m_event_log_header.type_code),
                           sizeof(uint8_t));
        m_binlog_file.read(reinterpret_cast<char*>(&m_event_log_header.server_id),
                           sizeof(uint32_t));
        m_binlog_file.read(reinterpret_cast<char*>(&m_event_log_header.event_length),
                           sizeof(uint32_t));
        m_binlog_file.read(reinterpret_cast<char*>(&m_event_log_header.next_position),
                           sizeof(uint32_t));
        m_binlog_file.read(reinterpret_cast<char*>(&m_event_log_header.flags),
                           sizeof(uint16_t));
                           */

        *event= parse_event(* static_cast<std::istream*> (&m_binlog_file),
                            &m_event_log_header);

        /*
          Correction. Except for the default case (above), this condition should
          always fail.
        */
        if (m_bytes_read + m_event_log_header.event_length !=
            m_binlog_file.tellg())
          m_binlog_file.seekg(m_bytes_read + m_event_log_header.event_length,
                              ios::beg);

        m_bytes_read= m_binlog_file.tellg();

        if(*event)
          return ERR_OK;
      }
    } catch(...)
    {
      return ERR_FAIL;
    }
    return ERR_EOF;
  }