diff options
author | Timo Dritschler <timo.dritschler@kit.edu> | 2014-08-28 17:44:24 +0200 |
---|---|---|
committer | Timo Dritschler <timo.dritschler@kit.edu> | 2014-08-28 17:44:24 +0200 |
commit | 0eb7de91194436c5716f5fb2574843628152cc13 (patch) | |
tree | a42b0e3093cc98fb47c80ed37b78bd2b0bcc25b8 /src | |
parent | 318c12699514f8187ab212a4db8492984f05348b (diff) | |
download | kiro-0eb7de91194436c5716f5fb2574843628152cc13.tar.gz kiro-0eb7de91194436c5716f5fb2574843628152cc13.tar.bz2 kiro-0eb7de91194436c5716f5fb2574843628152cc13.tar.xz kiro-0eb7de91194436c5716f5fb2574843628152cc13.zip |
KIRO Server now maintains a list of all connected clients
Removed kiro_connected structure from kiro-rdma.h as it is no longer needed
Diffstat (limited to 'src')
-rw-r--r-- | src/kiro-rdma.h | 9 | ||||
-rw-r--r-- | src/kiro-server.c | 45 |
2 files changed, 24 insertions, 30 deletions
diff --git a/src/kiro-rdma.h b/src/kiro-rdma.h index fa16fd1..8779b2e 100644 --- a/src/kiro-rdma.h +++ b/src/kiro-rdma.h @@ -46,15 +46,6 @@ struct kiro_connection_context { }; -struct kiro_connection { - - uint32_t identifier; - struct rdma_cm_id *id; - struct kiro_connection *next; - -}; - - struct kiro_ctrl_msg { enum { diff --git a/src/kiro-server.c b/src/kiro-server.c index 3a112e6..171decc 100644 --- a/src/kiro-server.c +++ b/src/kiro-server.c @@ -52,7 +52,8 @@ struct _KiroServerPrivate { /* (Not accessible by properties) */ struct rdma_event_channel *ec; // Main Event Channel struct rdma_cm_id *base; // Base-Listening-Connection - struct kiro_connection *client; // Connection to the client + GList *clients; // List of connected clients + guint next_client_id; // Numeric ID for the next client that will connect pthread_t event_listener; // Pointer to the completion-listener thread of this connection int close_signal; // Integer flag used to signal to the listener-thread that the server is going to shut down void *mem; // Pointer to the server buffer @@ -227,35 +228,37 @@ void * event_loop (void *self) //Sorry mate! rdma_reject(ev->id, NULL, 0); } - - /* - priv->client = (struct kiro_connection *)calloc(1, sizeof(struct kiro_connection)); - if(!(priv->client)) - { - printf("Failed to create container for client connection.\n"); - free(ev); - continue; - } - priv->client->identifier = 0; //First Client - priv->client->id = ev->id; - */ - if(0 == connect_client(ev->id)) - { - // Connection set-up successfully! (Server) + if(0 == connect_client(ev->id)) { // Post a welcoming "Recieve" for handshaking - welcome_client(ev->id, priv->mem, priv->mem_size); + if (0 == welcome_client(ev->id, priv->mem, priv->mem_size)) { + // Connection set-up successfully! (Server) + //new_client->id = ev->id; + //new_client->identifier = priv->next_client_id; + struct kiro_connection_context *ctx = (struct kiro_connection_context *)(ev->id->context); + ctx->identifier = priv->next_client_id++; + priv->clients = g_list_append (priv->clients, (gpointer)ev->id); + printf("Client id %u connected\n", ctx->identifier); + printf("Currently %u clients in total are connected.\n", g_list_length (priv->clients)); + } } } else if(ev->event == RDMA_CM_EVENT_DISCONNECTED) { - printf("Got disconnect request.\n"); + GList *client = g_list_find (priv->clients, (gconstpointer) ev->id); + if (client) { + struct kiro_connection_context *ctx = (struct kiro_connection_context *)(ev->id->context); + printf ("Got disconnect request from client %s.\n", ctx->identifier); + priv->clients = g_list_delete_link (priv->clients, client); + } + else + printf("Got disconnect request from unknown client.\n"); + kiro_destroy_connection(&(ev->id)); - printf("Connection closed successfully\n"); + printf("Connection closed successfully. %u connected clients remaining.\n", g_list_length (priv->clients)); } free(ev); } - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); } @@ -303,7 +306,7 @@ int kiro_server_start (KiroServer *self, char *address, char *port, void* mem, s if(rdma_create_ep(&(priv->base), res_addrinfo, NULL, &qp_attr)) { - printf("Endpoint creation failed.\n"); + printf("Endpoint creation failed: %s.\n", strerror (errno)); return -1; } printf("Endpoint created.\n"); |