Just a teaser:
int main()
{
try
{
using asio::ip::tcp;
using namespace boost::lambda;
asio::io_service io_service;
tcp::acceptor acceptor(io_service,
tcp::endpoint(tcp::v4(), 54321));
const int max_clients = 100;
coroutine coro[max_clients];
std::auto_ptr<tcp::socket> socket[max_clients];
asio::error_code ec[max_clients];
std::size_t length[max_clients];
boost::array<char, 1024> data[max_clients];
// Kick off all the coroutines.
int n = -1;
for (int i = 0; i < max_clients; ++i)
{
socket[i].reset(new tcp::socket(io_service));
io_service.post(
unlambda((
var(n) = i
)));
}
for (; io_service.run_one() > 0; n = -1)
{
if (n != -1)
{
reenter (coro[n])
{
entry:
for (;;)
{
// Wait for a client to connect.
yield acceptor.async_accept(
*socket[n],
unlambda((
var(n) = n,
var(ec[n]) = _1
)));
// Echo at will.
while (!ec[n])
{
yield socket[n]->async_read_some(
asio::buffer(data[n]),
unlambda((
var(n) = n,
var(ec[n]) = _1,
var(length[n]) = _2
)));
if (!ec[n])
{
yield asio::async_write(
*socket[n],
asio::buffer(data[n], length[n]),
unlambda((
var(n) = n,
var(ec[n]) = _1
)));
}
}
// Clean up before accepting next client.
socket[n]->close();
}
}
}
}
}
catch (std::exception& e)
{
std::cerr << "Exception: " << e.what() << "\n";
}
}
One function. One fully asynchronous server. Bog standard C++.
27 comments:
Cute!
Thanks for boost::asio by the way!
yield in c++?
wait, what compiler is this using?
Tested with: g++ 3.4.5, 4.1, 4.3 and 4.4; MSVC 8.0 and 9.0.
Obviously there's a little bit of something not shown in the snippet :)
I envy the fact that your wife understands enough about what you do to not understand how that works :~(
Thanks for this. learning a little more on asio. http://www.directics.com/altera/
آهنگ جدید
امین کامی ثابتی تو قلب من
دانلود آهنگ آصف آریا هیس
آهنگ کارن کیان دلتنگتم این روزا
What a good blog you have here. Please update it more often. This topics is my interest. Thank you. .
토토사이트
온라인카지노
파워볼사이트
I want to say thanks for beautiful blog sharing with us. Your blog really great resource to update my knowledge
스포츠토토
토토
안전놀이터
토토사이트
Thanks for providing recent updates regarding the concern, I look forward to read more
토토사이트
온라인카지노
파워볼게임
바카라사이트
I was very pleased to find this page. I wanted to thank you for your time due to this wonderful read!!
카지노사이트원
카지노사이트
바카라사이트
I definitely loved every part of it and I have you bookmarked to check out new information on your blog.
카지노사이트777
카지노사이트
바카라사이트
Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style.
카지노사이트존
카지노사이트
바카라사이트
Executive-Education.id allows college students to analyze at home, along with various aesthetic programs. School, SD, SMP, SMA, University student / General. Location & Program as outlined by pupil request... click https://kursus-akuntansi.netlify.app/kursus-akuntansi-koja.html for further
In total, we analyze 8 datasets collected from four different online playing websites, and the variety of bet logs contained in every dataset ranges from zero.three million to 19.2 million. Due to the excessive variation of market prices of crypto-currencies and in-game skins, the wager and deposits 1xbet are first transformed into US cents based on their day by day market prices. The fast development of the video gaming trade has additionally resulted in an explosive progress of different online entertainment. This is very true for online playing that has developed quickly right into a booming trade with multi-billion levels.
Jabodetabek private tutoring services with teachers going to the house. Over many active tutors will be ready teach various skills and lessons for the kids to adults ... go to https://privatmurah.vercel.app/les-privat-senen-murah.html for further
Very attractive blog post. Thanks for sharing with us! Concrete Services
Thank you so much for sharing this article with us and all the best for your next blog.
Great article. Thank you for sharing your insight on this topic.
This is a well written article, thank you for sharing your thoughts on this.
thanks
آهنگهای پرطرفدار
آهنگ جدید
Wow, incredible blog format! Your site is fantastic. Unique style, great job
I’m truly enjoying the design and layout of this website. I also love the blog Thanks
Fantastic!! You put very helpful information here with us. Thanks a lot!
Your data was very informative and helpful for us. Keep writing like this!
I really enjoyed reading this articles. Very good message you've done. Thanks
Thank you for the informative blog and the chance to share perspectives. Siding Pros of Coquitlam
I want to say thanks for beautiful blog sharing with us. Your blog really great resource to update my knowledge
cricut 3d flower
Valentine’s Day Cricut designs
Sarcastic quotes for Cricut projects
Mountain cut file for Cricut
Post a Comment