TEST_F(positive_test_connection_to_levin_protocol_handler_calls, handler_processes_handle_read_as_notify)
{
  // Setup
  const int expected_command = 4673261;

  test_connection_ptr conn = create_connection();

  std::string in_data(256, 'e');

  epee::levin::bucket_head2 req_head;
  req_head.m_signature = LEVIN_SIGNATURE;
  req_head.m_cb = in_data.size();
  req_head.m_have_to_return_data = false;
  req_head.m_command = expected_command;
  req_head.m_flags = LEVIN_PACKET_REQUEST;
  req_head.m_protocol_version = LEVIN_PROTOCOL_VER_1;

  std::string buf(reinterpret_cast<const char*>(&req_head), sizeof(req_head));
  buf += in_data;

  // Test
  ASSERT_TRUE(conn->m_protocol_handler.handle_recv(buf.data(), buf.size()));

  // Check connection and levin_commands_handler states
  ASSERT_EQ(1, m_commands_handler.notify_counter());
  ASSERT_EQ(0, m_commands_handler.invoke_counter());
  ASSERT_EQ(expected_command, m_commands_handler.last_command());
  ASSERT_EQ(in_data, m_commands_handler.last_in_buf());
  ASSERT_LE(0, conn->send_counter());
  ASSERT_TRUE(conn->last_send_data().empty());
}
Esempio n. 2
0
	void LZMACodec::Decode(std::vector<uint8_t>& output, ResIdentifierPtr const & is, uint64_t len, uint64_t original_len)
	{
		std::vector<uint8_t> in_data(static_cast<size_t>(len));
		is->read(&in_data[0], static_cast<size_t>(len));

		this->Decode(output, &in_data[0], len, original_len);
	}
Esempio n. 3
0
/* called from corr_loop, to do the main calculations */
static void calc_corr(t_corr *curr, int nr, int nx, atom_id index[], rvec xc[],
                      gmx_bool bRmCOMM, rvec com, t_calc_func *calc1, gmx_bool bTen)
{
    int    nx0;
    real   g;
    matrix mat;
    rvec   dcom;

    /* Check for new starting point */
    if (curr->nlast < curr->nrestart)
    {
        if ((thistime(curr) >= (curr->nlast*curr->delta_t)) && (nr == 0))
        {
            std::memcpy(curr->x0[curr->nlast], xc, curr->ncoords*sizeof(xc[0]));
            curr->n_offs[curr->nlast] = curr->nframes;
            copy_rvec(com, curr->com[curr->nlast]);
            curr->nlast++;
        }
    }

    /* nx0 appears to be the number of new starting points,
     * so for all starting points, call calc1.
     */
    for (nx0 = 0; (nx0 < curr->nlast); nx0++)
    {
        if (bRmCOMM)
        {
            rvec_sub(com, curr->com[nx0], dcom);
        }
        else
        {
            clear_rvec(dcom);
        }
        g = calc1(curr, nx, index, nx0, xc, dcom, bTen, mat);
#ifdef DEBUG2
        printf("g[%d]=%g\n", nx0, g);
#endif
        curr->data[nr][in_data(curr, nx0)] += g;
        if (bTen)
        {
            m_add(curr->datam[nr][in_data(curr, nx0)], mat,
                  curr->datam[nr][in_data(curr, nx0)]);
        }
        curr->ndata[nr][in_data(curr, nx0)]++;
    }
}
TEST_F(positive_test_connection_to_levin_protocol_handler_calls, handler_processes_handle_read_as_invoke)
{
  // Setup
  const int expected_command = 2634981;
  const int expected_return_code = 6732;
  const std::string expected_out_data(128, 'w');

  test_connection_ptr conn = create_connection();

  std::string in_data(256, 'q');

  epee::levin::bucket_head2 req_head;
  req_head.m_signature = LEVIN_SIGNATURE;
  req_head.m_cb = in_data.size();
  req_head.m_have_to_return_data = true;
  req_head.m_command = expected_command;
  req_head.m_flags = LEVIN_PACKET_REQUEST;
  req_head.m_protocol_version = LEVIN_PROTOCOL_VER_1;

  std::string buf(reinterpret_cast<const char*>(&req_head), sizeof(req_head));
  buf += in_data;

  m_commands_handler.invoke_out_buf(expected_out_data);
  m_commands_handler.return_code(expected_return_code);

  // Test
  ASSERT_TRUE(conn->m_protocol_handler.handle_recv(buf.data(), buf.size()));

  //
  // Check
  //

  // Check connection and levin_commands_handler states
  ASSERT_EQ(1, m_commands_handler.invoke_counter());
  ASSERT_EQ(0, m_commands_handler.notify_counter());
  ASSERT_EQ(expected_command, m_commands_handler.last_command());
  ASSERT_EQ(in_data, m_commands_handler.last_in_buf());
  ASSERT_LE(1, conn->send_counter());

  // Parse send data
  std::string send_data = conn->last_send_data();
  epee::levin::bucket_head2 resp_head;
  resp_head = *reinterpret_cast<const epee::levin::bucket_head2*>(send_data.data());
  ASSERT_LT(sizeof(resp_head), send_data.size());
  std::string out_data = send_data.substr(sizeof(resp_head));

  // Check sent response
  ASSERT_EQ(expected_out_data, out_data);
  ASSERT_EQ(LEVIN_SIGNATURE, resp_head.m_signature);
  ASSERT_EQ(expected_command, resp_head.m_command);
  ASSERT_EQ(expected_return_code, resp_head.m_return_code);
  ASSERT_EQ(expected_out_data.size(), resp_head.m_cb);
  ASSERT_FALSE(resp_head.m_have_to_return_data);
  ASSERT_EQ(LEVIN_PROTOCOL_VER_1, resp_head.m_protocol_version);
  ASSERT_TRUE(0 != (resp_head.m_flags & LEVIN_PACKET_RESPONSE));
}
Esempio n. 5
0
	uint64_t LZMACodec::Decode(std::ostream& os, ResIdentifierPtr const & is, uint64_t len, uint64_t original_len)
	{
		std::vector<uint8_t> in_data(static_cast<size_t>(len));
		is->read(&in_data[0], static_cast<size_t>(len));

		std::vector<uint8_t> output;
		this->Decode(output, &in_data[0], len, original_len);

		os.write(reinterpret_cast<char*>(&output[0]), static_cast<std::streamsize>(output.size()));

		return output.size();
	}
