summaryrefslogtreecommitdiffstats
path: root/src/server/server.c
diff options
context:
space:
mode:
authorsr2013-07-16 12:30:06 +0200
committersr2013-07-16 12:30:06 +0200
commit0c584f43f1b30ab0ae895f58593c8035d666e16f (patch)
tree5e6abce006c41b1a8a8f06ddd377ebae7051090a /src/server/server.c
parentFix bugs from rewrite so it actually works (diff)
downloaddnbd3-0c584f43f1b30ab0ae895f58593c8035d666e16f.tar.gz
dnbd3-0c584f43f1b30ab0ae895f58593c8035d666e16f.tar.xz
dnbd3-0c584f43f1b30ab0ae895f58593c8035d666e16f.zip
Fix more bugs, remove debug messages
Diffstat (limited to 'src/server/server.c')
-rw-r--r--src/server/server.c51
1 files changed, 25 insertions, 26 deletions
diff --git a/src/server/server.c b/src/server/server.c
index 85461ff..19dd18d 100644
--- a/src/server/server.c
+++ b/src/server/server.c
@@ -54,7 +54,6 @@ char *_rpc_password = NULL;
char *_cache_dir = NULL;
static int dnbd3_add_client(dnbd3_client_t *client);
-static dnbd3_client_t* dnbd3_free_client(dnbd3_client_t *client);
static void dnbd3_load_config();
static void dnbd3_handle_sigpipe(int signum);
static void dnbd3_handle_sigterm(int signum);
@@ -267,14 +266,14 @@ int main(int argc, char *argv[])
// This has to be done before creating the thread, otherwise a race condition might occur when the new thread dies faster than this thread adds the client to the list after creating the thread
if ( !dnbd3_add_client( dnbd3_client ) ) {
- dnbd3_free_client( dnbd3_client );
+ dnbd3_client = dnbd3_free_client( dnbd3_client );
continue;
}
if ( 0 != pthread_create( &(dnbd3_client->thread), NULL, net_client_handler, (void *)(uintptr_t)dnbd3_client ) ) {
memlogf( "[ERROR] Could not start thread for new client." );
dnbd3_remove_client( dnbd3_client );
- dnbd3_free_client( dnbd3_client );
+ dnbd3_client = dnbd3_free_client( dnbd3_client );
continue;
}
pthread_detach( dnbd3_client->thread );
@@ -331,6 +330,29 @@ void dnbd3_remove_client(dnbd3_client_t *client)
pthread_spin_unlock( &_clients_lock );
}
+/**
+ * Free the client struct recursively.
+ * !! Make sure to call this function after removing the client from _dnbd3_clients !!
+ * Locks on: _clients[].lock
+ */
+dnbd3_client_t* dnbd3_free_client(dnbd3_client_t *client)
+{
+ GSList *it;
+ pthread_spin_lock(&client->lock);
+ for (it = client->sendqueue; it; it = it->next) {
+ free( it->data );
+ }
+ g_slist_free( client->sendqueue );
+ if ( client->sock >= 0 ) close( client->sock );
+ client->sock = -1;
+ if ( client->image != NULL ) image_release( client->image );
+ client->image = NULL;
+ pthread_spin_unlock(&client->lock);
+ pthread_spin_destroy(&client->lock);
+ free( client );
+ return NULL;
+}
+
//###//
/**
@@ -357,29 +379,6 @@ static int dnbd3_add_client(dnbd3_client_t *client)
return TRUE;
}
-/**
- * Free the client struct recursively.
- * !! Make sure to call this function after removing the client from _dnbd3_clients !!
- * Locks on: _clients[].lock
- */
-static dnbd3_client_t* dnbd3_free_client(dnbd3_client_t *client)
-{
- GSList *it;
- pthread_spin_lock(&client->lock);
- for (it = client->sendqueue; it; it = it->next) {
- free( it->data );
- }
- g_slist_free( client->sendqueue );
- if ( client->sock >= 0 ) close( client->sock );
- client->sock = -1;
- if ( client->image != NULL ) image_release( client->image );
- client->image = NULL;
- pthread_spin_unlock(&client->lock);
- pthread_spin_destroy(&client->lock);
- free( client );
- return NULL;
-}
-
static void dnbd3_load_config()
{
// Load configuration