Make canl_io_connect() retun a canl_code (to be consistent with other calls)
authorDaniel Kouřil <kouril@ics.muni.cz>
Thu, 12 Jan 2012 09:27:49 +0000 (09:27 +0000)
committerDaniel Kouřil <kouril@ics.muni.cz>
Thu, 12 Jan 2012 09:27:49 +0000 (09:27 +0000)
emi.canl.canl-c/src/canl.c
emi.canl.canl-c/src/canl.h
emi.canl.canl-c/src/canl_sample_client.c
emi.canl.canl-c/src/canl_sample_server.c

index fc4839e..a09fd4a 100644 (file)
@@ -42,35 +42,28 @@ void canl_free_ctx(canl_ctx cc)
     free(ctx);
 }
 
-canl_io_handler canl_create_io_handler(canl_ctx cc)
+int canl_create_io_handler(canl_ctx cc, canl_io_handler *io)
 {
     io_handler *new_io_h = NULL;
     glb_ctx *g_cc = cc;
     int err = 0;
 
-    if (!g_cc)
-        return NULL;
+    if (!g_cc || io == NULL)
+        return EINVAL;
 
     /*create io handler*/
     new_io_h = (io_handler *) calloc(1, sizeof(*new_io_h));
-    if (!new_io_h){
-        set_error(g_cc, ENOMEM, posix_error, "Not enough memory ");
-        return NULL;
-    }
+    if (!new_io_h)
+        return set_error(g_cc, ENOMEM, posix_error, "Not enough memory");
 
     /* allocate memory and initialize io content*/
     if ((err = init_io_content(g_cc ,new_io_h))){
-        goto end;
+       free(new_io_h);
+       return err;
     }
 
-end:
-    if (err) {
-        update_error(g_cc,"cannot create canl_io_handler");
-        if ((err = canl_io_destroy(cc, (canl_io_handler)new_io_h)))
-            update_error(g_cc, "cannot destroy canl_ctx");
-        new_io_h = NULL;
-    }
-    return new_io_h;
+    *io = new_io_h;
+    return 0;
 }
 
 static int init_io_content(glb_ctx *cc, io_handler *io)
index 9a7a3f1..a4aa739 100644 (file)
@@ -16,7 +16,7 @@ typedef void *canl_principal;
 
 canl_ctx canl_create_ctx();
 void canl_free_ctx(canl_ctx cc);
-canl_io_handler canl_create_io_handler(canl_ctx cc);
+int canl_create_io_handler(canl_ctx, canl_io_handler*);
 
 int canl_io_connect(canl_ctx cc, canl_io_handler io, const char *host, const char *service,
         int port, gss_OID_set auth_mechs, int flags, struct timeval *timeout);
index 44d64e5..1bf5c06 100644 (file)
@@ -47,8 +47,8 @@ int main(int argc, char *argv[])
         goto end;
     }
 
-    my_io_h = canl_create_io_handler(my_ctx);
-    if (!my_io_h) {
+    err = canl_create_io_handler(my_ctx, &my_io_h);
+    if (err) {
        printf("io handler cannot be created: %s\n",
               canl_get_error_message(my_ctx));
         goto end;
@@ -57,7 +57,7 @@ int main(int argc, char *argv[])
    timeout.tv_sec = 150;
    timeout.tv_usec = 0;
 
-    err = canl_io_connect(my_ctx, my_io_h, p_server, port, 0, NULL, &timeout);
+    err = canl_io_connect(my_ctx, my_io_h, p_server, NULL, port, NULL, 0, &timeout);
     if (err) {
         printf("[CLIENT] connection to %s cannot be established: %s\n",
               p_server, canl_get_error_message(my_ctx));
index c3a1c28..9814106 100644 (file)
@@ -14,7 +14,6 @@ int main(int argc, char *argv[])
 {
     canl_ctx my_ctx;
     canl_io_handler my_io_h = NULL;
-    canl_io_handler my_new_io_h;
     int err = 0;
     int opt, port = 4321;
     char *serv_cert = NULL;
@@ -51,15 +50,8 @@ int main(int argc, char *argv[])
         return -1;
     }
 
-    my_io_h = canl_create_io_handler(my_ctx);
-    if (!my_io_h) {
-        printf("[SERVER] io handler cannot be created: %s\n",
-              canl_get_error_message(my_ctx));
-        goto end;
-    }
-
-    my_new_io_h = canl_create_io_handler(my_ctx);
-    if (!my_new_io_h) {
+    err = canl_create_io_handler(my_ctx, &my_io_h);
+    if (err) {
         printf("[SERVER] io handler cannot be created: %s\n",
               canl_get_error_message(my_ctx));
         goto end;