sample server and client print better error messages now
authorMarcel Poul <marcel.poul@cern.ch>
Sat, 3 Dec 2011 20:33:44 +0000 (20:33 +0000)
committerMarcel Poul <marcel.poul@cern.ch>
Sat, 3 Dec 2011 20:33:44 +0000 (20:33 +0000)
emi.canl.canl-c/src/canl_sample_client.c
emi.canl.canl-c/src/canl_sample_server.c

index 479e2c7..b347c1b 100644 (file)
@@ -53,22 +53,22 @@ int main(int argc, char *argv[])
         goto end;
     }
 
-   timeout.tv_sec = 15;
+   timeout.tv_sec = 150;
    timeout.tv_usec = 0;
 
     err = canl_io_connect(my_ctx, my_io_h, p_server, port, 0, NULL, &timeout);
     if (err) {
-        printf("connection cannot be established\n");
+        printf("[CLIENT] connection cannot be established\n");
         goto end;
     }
     else {
-        printf("connection established\n");
+        printf("[CLIENT] connection established\n");
     }
 
     strcpy(buf, "This is the testing message to send");
     buf_len = strlen(buf) + 1;
 
-    printf("Trying to send sth to the server\n");
+    printf("[CLIENT] Trying to send sth to the server\n");
     err = canl_io_write (my_ctx, my_io_h, buf, buf_len, &timeout);
     if (err <= 0) {
         printf("can't write using ssl\n");
@@ -76,23 +76,23 @@ int main(int argc, char *argv[])
     }
     else {
         buf[err] = '\0';
-        printf("message \"%s\" sent successfully\n", buf);
+        printf("[CLIENT] message \"%s\" sent successfully\n", buf);
     }
 
     err = canl_io_read (my_ctx, my_io_h, buf, sizeof(buf)-1, &timeout);
     if (err > 0) {
         buf[err] = '\0';
-        printf ("received: %s\n", buf);
+        printf ("[CLIENT] received: %s\n", buf);
     }
 
     err = canl_io_close(my_ctx, my_io_h);
     if (err){
-        //set_error ("cannot close io");
+        printf("[CLIENT] Cannot close connection to server\n");
     }
 
     err = canl_io_destroy(my_ctx, my_io_h);
     if (err){
-        //set_error ("cannot destroy io");
+        printf("[CLIENT] Cannot destroy connection with server\n");
     }
     my_io_h = NULL;
 
index a6d7a91..ca96a3f 100644 (file)
@@ -59,13 +59,15 @@ int main(int argc, char *argv[])
         //set_error("io handler cannot be created\n");
         goto end;
     }
-
-    err = canl_set_ctx_own_cert_file(my_ctx, serv_cert, serv_key, NULL, NULL);
-    if (err) {
-        printf("[SERVER] cannot set certificate or file to context\n");
+    if (serv_cert || serv_key){
+        err = canl_set_ctx_own_cert_file(my_ctx, serv_cert, serv_key, 
+                NULL, NULL);
+        if (err) {
+            printf("[SERVER] cannot set certificate or file to context\n");
+        }
     }
 
-    timeout.tv_sec = 15;
+    timeout.tv_sec = 150;
     timeout.tv_usec = 0;
 
     /* canl_create_io_handler has to be called for my_new_io_h and my_io_h*/
@@ -84,7 +86,7 @@ int main(int argc, char *argv[])
 
     printf("[SERVER] Trying to send sth to the client\n");
     err = canl_io_write (my_ctx, my_new_io_h, buf, buf_len, &timeout);
-    if (err) {
+    if (err <= 0) {
         printf("[SERVER] cannot send message to the client\n");
         goto end;
     }
@@ -94,29 +96,35 @@ int main(int argc, char *argv[])
     }
 
     err = canl_io_read (my_ctx, my_io_h, buf, sizeof(buf)-1, NULL);
-    if (err) {
-        //set_error ("cannot read");
+    if (err > 0) {
+        buf[err] = '\0';
+        printf ("[SERVER] received: %s\n", buf);
     }
+    else
+    printf("[SERVER] nothing received from client\n");
 
-    err = canl_io_close(my_ctx, my_io_h);
+
+    err = canl_io_close(my_ctx, my_new_io_h);
     if (err){
-        //set_error ("cannot close io");
+    printf("[SERVER] Cannot close connection with client\n");
     }
 
-    err = canl_io_destroy(my_ctx, my_io_h);
+    err = canl_io_destroy(my_ctx, my_new_io_h);
     if (err){
-        //set_error ("cannot destroy io");
+    printf("[SERVER] Cannot destroy connection with client\n");
     }
+    my_new_io_h = NULL;
     
-    err = canl_io_close(my_ctx, my_new_io_h);
+    err = canl_io_close(my_ctx, my_io_h);
     if (err){
-        //set_error ("cannot close io");
+    printf("[SERVER] Cannoc close listening socket\n");
     }
 
-    err = canl_io_destroy(my_ctx, my_new_io_h);
+    err = canl_io_destroy(my_ctx, my_io_h);
     if (err){
-        //set_error ("cannot destroy io");
+    printf("[SERVER] Trying destroy listening socket\n");
     }
+    my_io_h = NULL;
 
 end:
     canl_get_error(my_ctx, &err_msg);