Esempio n. 6
0
	void LZMACodec::Decode(void* output, void const * input, uint64_t len, uint64_t original_len)
	{
		uint8_t const * p = static_cast<uint8_t const *>(input);

		std::vector<uint8_t> in_data(static_cast<size_t>(len));
		std::memcpy(&in_data[0], p, static_cast<std::streamsize>(in_data.size()));

		SizeT s_out_len = static_cast<SizeT>(original_len);

		SizeT s_src_len = static_cast<SizeT>(len - LZMA_PROPS_SIZE);
		int res = LZMALoader::Instance().LzmaUncompress(static_cast<Byte*>(output), &s_out_len, &in_data[LZMA_PROPS_SIZE], &s_src_len,
			&in_data[0], LZMA_PROPS_SIZE);
		Verify(0 == res);
	}
Esempio n. 7
0
//根据回复更新RS的规则,这里需要保证更新的原子性
int GetRuleTask::get_new_rule_ack(InReq *req)
{
    MsgHeader header = req->m_msgHeader;
    std::string in_data(req->ioBuf , header.length);

    //如果RS已经是最新的规则了,那么这里就会返回空的负载数据
    if(0 == header.length)
    {
        LOG_EVENT("Get new rule from CS back , empty load data !");
        return 0;
    }

    cstore::pb_MSG_RS_CS_UPDATE_MU_HASH_ACK  in_mu_ack;
    cstore::pb_MSG_RS_CS_UPDATE_SU_HASH_ACK  in_su_ack;
    int sys_order_number = 0;
    std::list<cstore::Sys_Order>  sys_order_list;  
    
    //首先将所有的版本更新的信息保存在list中,再一一更新
    if(MU_RULER == m_type)
    {
        if(!in_mu_ack.ParseFromString(in_data))
        {
            LOG_ERROR("GetRuleTask::parse mu ack from protbuf error !");
            return -1;
        }
        sys_order_number = in_mu_ack.sys_order_size();
        for(int i = 0 ; i < sys_order_number ; ++ i)
        {
            sys_order_list.push_back(in_mu_ack.sys_order(i));
        }
    }
    else
    {
        if(!in_su_ack.ParseFromString(in_data))
        {
            LOG_ERROR("GetRuleTask::parse su ack from protbuf error !");
            return -1;
        }
        sys_order_number = in_su_ack.sys_order_size();
        for(int i = 0 ; i < sys_order_number ; ++ i)
        {
            sys_order_list.push_back(in_su_ack.sys_order(i));
        }
    }

    apply_all_new_rule(sys_order_list);

    return 0;
}
Esempio n. 8
0
  void out_of_place(BE *backend,
		    const_Vector<InT, Block0>& in,
		    Vector<OutT, Block1>& out)
  {
    {
      dda::Data<Block0, dda::in> in_data(in.block());
      dda::Data<Block1, dda::out> out_data(out.block());

      backend->out_of_place(in_data.ptr(),  in_data.stride(0),
			    out_data.ptr(), out_data.stride(0),
			    select_fft_size<InT, OutT>(in_data.size(0), out_data.size(0)));
    }

    // Scale the data if not already done by the backend.
    if (!backend->supports_scale() && !almost_equal(scale_, scalar_type(1.)))
      out *= scale_;
  }
