-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
148 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,45 @@ | ||
#pragma once // Copyright 2024 Alex0vSky (https://github.com/Alex0vSky), Copyright 2015-2021 (https://github.com/KrystianKaluzny/Tanks) | ||
#include "net/tx/base.h" | ||
|
||
namespace net::tx { | ||
Base::Base() : | ||
Base::Base(function_t client, function_t server) : | ||
m_ioContext( 1 ) | ||
, c_endpointClient{ boost::asio::ip::address_v4( c_host ), c_port } | ||
, m_acceptor( m_ioContext, c_endpointServer ) | ||
, m_acceptor( m_ioContext ) | ||
, m_client( client ), m_server( server ) | ||
, m_exchanger( reinterpret_cast< Exchanger * >( this ) ) | ||
, m_socketClient( m_ioContext ), m_socketServer( m_ioContext ) | ||
{} | ||
|
||
void Base::update(function_t client, function_t server) { | ||
bool stop = false; | ||
if ( server ) | ||
co_spawn_( [this, server]() mutable ->awaitable { | ||
co_await server( reinterpret_cast< Exchanger * >( this ) ); | ||
void Base::update(bool isServer) { | ||
boost::asio::io_context::count_type count; | ||
if ( | ||
!isServer && | ||
!m_socketClient.is_open( ) ) { | ||
co_spawn_( [this]() mutable ->awaitable { | ||
m_acceptor.open( c_endpointServer.protocol( ) ), m_acceptor.bind( c_endpointServer ), m_acceptor.listen( 1 ); | ||
do m_socketClient = std::get< 1 >( co_await m_acceptor.async_accept( c_tuple ) ); | ||
while ( !m_socketClient.is_open( ) && sleep_( ) ); | ||
__nop( ); | ||
} ); | ||
else | ||
m_acceptor.close( ); | ||
if ( client ) | ||
co_spawn_( [this, client, &stop]() mutable ->awaitable { | ||
co_await client( reinterpret_cast< Exchanger * >( this ) ); | ||
stop = true; | ||
} | ||
if ( | ||
isServer && | ||
!m_socketServer.is_open( ) ) { | ||
co_spawn_( [this]() mutable ->awaitable { | ||
do co_await m_socketServer.async_connect( c_endpointClient, c_tuple ); | ||
while ( !m_socketServer.is_open( ) && sleep_( ) ); | ||
__nop( ); | ||
} ); | ||
while ( true ) { | ||
m_ioContext.run_one_for( std::chrono::milliseconds{ 300 } ); | ||
if ( stop ) { | ||
if ( server ) { | ||
m_acceptor.cancel( ); | ||
m_ioContext.run( ); | ||
} | ||
break; | ||
} | ||
} | ||
count = m_ioContext.run( ); | ||
m_ioContext.restart( ); | ||
__nop( ); | ||
|
||
if ( !isServer ) | ||
co_spawn_( m_client( m_exchanger ) ); | ||
else | ||
co_spawn_( m_server( m_exchanger ) ); | ||
count = m_ioContext.run( ); | ||
__nop( ); | ||
} | ||
} // namespace net::tx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.