void handle_io(orchid::coroutine_handle co,orchid::chan<counter_t>& ch, socket_ptr sock, std::size_t buffer_size) { counter_t c; c.total_read = 0; c.total_write = 0; int n = buffer_size; try { boost::scoped_array<char> buff(new char[buffer_size]); sock -> connect("127.0.0.1","5678",co); sock -> get_impl().set_option(boost::asio::ip::tcp::no_delay(true)); printf("connect_sucess!!\r\n"); for(;;) { n = sock -> write(buff.get(),n,co); c.total_write += n; n = sock -> read(buff.get(),buffer_size,co); c.total_read += n; } } catch (boost::system::system_error& e) { printf("errr:%s\r\n",e.what()); } ch.send(c,co); printf("io_done!\r\n"); }
void sender(orchid::coroutine_handle co,int id,orchid::chan<int>& ch) { for (;;) { ch.send(id,co); } }