diff --git a/.gitmodules b/.gitmodules index 932c689c65fdc63451214273ad6f6cb896a9d809..826a90d9aa670031036467132d9e848d5e0f02da 100755 --- a/.gitmodules +++ b/.gitmodules @@ -1,8 +1,12 @@ -[submodule "libdap-server-core"] - path = libdap-server-core - url = https://github.com/kelvinblockchain/libdap-server-core.git - branch = master [submodule "test/libdap-test"] - path = test/libdap-test - url = https://github.com/kelvinblockchain/libdap-test.git - branch = master + path = test/libdap-test + url = https://github.com/cellframe/libdap-test + branch = master +[submodule "libdap"] + path = libdap + url = https://github.com/cellframe/libdap + branch = master +[submodule "libdap-server-core"] + path = libdap-server-core + url = https://github.com/cellframe/libdap-server-core + branch = master diff --git a/CMakeLists.txt b/CMakeLists.txt index f2bdc3f8d7be2dfb421094e6ff880d2b125e007e..0b7195cca33f5ac5a90b072a78534098c2fbd0ba 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,9 +2,19 @@ cmake_minimum_required(VERSION 3.1) project (dap_udp_server C) if(NOT (${SUBMODULES_NO_BUILD} MATCHES ON)) - if ( NOT ( TARGET dap_core_server ) ) + +# if ( NOT ( TARGET dap_core_server ) ) +# add_subdirectory(libdap-server-core) +# endif() + + if ( NOT ( TARGET dap_server_core ) ) add_subdirectory(libdap-server-core) endif() + + if ( NOT ( TARGET dap_core ) ) + add_subdirectory(libdap) + endif() + enable_testing() add_subdirectory(test) endif() @@ -13,6 +23,6 @@ set(DAP_UDP_SERVER_SRCS dap_udp_server.c dap_udp_client.h dap_udp_client.c) add_library(${PROJECT_NAME} STATIC ${DAP_UDP_SERVER_SRCS}) -target_link_libraries(${PROJECT_NAME} dap_core dap_server_core ev) +target_link_libraries(${PROJECT_NAME} dap_core dap_server_core ) target_include_directories(${PROJECT_NAME} INTERFACE .) diff --git a/dap_udp_client.c b/dap_udp_client.c index ac0a3a8851534f38248b78ee8dd960f39ad0b1a3..e1e92b4f5cf875d9159f2592f1561b642a31320d 100755 --- a/dap_udp_client.c +++ b/dap_udp_client.c @@ -91,6 +91,7 @@ dap_client_remote_t *dap_udp_client_create( dap_server_t *dap_srv, EPOLL_HANDLE ret->efd = efd; ret->flags = DAP_SOCK_READY_TO_READ; + // ret->signal_close = false; // ret->_ready_to_read = true; // ret->_ready_to_write = false; @@ -100,7 +101,7 @@ dap_client_remote_t *dap_udp_client_create( dap_server_t *dap_srv, EPOLL_HANDLE pthread_mutex_init( &inh->mutex_on_client, NULL ); pthread_mutex_lock( &udp_server->mutex_on_list ); - HASH_ADD_INT( udp_server->clients, host_key, inh ); + HASH_ADD_INT( udp_server->hclients, host_key, inh ); pthread_mutex_unlock( &udp_server->mutex_on_list ); if( dap_srv->client_new_callback ) @@ -129,15 +130,15 @@ void dap_udp_client_get_address( dap_client_remote_t *client, unsigned int* host * @param port Source port * @return Pointer to client or NULL if not found */ -dap_client_remote_t *dap_udp_client_find( dap_server_t * dap_srv, unsigned long host, unsigned short port ) +dap_client_remote_t *dap_udp_client_find( dap_server_t *dap_srv, unsigned long host, unsigned short port ) { dap_udp_client_t *inh = NULL; - dap_udp_server_t *udp_server = DAP_UDP_SERVER( dap_srv ); + uint64_t token = get_key( host, port ); pthread_mutex_lock( &udp_server->mutex_on_list ); - HASH_FIND_INT( udp_server->clients, &token, inh ); + HASH_FIND_INT( udp_server->hclients, &token, inh ); pthread_mutex_unlock( &udp_server->mutex_on_list ); if( inh == NULL ) diff --git a/dap_udp_server.c b/dap_udp_server.c index ba9adb6e1f62754f09f24f5c6431b0c85c6daac2..f74ecffe1cf603b86f0018b6354586f0fb1100bf 100755 --- a/dap_udp_server.c +++ b/dap_udp_server.c @@ -105,15 +105,18 @@ dap_server_t *dap_udp_server_new( ) */ void dap_udp_server_delete( dap_server_t *sh ) { - dap_client_remote_t *client, *tmp; - if ( !sh ) return; +// dap_client_remote_t *client, *tmp; +// dap_udp_server_t *udps = (dap_udp_server_t *)sh->_inheritor; + +// if ( !udps ) return; + if( sh->address ) free( sh->address ); - HASH_ITER( hh, sh->clients, client, tmp ) - dap_client_remote_remove( client, sh ); +// HASH_ITER( hh, udps->hclients, client, tmp ) +// dap_client_remote_remove( client ); if ( sh->server_delete_callback ) sh->server_delete_callback( sh, NULL ); @@ -158,6 +161,7 @@ dap_server_t *dap_udp_server_listen( uint16_t port ) { } pthread_mutex_init( &DAP_UDP_SERVER(sh)->mutex_on_list, NULL ); + pthread_mutex_init( &DAP_UDP_SERVER(sh)->mutex_on_hash, NULL ); return sh; } @@ -237,9 +241,9 @@ int check_close( dap_client_remote_t *client ) if ( client_check->host_key == udp_client->host_key ) LL_DELETE( udp_server->waiting_clients, client_check ); - } + } - dap_client_remote_remove( client, sh ); + dap_client_remote_remove( client ); return 1; } @@ -402,7 +406,10 @@ void dap_udp_server_loop( dap_server_t *d_server ) int32_t n = epoll_wait( efd_read, &events[0], 16, -1 ); if ( !n ) continue; + if ( n < 0 ) { + if ( errno == EINTR ) + continue; log_it( L_ERROR, "Server epoll error" ); break; } @@ -417,6 +424,7 @@ void dap_udp_server_loop( dap_server_t *d_server ) goto error; } } + } error: diff --git a/dap_udp_server.h b/dap_udp_server.h index dcb94c77eaee4fef438bcbac42feefed2b0c6bbd..94f62a2536fea5f9fc9504a8c6fd901a88b988b1 100755 --- a/dap_udp_server.h +++ b/dap_udp_server.h @@ -50,9 +50,10 @@ typedef void (*dap_udp_server_callback_t) (struct dap_udp_server *,void *arg); / typedef struct dap_udp_server { - dap_udp_client_t *clients; + dap_udp_client_t *hclients; dap_udp_client_t *waiting_clients; // List clients for writing data pthread_mutex_t mutex_on_list; + pthread_mutex_t mutex_on_hash; void *_inheritor; dap_server_t *dap_server; diff --git a/libdap b/libdap new file mode 160000 index 0000000000000000000000000000000000000000..78cc4a3aca1775288662ef7a9f49f7b747479e15 --- /dev/null +++ b/libdap @@ -0,0 +1 @@ +Subproject commit 78cc4a3aca1775288662ef7a9f49f7b747479e15