OSSP CVS Repository

ossp - Check-in [1032]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 1032
Date: 2001-Sep-24 17:36:23 (local)
2001-Sep-24 15:36:23 (UTC)
User:rse
Branch:
Comment: Provide convinient channel error handling functions.
Tickets:
Inspections:
Files:
ossp-pkg/l2/l2_channel.c      1.18 -> 1.19     67 inserted, 0 deleted
ossp-pkg/l2/l2_p.h      1.20 -> 1.21     3 inserted, 0 deleted

ossp-pkg/l2/l2_channel.c 1.18 -> 1.19

--- l2_channel.c 2001/09/13 12:50:26     1.18
+++ l2_channel.c 2001/09/24 15:36:23     1.19
@@ -51,6 +51,9 @@
     ch->downstream = NULL;
     memset(&ch->context, 0, sizeof(l2_context_t));
     memcpy(&ch->handler, h, sizeof(l2_handler_t));
+    ch->rvErrorInfo = L2_OK;
+    ch->szErrorInfo[0] = '\0';
+    ch->szError[0] = '\0';
 
     /* (optionally) perform create operation in handler */
     if (ch->handler.create != NULL) {
@@ -229,6 +232,70 @@
     return rv;
 }
 
+l2_result_t l2_channel_errorinfo(l2_channel_t *ch, l2_result_t rv, const char *fmt, ...)
+{
+    va_list ap;
+
+    /* argument sanity check */
+    if (ch == NULL || rv == L2_OK || fmt == NULL)
+        return L2_ERR_ARG;
+
+    /* remember error information */
+    va_start(ap, fmt);
+    l2_util_vsprintf(ch->szErrorInfo, sizeof(ch->szErrorInfo), fmt, ap);
+    ch->rvErrorInfo = rv;
+    va_end(ap);
+
+    return L2_OK;
+}
+
+char *l2_channel_strerror(l2_channel_t *ch, l2_result_t rv)
+{
+    char *sz;
+    char *cpBuf;
+    int nBuf;
+    int n;
+
+    /* argument sanity check */
+    if (ch == NULL)
+        return NULL;
+
+    /* start at begin of buffer */
+    cpBuf = ch->szError;
+    nBuf  = sizeof(ch->szError);
+
+    /* translate result value into corresponding string */
+    if      (rv == L2_OK)      sz = "everything ok";
+    else if (rv == L2_ERR_ARG) sz = "invalid argument";
+    else if (rv == L2_ERR_USE) sz = "invalid use";
+    else if (rv == L2_ERR_MEM) sz = "no more memory available";
+    else if (rv == L2_ERR_SYS) sz = "operating system error";
+    else if (rv == L2_ERR_IO)  sz = "input/output error";
+    else if (rv == L2_ERR_FMT) sz = "formatting error";
+    else if (rv == L2_ERR_INT) sz = "internal error";
+    else                       sz = "unknown error";
+    n = l2_util_sprintf(cpBuf, nBuf, "%s", sz);
+    cpBuf += n;
+    nBuf  -= n;
+
+    /* optionally annotate with error information */
+    if (rv == ch->rvErrorInfo && ch->szErrorInfo[0] != '\0') {
+        n = l2_util_sprintf(cpBuf, nBuf, "; %s", ch->szErrorInfo);
+        cpBuf += n;
+        nBuf  -= n;
+    }
+
+    /* optionally annotate with operating system error information */
+    if (rv == L2_ERR_SYS) {
+        n = l2_util_sprintf(cpBuf, nBuf, "; %s (%d)", strerror(errno), errno);
+        cpBuf += n;
+        nBuf  -= n;
+    }
+
+    /* return pointer to internal buffer */
+    return ch->szError;
+}
+
 /* stack channel on top of another channel */
 l2_result_t l2_channel_stack(l2_channel_t *ch, l2_channel_t *chTop)
 {


ossp-pkg/l2/l2_p.h 1.20 -> 1.21

--- l2_p.h       2001/09/24 14:37:36     1.20
+++ l2_p.h       2001/09/24 15:36:23     1.21
@@ -77,6 +77,9 @@
     l2_channel_t *downstream;
     l2_context_t  context;
     l2_handler_t  handler;
+    char          szError[1024];
+    char          szErrorInfo[512];
+    l2_result_t   rvErrorInfo;
 };
 
 typedef struct {

CVSTrac 2.0.1