From b984dac55bdd0a5b694837fb8fb2ceb07ce9808f Mon Sep 17 00:00:00 2001
From: fujuntang <fujuntang@smartai.com>
Date: 星期二, 07 九月 2021 11:25:57 +0800
Subject: [PATCH] resize the buf allocation to dynamic buf.

---
 src/bus_error.cpp |   54 ++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 42 insertions(+), 12 deletions(-)

diff --git a/src/bus_error.cpp b/src/bus_error.cpp
index c2dd63a..29d5683 100644
--- a/src/bus_error.cpp
+++ b/src/bus_error.cpp
@@ -11,11 +11,21 @@
 static pthread_key_t strerrorKey;
 
 
-static char *_bus_errlist[_bus_nerr] = {
+static const char *_bus_errlist[_bus_nerr] = {
   "\0",
-  "timeout",
+  "Timed out",
   "The other end is not inline",
-  "Key already in use"
+  "Key already in use",
+  "Network fault",
+  "Send to self error",
+  "Receive from wrong end",
+  "Service stoped",
+  "Exceed resource limit",
+  "Service not supported",
+  "Resource busy",
+  "Resource not provide",
+  "Invalid parameters",
+  "No enough memory"
 
 };
 
@@ -43,8 +53,11 @@
 {
   int s;
   char *buf;
-
   /* Make first caller allocate key for thread-specific data */
+
+  if (err == 0) {
+    err = EBUS_BASE;
+  }
 
   s = pthread_once(&once, createKey);
   if (s != 0)
@@ -64,14 +77,31 @@
       err_exit(s, "pthread_setspecific");
   }
 
-  if (err < 0 || err >= _bus_nerr || _bus_errlist[err] == NULL)
-  {
-    snprintf(buf, MAX_ERROR_LEN, "Unknown error %d", err);
-  }
-  else
-  {
-    strncpy(buf, _bus_errlist[err], MAX_ERROR_LEN - 1);
-    buf[MAX_ERROR_LEN - 1] = '\0';          /* Ensure null termination */
+
+  if(err < EBUS_BASE) {
+    // libc閿欒
+    if (err < 0 || err >= _sys_nerr || _sys_errlist[err] == NULL)
+    {
+      snprintf(buf, MAX_ERROR_LEN, "Unknown error %d", err);
+    }
+    else
+    {
+      strncpy(buf, _sys_errlist[err], MAX_ERROR_LEN - 1);
+      buf[MAX_ERROR_LEN - 1] = '\0';          /* Ensure null termination */
+    }
+  } else {
+    //鑷畾涔夐敊璇�
+    err -= EBUS_BASE;
+    if (err < 0 || err >= _bus_nerr || _bus_errlist[err] == NULL)
+    {
+      snprintf(buf, MAX_ERROR_LEN, "Unknown error %d", err);
+    }
+    else
+    {
+      strncpy(buf, _bus_errlist[err], MAX_ERROR_LEN - 1);
+      buf[MAX_ERROR_LEN - 1] = '\0';          /* Ensure null termination */
+    }
+
   }
 
   return buf;

--
Gitblit v1.8.0