本文整理汇总了C++中Connection_ptr类的典型用法代码示例。如果您正苦于以下问题:C++ Connection_ptr类的具体用法?C++ Connection_ptr怎么用?C++ Connection_ptr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Connection_ptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: htonl
void ServicePort::handle(Acceptor_ptr acceptor, boost::asio::ip::tcp::socket* socket, const boost::system::error_code& error)
{
if(!error)
{
if(m_services.empty())
{
#ifdef __DEBUG_NET__
std::clog << "[Error - ServerPort::handle] No services running!" << std::endl;
#endif
return;
}
boost::system::error_code error;
const boost::asio::ip::tcp::endpoint ip = socket->remote_endpoint(error);
uint32_t remoteIp = 0;
if(!error)
remoteIp = htonl(ip.address().to_v4().to_ulong());
Connection_ptr connection;
if(remoteIp && ConnectionManager::getInstance()->acceptConnection(remoteIp) &&
(connection = ConnectionManager::getInstance()->createConnection(
socket, m_io_service, shared_from_this())))
{
if(m_services.front()->isSingleSocket())
connection->handle(m_services.front()->makeProtocol(connection));
else
connection->accept();
}
else if(socket->is_open())
{
boost::system::error_code error;
socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both, error);
socket->close(error);
delete socket;
}
#ifdef __DEBUG_NET_DETAIL__
std::clog << "handle - OK" << std::endl;
#endif
accept(acceptor);
}
else if(error != boost::asio::error::operation_aborted)
{
PRINT_ASIO_ERROR("Handling");
close();
if(!m_pendingStart)
{
m_pendingStart = true;
Scheduler::getInstance().addEvent(createSchedulerTask(5000, boost::bind(
&ServicePort::service, boost::weak_ptr<ServicePort>(shared_from_this()),
m_acceptors[acceptor], m_serverPort)));
}
}
#ifdef __DEBUG_NET__
else
std::clog << "[Error - ServerPort::handle] Operation aborted." << std::endl;
#endif
}
示例2: TRACK_MESSAGE
void OutputMessagePool::configureOutputMessage(OutputMessage_ptr msg, Protocol* protocol, bool autosend)
{
TRACK_MESSAGE(msg);
msg->Reset();
if(autosend)
{
msg->setState(OutputMessage::STATE_ALLOCATED);
m_autoSendOutputMessages.push_back(msg);
}
else
msg->setState(OutputMessage::STATE_ALLOCATED_NO_AUTOSEND);
Connection_ptr connection = protocol->getConnection();
assert(connection != NULL);
msg->setProtocol(protocol);
protocol->addRef();
#ifdef __DEBUG_NET_DETAIL__
std::cout << "Adding reference to protocol - " << protocol << std::endl;
#endif
msg->setConnection(connection);
connection->addRef();
#ifdef __DEBUG_NET_DETAIL__
std::cout << "Adding reference to connection - " << connection << std::endl;
#endif
msg->setFrame(m_frameTime);
}
示例3: insert_connection
void TCP::insert_connection(Connection_ptr conn)
{
connections_.emplace(
std::piecewise_construct,
std::forward_as_tuple(conn->local(), conn->remote()),
std::forward_as_tuple(conn));
}
示例4: connected
void Listener::connected(Connection_ptr conn) {
debug("<Listener::connected> %s connected\n", conn->to_string().c_str());
remove(conn);
Expects(conn->is_connected());
host_.add_connection(conn);
on_connect_(conn);
}
示例5: htonl
void ServicePort::onAccept(boost::asio::ip::tcp::socket* socket, const boost::system::error_code& error)
{
if(!error)
{
if(m_services.empty())
{
#ifdef __DEBUG_NET__
std::cout << "Error: [ServerPort::accept] No services running!" << std::endl;
#endif
return;
}
boost::system::error_code error;
const boost::asio::ip::tcp::endpoint endpoint = socket->remote_endpoint(error);
uint32_t remote_ip = 0;
if(!error)
remote_ip = htonl(endpoint.address().to_v4().to_ulong());
if(remote_ip != 0/* && g_bans.acceptConnection(remote_ip)*/)
{
Connection_ptr connection = ConnectionManager::getInstance()->createConnection(socket, m_io_service, shared_from_this());
if(m_services.front()->is_single_socket())
connection->acceptConnection(m_services.front()->make_protocol(connection));
else
connection->acceptConnection();
}
else if(socket->is_open())
{
boost::system::error_code error;
socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both, error);
socket->close(error);
delete socket;
}
accept();
}
else if(error != boost::asio::error::operation_aborted)
{
if(!m_pendingStart)
{
close();
m_pendingStart = true;
g_scheduler.addEvent(createSchedulerTask(15000,
boost::bind(&ServicePort::openAcceptor, boost::weak_ptr<ServicePort>(shared_from_this()), m_serverPort)));
}
}
else
{
#ifdef __DEBUG_NET__
std::cout << "Error: [ServicePort::onAccept] Operation aborted." << std::endl;
#endif
}
}
示例6: remove
void Listener::remove(Connection_ptr conn) {
debug2("<Listener::remove> Try remove %s\n", conn->to_string().c_str());
auto it = syn_queue_.begin();
while(it != syn_queue_.end())
{
if((*it) == conn)
{
syn_queue_.erase(it);
debug("<Listener::remove> %s removed.\n", conn->to_string().c_str());
return;
}
it++;
}
}
示例7: send
void OutputMessagePool::send(OutputMessage_ptr msg)
{
m_outputPoolLock.lock();
OutputMessage::OutputMessageState state = msg->getState();
m_outputPoolLock.unlock();
if (state == OutputMessage::STATE_ALLOCATED_NO_AUTOSEND) {
Connection_ptr connection = msg->getConnection();
if (connection && !connection->send(msg)) {
// Send only fails when connection is closing (or in error state)
// This call will free the message
msg->getProtocol()->onSendMessage(msg);
}
}
}
示例8: htonl
void ServicePort::handle(boost::asio::ip::tcp::socket* socket, const boost::system::error_code& error)
{
if(!error)
{
if(m_services.empty())
{
return;
}
boost::system::error_code error;
const boost::asio::ip::tcp::endpoint ip = socket->remote_endpoint(error);
uint32_t remoteIp = 0;
if(!error)
remoteIp = htonl(ip.address().to_v4().to_ulong());
Connection_ptr connection;
if(remoteIp && ConnectionManager::getInstance()->acceptConnection(remoteIp) &&
(connection = ConnectionManager::getInstance()->createConnection(
socket, m_io_service, shared_from_this())))
{
if(m_services.front()->isSingleSocket())
connection->handle(m_services.front()->makeProtocol(connection));
else
connection->accept();
}
else if(socket->is_open())
{
boost::system::error_code error;
socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both, error);
socket->close(error);
delete socket;
}
accept();
}
else if(error != boost::asio::error::operation_aborted)
{
close();
if(!m_pendingStart)
{
m_pendingStart = true;
server.scheduler().addTask(SchedulerTask::create(Milliseconds(5000), std::bind(
&ServicePort::onOpen, std::weak_ptr<ServicePort>(shared_from_this()), m_serverPort)));
}
}
}
示例9: send
size_t TCP::send(Connection_ptr conn, const char* buffer, size_t n) {
size_t written{0};
auto packets = inet_.transmit_queue_available();
debug2("<TCP::send> Send request for %u bytes\n", n);
if(packets > 0) {
written += conn->send(buffer, n, packets);
}
// if connection still can send (means there wasn't enough packets)
// only requeue if not already queued
if(conn->can_send() and !conn->is_queued()) {
debug2("<TCP::send> Conn queued.\n");
writeq.push_back(conn);
conn->set_queued(true);
}
return written;
}
示例10: htonl
void ServicePort::onAccept(boost::asio::ip::tcp::socket* socket, const boost::system::error_code& error)
{
if (!error) {
if (m_services.empty()) {
return;
}
boost::system::error_code socketError;
const boost::asio::ip::tcp::endpoint endpoint = socket->remote_endpoint(socketError);
uint32_t remote_ip = 0;
if (!socketError) {
remote_ip = htonl(endpoint.address().to_v4().to_ulong());
}
if (remote_ip != 0 && g_bans.acceptConnection(remote_ip)) {
Connection_ptr connection = ConnectionManager::getInstance()->createConnection(socket, m_io_service, shared_from_this());
Service_ptr service = m_services.front();
if (service->is_single_socket()) {
connection->acceptConnection(service->make_protocol(connection));
} else {
connection->acceptConnection();
}
} else if (socket->is_open()) {
socket->shutdown(boost::asio::ip::tcp::socket::shutdown_both, socketError);
socket->close(socketError);
delete socket;
}
accept();
} else if (error != boost::asio::error::operation_aborted) {
if (!m_pendingStart) {
close();
m_pendingStart = true;
g_scheduler.addEvent(createSchedulerTask(15000,
boost::bind(&ServicePort::openAcceptor, boost::weak_ptr<ServicePort>(shared_from_this()), m_serverPort)));
}
}
}
示例11: ToClientData
void GateModule::ToClientData(const message& msg)
{
UserContext ctx = get_userdata<UserContext>(msg);
Connection_ptr pconn = nullptr;
if (ctx.accountid != 0)
{
pconn = m_Connections->find_by_account(account_id::create(ctx.accountid));
}
else if (ctx.playerid != 0)
{
pconn = m_Connections->find_by_player( player_id::create(ctx.playerid));
}
if (pconn == nullptr)
{
return;
}
send_socket_message(pconn->getsocket_id(), msg.msg_data());
}
示例12: configureOutputMessage
void OutputMessagePool::configureOutputMessage(OutputMessage_ptr msg, Protocol* protocol, bool autosend)
{
msg->Reset();
if (autosend) {
msg->setState(OutputMessage::STATE_ALLOCATED);
m_autoSendOutputMessages.push_back(msg);
} else {
msg->setState(OutputMessage::STATE_ALLOCATED_NO_AUTOSEND);
}
Connection_ptr connection = protocol->getConnection();
assert(connection);
msg->setProtocol(protocol);
protocol->addRef();
msg->setConnection(connection);
connection->addRef();
msg->setFrame(m_frameTime);
}
示例13: lockClass
void OutputMessagePool::sendAll()
{
std::lock_guard<std::recursive_mutex> lockClass(m_outputPoolLock);
const int64_t dropTime = m_frameTime - 10000;
const int64_t frameTime = m_frameTime - 10;
for (OutputMessage_ptr omsg : m_toAddQueue) {
const int64_t msgFrame = omsg->getFrame();
if (msgFrame >= dropTime) {
omsg->setState(OutputMessage::STATE_ALLOCATED);
if (frameTime > msgFrame) {
m_autoSendOutputMessages.push_front(omsg);
} else {
m_autoSendOutputMessages.push_back(omsg);
}
} else {
//drop messages that are older than 10 seconds
omsg->getProtocol()->onSendMessage(omsg);
}
}
m_toAddQueue.clear();
for (auto it = m_autoSendOutputMessages.begin(), end = m_autoSendOutputMessages.end(); it != end; it = m_autoSendOutputMessages.erase(it)) {
OutputMessage_ptr omsg = *it;
if (frameTime <= omsg->getFrame()) {
break;
}
Connection_ptr connection = omsg->getConnection();
if (connection && !connection->send(omsg)) {
// Send only fails when connection is closing (or in error state)
// This call will free the message
omsg->getProtocol()->onSendMessage(omsg);
}
}
}
示例14: processMessage
void MessageProcessorManager::processMessage(
Connection_ptr con,
Message_ptr msg)
{
// Obtiene el contenido y el descriptor del mensaje
Holder holder = msg->holder();
TypeDescriptor_ptr messageDescriptor =
holder.get_type_descriptor();
// creates the key
map_t::iterator it = m_processors.find(
std::make_pair(con.get(), messageDescriptor));
if (it != m_processors.end() &&
!it->second.empty())
{
// Iterates over its associated processors
processors_t::const_iterator pit = it->second.begin();
for (; pit != it->second.end(); ++pit)
{
const MessageProcessor_ptr processor = *pit;
const ReflectivePath_t& path = processor->path();
// Results
TypeDescriptor_ptr descriptor = NULL;
Holder value;
bool res = followPath(messageDescriptor, holder, path,
// Results
descriptor, value);
if (res)
processor->process(msg, value);
}
}
}
示例15: handle_python_on_read
// Called when data is received on python (outgoing connection)
void handle_python_on_read(Connection_ptr client, std::string response) {
// Write response to our client
client->write(response.data(), response.size());
}