1 Star 1 Fork 0

undefined/xh_coroutine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
xh_asio.hpp 2.23 KB
一键复制 编辑 原始数据 按行查看 历史
ctemple 提交于 2016-04-03 11:31 . 优化:先尝试读写
#pragma once
#ifdef _MSC_VER
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#endif
#include <boost/asio.hpp>
#include <memory>
struct ASIOErrrCode
{
boost::system::error_code ec;
std::size_t bytes;
ASIOErrrCode()
: bytes(0)
{
}
};
struct ASIOConnection : public std::enable_shared_from_this<ASIOConnection>
{
ASIOConnection(boost::asio::ip::tcp::socket sock)
: m_socket(std::move(sock))
{
m_socket.non_blocking(true);
}
inline bool is_open() const
{
return m_socket.is_open();
}
inline void close()
{
if (is_open())
m_socket.close();
}
std::size_t read(void* buffer, std::size_t length, boost::system::error_code* pec = nullptr);
std::size_t read_some(void* buffer, std::size_t length, boost::system::error_code* pec = nullptr);
std::size_t write(const void* buffer, std::size_t length, boost::system::error_code* pec = nullptr);
std::size_t write_some(const void* buffer, std::size_t length, boost::system::error_code* pec = nullptr);
private:
ASIOErrrCode m_read_ec;
ASIOErrrCode m_write_ec;
boost::asio::ip::tcp::socket m_socket;
};
struct ASIOConnector : public std::enable_shared_from_this<ASIOConnector>
{
ASIOConnector(boost::asio::io_service& ioservice)
: m_socket(ioservice)
{
}
boost::system::error_code connect(const char* addr, const char* port);
boost::system::error_code connect(const boost::asio::ip::tcp::endpoint& endpoint);
boost::asio::ip::tcp::socket& socket() { return m_socket; }
std::shared_ptr<ASIOConnection> make_connection();
private:
boost::asio::ip::tcp::socket m_socket;
ASIOErrrCode m_connect_ec;
};
struct ASIOAcceptor : public std::enable_shared_from_this<ASIOAcceptor>
{
ASIOAcceptor(boost::asio::io_service& ioservice, const boost::asio::ip::tcp::endpoint& endpoint)
: m_acceptor(ioservice, endpoint)
, m_socket(ioservice)
{
}
boost::system::error_code accept();
boost::asio::ip::tcp::acceptor& asio_acceptor() { return m_acceptor; }
boost::asio::ip::tcp::socket& socket() { return m_socket; }
std::shared_ptr<ASIOConnection> make_accepted_connection();
private:
boost::asio::ip::tcp::acceptor m_acceptor;
boost::asio::ip::tcp::socket m_socket;
ASIOErrrCode m_accept_ec;
};
struct ASIOUtils
{
static void sleep(boost::asio::io_service& ioservice,unsigned int millsecs);
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ctemple/xh_coroutine.git
git@gitee.com:ctemple/xh_coroutine.git
ctemple
xh_coroutine
xh_coroutine
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385