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 receiver(orchid::coroutine_handle co,orchid::chan<int>& ch) { orchid::descriptor stdout(co -> get_scheduler().get_io_service(),STDOUT_FILENO); orchid::descriptor_ostream console(stdout,co); int id; for (;;) { ch.recv(id,co); console<<"receiver receive: "<<id<<std::endl; } }
void counter(orchid::coroutine_handle co, orchid::chan<counter_t>& ch, orchid::scheduler_group& group, std::size_t size) { counter_t c; counter_t tmp; c.total_read = 0; c.total_write = 0; //printf("total_%d\n",size); while(size-- > 0) { ch.recv(tmp,co); c.total_write += tmp.total_write; c.total_read += tmp.total_read; } cout<<"total_read:"<<c.total_read<<endl; cout<<"total_write:"<<c.total_write<<endl; group.stop(); }
void sender(orchid::coroutine_handle co,int id,orchid::chan<int>& ch) { for (;;) { ch.send(id,co); } }