summaryrefslogtreecommitdiff
path: root/server/server.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'server/server.cpp')
-rw-r--r--server/server.cpp30
1 files changed, 16 insertions, 14 deletions
diff --git a/server/server.cpp b/server/server.cpp
index 2c46489..05d011d 100644
--- a/server/server.cpp
+++ b/server/server.cpp
@@ -1,7 +1,7 @@
#include "server.hpp"
int server::c_server::init( ) {
-#if WIN32
+#if WIN
if( WSAStartup( MAKEWORD( 2, 2 ), &m_sock_data ) ) // windows
return 1;
#endif
@@ -37,23 +37,25 @@ void server::c_server::listen( ) {
printf( "incoming connection from: %s\n", inet_ntoa( client_address.sin_addr ) );
// connection established.
- std::lock_guard lock( m_mutex );
auto client = std::make_shared< c_client >( result, client_address.sin_addr );
- client->send_message( "hello" );
+ // handshake.
+ client->send_msg( "hello" );
- m_clients.push_back( client );
+ // surprised it even works with shared_ptr.
+ std::thread thread( &c_client::handle, client );
+ thread.detach( );
}
void server::c_server::client_loop( ) {
- if( m_clients.size( ) ) {
- std::lock_guard lock( m_mutex );
- for( auto it = m_clients.begin( ); it != m_clients.end( ); ++it ) {
- if( !( *it )->handle( ) ) {
- printf( "%s disconnected\n", ( *it )->get_ip( ) );
- m_clients.erase( it );
- break;
- }
- }
- }
+ //if( m_clients.size( ) ) {
+ // std::lock_guard lock( m_mutex );
+ // for( auto it = m_clients.begin( ); it != m_clients.end( ); ++it ) {
+ // if( !( *it )->handle( ) ) {
+ // ( *it )->kill( );
+ // m_clients.erase( it );
+ // break;
+ // }
+ // }
+ //}
} \ No newline at end of file