Skip to content

Commit

Permalink
Some [#89] - 🎨 more on the network side. ♻️ the handling of client/se…
Browse files Browse the repository at this point in the history
…rver 🚑
  • Loading branch information
aconstlink committed May 3, 2024
1 parent c9dd12f commit 156167d
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 176 deletions.
2 changes: 1 addition & 1 deletion core/mtr_ownership.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ namespace motor
{
auto * tmp = _ptr ;
_ptr = nullptr ;
return _ptr ;
return tmp ;
}

// get the managed pointer
Expand Down
7 changes: 7 additions & 0 deletions memory/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,5 +385,12 @@ namespace motor

T & operator * ( void_t ) noexcept { return *_mtr ; }
T const & operator * ( void_t ) const noexcept { return *_mtr ; }

T * move( void_t ) noexcept
{
auto * ret = _mtr ;
_mtr = nullptr ;
return ret ;
}
};
}
2 changes: 1 addition & 1 deletion memory/manager/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void_ptr_t manager::alloc( size_t const sib, char_cptr_t purpose, bool_t const m
if ( _observer->on_alloc( sib, managed ) > 500000 )
{
_observer->swap_and_clear() ;
//std::cout << "[MOTOR_MEMORY_OBSERVER] : swap and clear" << std::endl ;
std::cout << "[MOTOR_MEMORY_OBSERVER] : swap and clear" << std::endl ;
}
#endif

Expand Down
20 changes: 17 additions & 3 deletions network/imodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,26 @@ namespace motor{ namespace network
};
motor_typedef( create_tcp_server_info ) ;

class iclient_handler
{
public:

virtual void_t on_connect( motor::network::connect_result const ) noexcept = 0 ;
virtual void_t on_close( void_t ) noexcept = 0 ;

virtual motor::network::receive_result on_receive(
byte_cptr_t, size_t const ) noexcept = 0 ;

virtual motor::network::transmit_result on_send(
byte_cptr_t & buffer, size_t & num_sib ) noexcept = 0 ;
};
motor_typedef( iclient_handler ) ;

struct create_tcp_client_info
{
motor::string_t name ;
motor::network::ipv4::binding_point_t bp ;
send_funk_t send_handler ;
recv_funk_t recv_handler ;
motor::network::ipv4::binding_point_host_t bp ;
iclient_handler_mtr_safe_t handler ;
};
motor_typedef( create_tcp_client_info ) ;

Expand Down
7 changes: 7 additions & 0 deletions network/ipv4_address.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,11 @@ namespace motor { namespace network { namespace ipv4 {
};
motor_typedef( binding_point ) ;

struct binding_point_host
{
motor::string_t service ;
motor::string_t host ;
};
motor_typedef( binding_point_host ) ;

} } }
25 changes: 22 additions & 3 deletions network/typedefs.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

#pragma once

#include <motor/std/string>

#include <motor/memory/global.h>
#include <motor/memory/allocator.hpp>

Expand All @@ -24,6 +26,20 @@ namespace motor
no_accept
};

enum class connect_result
{
established,
failed
};

static motor::string_t to_string( connect_result const res ) noexcept
{
static char const * const __connect_result_strings[] =
{ "established", "failed" } ;

return __connect_result_strings[ size_t( res ) ] ;
}

enum class receive_result
{
ok,
Expand All @@ -32,12 +48,15 @@ namespace motor

enum class transmit_result
{
proceed,
break_now,
ok,
have_nothing,

have_more,
break_after

};




static const size_t send_buffer_sib = 2048 ;

Expand Down
Loading

0 comments on commit 156167d

Please sign in to comment.