proper error codes and messages assigned
authorMarcel Poul <marcel.poul@cern.ch>
Mon, 14 Nov 2011 21:40:21 +0000 (21:40 +0000)
committerMarcel Poul <marcel.poul@cern.ch>
Mon, 14 Nov 2011 21:40:21 +0000 (21:40 +0000)
emi.canl.canl-c/src/canl.h
emi.canl.canl-c/src/canl_err.c
emi.canl.canl-c/src/canl_locl.h

index 17ce298..aa8cfd8 100644 (file)
@@ -18,7 +18,7 @@ int canl_io_accept(canl_ctx cc, canl_io_handler io, int port, int flags, cred_ha
 size_t canl_io_read(canl_ctx cc, canl_io_handler io, void *buffer, size_t size, struct timeval *timeout);
 size_t canl_io_write(canl_ctx cc, canl_io_handler io, void *buffer, size_t size, struct timeval *timeout);
 
-size_t canl_get_error(canl_ctx cc, char ** reason);
+int canl_get_error(canl_ctx cc, char ** reason);
 int canl_io_close(canl_ctx cc, canl_io_handler io);
 int canl_io_destroy(canl_ctx cc, canl_io_handler io);
 
index 29cd7fd..ea316d1 100644 (file)
@@ -16,13 +16,22 @@ void update_error (glb_ctx *cc, CANL_ERROR err_code, const char *err_format, ...
     va_list ap;
     char *new_msg;
 
-    if (err_format == NULL)
+    if (!cc)
         return;
 
+    if (err_format == NULL) {
+        if (!err_code)
+            return;
+        else {
+            cc->err_code = err_code;
+            return;
+        }
+    }
+
     va_start(ap, err_format);
 
-    if (!(*cc->err_msg)) {
-        vasprintf(&cc->err_msg,err_format, ap);
+    if (!(cc->err_msg)) {
+        vasprintf(&cc->err_msg, err_format, ap);
         va_end(ap);
         return;
     }
@@ -77,7 +86,7 @@ void reset_error (glb_ctx *cc, CANL_ERROR err_code)
 }
 
 /* Provide human readable information about errors */
-size_t canl_get_error(canl_ctx cc, char  **reason)
+int canl_get_error(canl_ctx cc, char  **reason)
 {
     int err = 0;
     int error_length = 0;
@@ -86,19 +95,16 @@ size_t canl_get_error(canl_ctx cc, char  **reason)
 
     /*check cc*/
     if (!ctx) {
-        err = 1;
-        goto end;
+        return EINVAL;
     }
 
-    if (!ctx->err_msg) {
-        err = 1;
+    if (!ctx->err_msg)
         goto end;
-    }
 
     error_length = strlen(ctx->err_msg);
     new_error = (char *) malloc ((error_length + 1) * sizeof (char));
     if (!new_error) {
-        err = 1; //TODO errno
+        err = ENOMEM;
         goto end;
     }
 
@@ -106,5 +112,7 @@ size_t canl_get_error(canl_ctx cc, char  **reason)
     *reason = new_error;
 
 end:
+    if (err)
+        update_error(ctx, err, "cannot get error message (canl_get_error)");
     return err;
 }
index 4d5e9a4..0d0ee31 100644 (file)
@@ -1,5 +1,6 @@
 #ifndef CANL_LOCL_H
 #define CANL_LOCL_H
+#include <errno.h>
 #include "canl_err.h"
 #include <ares.h>
 #include <ares_version.h>