Esempio n. 9
0
static int  test_compressor(const ::Compression::Compressor_var &compressor)
{
    if (::CORBA::is_nil(compressor.in())) {
        ACE_ERROR_RETURN((LM_ERROR,
            ACE_TEXT("ERROR: nil Compressor.\n")),-1);
    }

    ::CORBA::ULong  in_len = static_cast< CORBA::ULong>(sizeof(test_array));
    ::CORBA::Octet* in_buf = reinterpret_cast< CORBA::Octet*>(test_array);

    ::Compression::Buffer in_data(in_len, in_len, in_buf, false);

    ::Compression::Buffer comp_out;

    comp_out.length(static_cast< ::CORBA::ULong>(in_len * 1.1));

    {
      HRTimer _hrt(ACE_TEXT("Compress Time - "));
      compressor->compress(in_data, comp_out);
    }

    ACE_HEX_DUMP((  LM_INFO,
                    reinterpret_cast<const char*>(comp_out.get_buffer()),
                    comp_out.length(),
                    ACE_TEXT("Compressed Buffer")
                    ));

    ::Compression::Buffer decomp_out; decomp_out.length(1024);

    {
        HRTimer _hrt(ACE_TEXT("DeCompress Time - "));
        compressor->decompress(comp_out, decomp_out);
    }

    // Make sure we got back the original OK.
    if (ACE_OS::memcmp( in_data.get_buffer(), decomp_out.get_buffer(), in_data.length()))
    {
        ACE_ERROR_RETURN((LM_ERROR,
            ACE_TEXT("ERROR: Did not Compress/Decompress correctly.\n")),-1);
    }

    ACE_ERROR_RETURN((LM_INFO, ACE_TEXT("\n********* END TEST ************\n")), 0);
}
Esempio n. 10
0
static real calc1_mol(t_corr *curr,int nx,atom_id index[],int nx0,rvec xc[],
		      rvec dcom,gmx_bool bTen,matrix mat, const output_env_t oenv)
{
  int  i;
  real g,tm,gtot,tt;

  tt = curr->time[in_data(curr,nx0)];
  gtot = 0;
  tm = 0;
  clear_mat(mat);
  for(i=0; (i<nx); i++) {
    g = calc_one_mw(curr,i,nx0,xc,&tm,dcom,bTen,mat);
    /* We don't need to normalize as the mass was set to 1 */
    gtot += g;
    if (tt >= curr->beginfit && (curr->endfit < 0 || tt <= curr->endfit))
      gmx_stats_add_point(curr->lsq[nx0][i],tt,g,0,0);
  }
  msmul(mat,1.0/nx,mat);

  return gtot/nx;
}
Esempio n. 11
0
	void KFont::GetDistanceData(uint8_t* p, uint32_t pitch, int32_t index) const
	{
		std::vector<uint8_t> decoded(char_size_ * char_size_);

		uint32_t size;
		this->GetLZMADistanceData(nullptr, size, index);

		std::vector<uint8_t> in_data(size);
		this->GetLZMADistanceData(&in_data[0], size, index);

		SizeT s_out_len = static_cast<SizeT>(decoded.size());

		SizeT s_src_len = static_cast<SizeT>(in_data.size() - LZMA_PROPS_SIZE);
		LZMALoader::Instance().LzmaUncompress(static_cast<Byte*>(&decoded[0]), &s_out_len, &in_data[LZMA_PROPS_SIZE], &s_src_len,
			&in_data[0], LZMA_PROPS_SIZE);

		uint8_t const * char_data = &decoded[0];
		for (uint32_t y = 0; y < char_size_; ++ y)
		{
			std::memcpy(p, char_data, char_size_);
			p += pitch;
			char_data += char_size_;
		}
	}
