예제 #1
0
		std::string 
		_gb_mmu::to_string(
			__in_opt bool verb,
			__in_opt gb_addr_t addr,
			__in_opt gbw_t off
			)
		{
			gb_buf_t buf;
			std::stringstream res;		

			res << "[" << (m_init ? "INIT" : "UNINIT") << "] " << GB_MMU_HEADER
				<< " (ptr=0x" << VAL_AS_HEX(gb_mmu_ptr, this) << ")";
			
			if(verb) {			

				if(m_init && off) {

					if((addr + off) > GB_MMU_MAX_ADDR) {
						off -= ((addr + off) - GB_MMU_MAX_ADDR - 1);
					}

					buf = gb_buf_t(m_buf.begin() + addr, m_buf.begin() + addr + off);
					res << std::endl << buffer_as_string(buf, true, addr);
				}
			}
			
			return res.str();
		}
예제 #2
0
/**
 * Reads data from a socket and parses the incoming data into a BLKMessage
 *
 * If a message is parsed it is returned in the ref argument msg and function returns true
 * If somethings goes wrong the function returns false and the status indocates the problem
 *
 *  BLK_READ_STATUS_EOF         -   got an EOF and no data
 *  BLK_READ_STATUS_PARSE_ERROR -   the data was not parsed successfully
 *  BLK_READ_STATUS_IOERROR     -   got an io error on the socket
 */
bool BlkSocket::readMessage(BlkMessage& msg, int& status)
{
    int buffer_length = 10000;
    char buffer[buffer_length];
    
    BlkParser parser(msg);
    int sockStatus;
    
    for(;;){
        int n = socket_read_data(socket, buffer, buffer_length, &sockStatus);
        
        std::string buffer_as_string(buffer, n);
        
        if( sockStatus == SOCKET_STATUS_GOOD){
            status = BLK_READ_STATUS_OK;
            //
            // NOTE - do not return
            //
        }else if(sockStatus == SOCKET_STATUS_EOF){
            status = BLK_READ_STATUS_EOF;
            return false;
        }else if(sockStatus == SOCKET_STATUS_ERROR){
            status = BLK_READ_STATUS_IOERROR;
            return false;
        }else{
            assert(false);
        }
        parser.append(buffer, n);
        if( parser.messageComplete ){
            return true;
        }
        if( parser.parseError ){
            status = BLK_READ_STATUS_PARSE_ERROR;
            return false;
        }
    }
    return true;
}