Integer type name change.
[silc.git] / lib / silcutil / unix / silcunixsockconn.c
index 330bab2dafa8631610875b698a913bc08dd36c5d..dada9d6e73cb49a2255f88ae64bd04abe12d51ed 100644 (file)
@@ -45,7 +45,8 @@ int silc_socket_write(SilcSocketConnection sock)
        SILC_LOG_DEBUG(("Could not write immediately, will do it later"));
        return -2;
       }
-      SILC_LOG_ERROR(("Cannot write to socket: %s", strerror(errno)));
+      SILC_LOG_DEBUG(("Cannot write to socket: %s", strerror(errno)));
+      sock->sock_error = errno;
       return -1;
     }
 
@@ -80,7 +81,8 @@ int silc_socket_read(SilcSocketConnection sock)
       SILC_LOG_DEBUG(("Could not read immediately, will do it later"));
       return -2;
     }
-    SILC_LOG_ERROR(("Cannot read from socket: %d:%s", fd, strerror(errno)));
+    SILC_LOG_DEBUG(("Cannot read from socket: %d:%s", fd, strerror(errno)));
+    sock->sock_error = errno;
     return -1;
   }
 
@@ -103,3 +105,22 @@ int silc_socket_read(SilcSocketConnection sock)
 
   return len;
 }
+
+/* Returns human readable socket error message */
+
+bool silc_socket_get_error(SilcSocketConnection sock, char *error,
+                          SilcUInt32 error_len)
+{
+  char *err;
+
+  if (!sock->sock_error)
+    return FALSE;
+
+  err = strerror(sock->sock_error);
+  if (strlen(err) > error_len)
+    return FALSE;
+
+  memset(error, 0, error_len);
+  memcpy(error, err, strlen(err));
+  return TRUE;
+}