Esempio n. 12
0
int
main(int argc, char *argv[])
{
	int i, n;
	struct interface *ifp;
	int c;
	struct timeval waittime;
	int timeout;
	boolean_t daemon = _B_TRUE;	/* Fork off a detached daemon */
	FILE *pidfp;
	mode_t pidmode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); /* 0644 */

	rip6_port = htons(IPPORT_ROUTESERVER6);
	allrouters.sin6_family = AF_INET6;
	allrouters.sin6_port = rip6_port;
	allrouters.sin6_addr = allrouters_in6;

	while ((c = getopt(argc, argv, "nsqvTtdgPp:")) != EOF) {
		switch (c) {
		case 'n':
			install = _B_FALSE;
			break;
		case 's':
			supplier = _B_TRUE;
			break;
		case 'q':
			supplier = _B_FALSE;
			break;
		case 'v':
			tracing |= ACTION_BIT;
			break;
		case 'T':
			daemon = _B_FALSE;
			break;
		case 't':
			tracepackets = _B_TRUE;
			daemon = _B_FALSE;
			tracing |= (INPUT_BIT | OUTPUT_BIT);
			break;
		case 'd':
			break;
		case 'P':
			dopoison = _B_FALSE;
			break;
		case 'p':
			rip6_port = htons(atoi(optarg));
			allrouters.sin6_port = rip6_port;
			break;
		default:
			usage(argv[0]);
			/* NOTREACHED */
		}
	}

	/*
	 * Any extra argument is considered
	 * a tracing log file.
	 */
	if (optind < argc) {
		traceon(argv[optind]);
	} else if (tracing && !daemon) {
		traceonfp(stdout);
	} else if (tracing) {
		(void) fprintf(stderr, "Need logfile with -v\n");
		usage(argv[0]);
		/* NOTREACHED */
	}

	if (daemon) {
		int t;

		if (fork())
			exit(EXIT_SUCCESS);
		for (t = 0; t < 20; t++) {
			if (!tracing || (t != fileno(ftrace)))
				(void) close(t);
		}
		(void) open("/", 0);
		(void) dup2(0, 1);
		(void) dup2(0, 2);
		(void) setsid();
	}

	/* Store our process id, blow away any existing file if it exists. */
	if ((pidfp = fopen(PATH_PID, "w")) == NULL) {
		(void) fprintf(stderr, "%s: unable to open " PATH_PID ": %s\n",
		    argv[0], strerror(errno));
	} else {
		(void) fprintf(pidfp, "%ld\n", getpid());
		(void) fclose(pidfp);
		(void) chmod(PATH_PID, pidmode);
	}


	iocsoc = socket(AF_INET6, SOCK_DGRAM, 0);
	if (iocsoc < 0) {
		syslog(LOG_ERR, "main: socket: %m");
		exit(EXIT_FAILURE);
	}

	setup_rtsock();

	/*
	 * Allocate the buffer to hold the RIPng packet.  In reality, it will be
	 * smaller than IPV6_MAX_PACKET octets due to (at least) the IPv6 and
	 * UDP headers but IPV6_MAX_PACKET is a convenient size.
	 */
	packet = (char *)malloc(IPV6_MAX_PACKET);
	if (packet == NULL) {
		syslog(LOG_ERR, "main: malloc: %m");
		exit(EXIT_FAILURE);
	}
	msg = (struct rip6 *)packet;

	/*
	 * Allocate the buffer to hold the ancillary data.  This data is used to
	 * insure that the incoming hop count of a RIPCMD6_RESPONSE message is
	 * IPV6_MAX_HOPS which indicates that it came from a direct neighbor
	 * (namely, no intervening router decremented it).
	 */
	control = (char *)malloc(IPV6_MAX_PACKET);
	if (control == NULL) {
		syslog(LOG_ERR, "main: malloc: %m");
		exit(EXIT_FAILURE);
	}

	openlog("in.ripngd", LOG_PID | LOG_CONS, LOG_DAEMON);

	(void) gettimeofday(&now, (struct timezone *)NULL);

	initifs();
	solicitall(&allrouters);

	if (supplier)
		supplyall(&allrouters, 0, (struct interface *)NULL, _B_TRUE);

	(void) sigset(SIGALRM, (void (*)(int))timer);
	(void) sigset(SIGHUP, (void (*)(int))initifs);
	(void) sigset(SIGTERM, (void (*)(int))term);
	(void) sigset(SIGUSR1, (void (*)(int))if_dump);
	(void) sigset(SIGUSR2, (void (*)(int))rtdump);

	/*
	 * Seed the pseudo-random number generator for GET_RANDOM().
	 */
	srandom((uint_t)gethostid());

	timer();

	for (;;) {
		if (needupdate) {
			waittime = nextmcast;
			timevalsub(&waittime, &now);
			if (waittime.tv_sec < 0) {
				timeout = 0;
			} else {
				timeout = TIME_TO_MSECS(waittime);
			}
			if (tracing & ACTION_BIT) {
				(void) fprintf(ftrace,
				    "poll until dynamic update in %d msec\n",
				    timeout);
				(void) fflush(ftrace);
			}
		} else {
			timeout = INFTIM;
		}

		if ((n = poll(poll_ifs, poll_ifs_num, timeout)) < 0) {
			if (errno == EINTR)
				continue;
			syslog(LOG_ERR, "main: poll: %m");
			exit(EXIT_FAILURE);
		}
		(void) sighold(SIGALRM);
		(void) sighold(SIGHUP);
		/*
		 * Poll timed out.
		 */
		if (n == 0) {
			if (needupdate) {
				TRACE_ACTION("send delayed dynamic update",
				    (struct rt_entry *)NULL);
				(void) gettimeofday(&now,
				    (struct timezone *)NULL);
				supplyall(&allrouters, RTS_CHANGED,
				    (struct interface *)NULL, _B_TRUE);
				lastmcast = now;
				needupdate = _B_FALSE;
				nextmcast.tv_sec = 0;
			}
			(void) sigrelse(SIGHUP);
			(void) sigrelse(SIGALRM);
			continue;
		}
		(void) gettimeofday(&now, (struct timezone *)NULL);
		for (i = 0; i < poll_ifs_num; i++) {
			/*
			 * This case should never happen.
			 */
			if (poll_ifs[i].revents & POLLERR) {
				syslog(LOG_ERR,
				    "main: poll returned a POLLERR event");
				continue;
			}
			if (poll_ifs[i].revents & POLLIN) {
				for (ifp = ifnet; ifp != NULL;
				    ifp = ifp->int_next) {
					if (poll_ifs[i].fd == ifp->int_sock)
						in_data(ifp);
				}
			}
		}
		(void) sigrelse(SIGHUP);
		(void) sigrelse(SIGALRM);
	}

	return (0);
}
int main(int argc,char **argv) {

  if (argc < 3)
  {
    cout << "Usage: " << argv[0] << " [CSV FILE] [FASTQ/GZ]" << "\n";

    return EXIT_FAILURE;
  }

  int count_clean = 0, count_filter = 0;
  string sequence = "";
  string csv_file = argv[1];
  string fastq_file = argv[2];
  string out_clean_file = fastq_file  + ".cleaned.result";
  string out_filter_file = fastq_file  + ".filtered.result";
  FastQ f;
  unordered_set<string> to_remove = loadCSV(csv_file);

  struct magic_set *magic = magic_open(MAGIC_MIME|MAGIC_CHECK);
  magic_load(magic, NULL);

  // ifstream in_fastq(fastq_file, ios_base::in | ios_base::binary);
  ifstream in_fastq(fastq_file, ios_base::in);
  boost::iostreams::filtering_streambuf<boost::iostreams::input> in_buf;

  if (std::strcmp("application/gzip; charset=binary", magic_file(magic, argv[2])) == 0)
    in_buf.push(boost::iostreams::gzip_decompressor());

  in_buf.push(in_fastq);
  istream in_data(&in_buf);

  ofstream out_clean(out_clean_file);
  ofstream out_filter(out_filter_file);

  cout << "\nUsing " << fastq_file << " and " << csv_file << "\n\nProcessing..." << "\n";

  std::string buffer_filter;
  buffer_filter.reserve(THRESHOLD);

  std::string buffer_clean;
  buffer_clean.reserve(THRESHOLD);

  while(!in_data.eof())
  {
    if (!getline(in_data, f.name,'\n')) break;
    if (!getline(in_data, f.sequence,'\n')) break;
    if (!getline(in_data, f.info,'\n')) break;
    if (!getline(in_data, f.quality,'\n')) break;

    f.remove = false;

    for (auto remove : to_remove) {
      if (f.sequence.find(remove) != std::string::npos)
      {
        // cout << "Found: " << remove << " in " << f.name << '\n';
        f.remove = true;
      }
    }

    if (f.remove == false) {
      if (buffer_clean.length() + 1 >= THRESHOLD) {
        out_clean << buffer_clean;
        buffer_clean.resize(0);
      }

      buffer_clean.append("@" + f.name + "\n");
      buffer_clean.append(f.sequence + "\n");
      buffer_clean.append(f.info + "\n");
      buffer_clean.append(f.quality + "\n");

      count_clean++;

    }
    else
    {
      if (buffer_filter.length() + 1 >= THRESHOLD) {
        out_filter << buffer_filter;
        buffer_filter.resize(0);
      }

      buffer_filter.append("@" + f.name + "\n");
      buffer_filter.append(f.sequence + "\n");
      buffer_filter.append(f.info + "\n");
      buffer_filter.append(f.quality + "\n");

      count_filter++;

    }
  }

  out_clean << buffer_clean;
  out_filter << buffer_filter;

  cout << "\nCheck the results in " << out_clean_file << " (" << count_clean <<  ")\n";
  cout << "\nFiltered results in " << out_filter_file << " (" << count_filter <<  ")\n";

  out_clean.close();
  out_filter.close();

  in_fastq.close();

  return EXIT_SUCCESS;
}
Esempio n. 14
0
int
IMAP4_SSL_Client_Session::on_read_complete(ACE_Message_Block& mb, const TRB_Asynch_Read_Stream::Result& result)
{
	//ACE_OS::write_n(ACE_STDOUT, mb.rd_ptr(), mb.length()); //@

	if ( step_ == 0 )
	{
		// read greetings
		while( mb.length() > 0 )
		{
			aos::bcstr line = io_.read_greeting(mb);
			ACE_OS::printf("%s", io_.buf().c_str());
		}
		// keep reading
		if ( io_.read_state() != IMAP4_Client_IO::RD_OK )
		{
			ACE_Message_Block* mb_read = new (std::nothrow) ACE_Message_Block(BUFSIZE+1);
			if ( !mb_read ) return -1;
			if ( read(*mb_read) != 0 ) return -1;
		}
		// write command: login
		else
		{
			ACE_Message_Block* mb_write = new (std::nothrow) ACE_Message_Block(BUFSIZE+1);
			if ( !mb_write ) return -1;
			if ( io_.cmd_login(*mb_write, "ntut", "111111") != IMAP4_Client_IO::WR_OK ) 
			{
				mb_write->release();
				return -1;
			}
			if ( write(*mb_write) != 0 ) return -1;
		}
	}
	else if ( step_ == 1 )
	{
		// read response
		while( mb.length() > 0 )
		{
			aos::bcstr line = io_.read_line(mb);
			ACE_OS::printf("%s", io_.buf().c_str());
		}
		// keep reading
		if ( io_.read_state() != IMAP4_Client_IO::RD_OK )
		{
			ACE_Message_Block* mb_read = new (std::nothrow) ACE_Message_Block(BUFSIZE+1);
			if ( !mb_read ) return -1;
			if ( read(*mb_read) != 0 ) return -1;
		}
		// write command: capability
		else
		{
			ACE_Message_Block* mb_write = new (std::nothrow) ACE_Message_Block(BUFSIZE+1);
			if ( !mb_write ) return -1;
			if ( io_.cmd_capability(*mb_write) != IMAP4_Client_IO::WR_OK ) 
			{
				mb_write->release();
				return -1;
			}
			if ( write(*mb_write) != 0 ) return -1;
		}
	}
	else if ( step_ == 2 )
	{
		// read response
		while( mb.length() > 0 )
		{
			aos::bcstr line = io_.read_line(mb);
			ACE_OS::printf("%s", io_.buf().c_str());
		}
		// keep reading
		if ( io_.read_state() != IMAP4_Client_IO::RD_OK )
		{
			ACE_Message_Block* mb_read = new (std::nothrow) ACE_Message_Block(BUFSIZE+1);
			if ( !mb_read ) return -1;
			if ( read(*mb_read) != 0 ) return -1;
		}
		// write command: user command
		else
		{
			ACE_Message_Block* mb_write = new (std::nothrow) ACE_Message_Block(BUFSIZE+1);
			if ( !mb_write ) return -1;
			mb_write->copy("A001 SELECT INBOX\r\n");
			mb_write->wr_ptr(-1); // take '\0' out!
			if ( write(*mb_write) != 0 ) return -1;
		}
	}
	else if ( step_ == 3 )
	{
		// read response
		while( mb.length() > 0 )
		{
			aos::bcstr line = io_.read_line(mb);
			ACE_OS::printf("%s", io_.buf().c_str());
		}
		// keep reading
		if ( io_.read_state() != IMAP4_Client_IO::RD_OK )
		{
			ACE_Message_Block* mb_read = new (std::nothrow) ACE_Message_Block(BUFSIZE+1);
			if ( !mb_read ) return -1;
			if ( read(*mb_read) != 0 ) return -1;
		}
		// write command: logout
		else
		{
			ACE_Message_Block* mb_write = new (std::nothrow) ACE_Message_Block(BUFSIZE+1);
			if ( !mb_write ) return -1;
			if ( io_.cmd_noop(*mb_write) != IMAP4_Client_IO::WR_OK ) 
			{
				mb_write->release();
				return -1;
			}
			if ( write(*mb_write) != 0 ) return -1;
		}
	}
	else if ( step_ == 4 )
	{
		// read response
		while( mb.length() > 0 )
		{
			aos::bcstr line = io_.read_line(mb);
			ACE_OS::printf("%s", io_.buf().c_str());
		}
		// keep reading
		if ( io_.read_state() != IMAP4_Client_IO::RD_OK )
		{
			ACE_Message_Block* mb_read = new (std::nothrow) ACE_Message_Block(BUFSIZE+1);
			if ( !mb_read ) return -1;
			if ( read(*mb_read) != 0 ) return -1;
		}
		// write command: logout
		else
		{
			ACE_Message_Block* mb_write = new (std::nothrow) ACE_Message_Block(BUFSIZE+1);
			if ( !mb_write ) return -1;
			mb_write->copy("A001 FETCH 1 BODY[]\r\n");
			mb_write->wr_ptr(-1); // take '\0' out!
			if ( write(*mb_write) != 0 ) return -1;
		}
	}
	else if ( step_ == 5 )
	{
		// read response
		while( mb.length() > 0 )
		{
			if ( io_.read_state() != IMAP4_Client_IO::RD_DATA )
			{
				aos::bcstr line = io_.read_line(mb);
				ACE_OS::printf("%s", io_.buf().c_str());
			}
			else
			{
				aos::bcstr data = io_.read_data(mb);
				std::string in_data(data.buf, data.len);
				ACE_OS::printf("%s", in_data.c_str());
			}
		}
		// keep reading
		if ( io_.read_state() != IMAP4_Client_IO::RD_OK )
		{
			ACE_Message_Block* mb_read = new (std::nothrow) ACE_Message_Block(BUFSIZE+1);
			if ( !mb_read ) return -1;
			if ( read(*mb_read) != 0 ) return -1;
		}
		// write command: logout
		else
		{
			ACE_Message_Block* mb_write = new (std::nothrow) ACE_Message_Block(BUFSIZE+1);
			if ( !mb_write ) return -1;
			if ( io_.cmd_logout(*mb_write) != IMAP4_Client_IO::WR_OK ) 
			{
				mb_write->release();
				return -1;
			}
			if ( write(*mb_write) != 0 ) return -1;
		}
	}
	else
	{
		// read response
		while( mb.length() > 0 )
		{
			aos::bcstr line = io_.read_line(mb);
			ACE_OS::printf("%s", io_.buf().c_str());
		}
		// keep reading
		if ( io_.read_state() != IMAP4_Client_IO::RD_OK )
		{
			ACE_Message_Block* mb_read = new (std::nothrow) ACE_Message_Block(BUFSIZE+1);
			if ( !mb_read ) return -1;
			if ( read(*mb_read) != 0 ) return -1;
		}
		return -1;
	}

	//+ if finish reading, get next command and write command...

	return 0;
}