1 /** @file
2 
3   Error code defines
4 
5   @section license License
6 
7   Licensed to the Apache Software Foundation (ASF) under one
8   or more contributor license agreements.  See the NOTICE file
9   distributed with this work for additional information
10   regarding copyright ownership.  The ASF licenses this file
11   to you under the Apache License, Version 2.0 (the
12   "License"); you may not use this file except in compliance
13   with the License.  You may obtain a copy of the License at
14 
15       http://www.apache.org/licenses/LICENSE-2.0
16 
17   Unless required by applicable law or agreed to in writing, software
18   distributed under the License is distributed on an "AS IS" BASIS,
19   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   See the License for the specific language governing permissions and
21   limitations under the License.
22 */
23 
24 #include "tscore/InkErrno.h"
25 #include "tscore/ink_assert.h"
26 #include <cstring>
27 
28 const char *
InkStrerror(int ink_errno)29 InkStrerror(int ink_errno)
30 {
31   if (ink_errno < INK_START_ERRNO) {
32     return strerror(ink_errno);
33   }
34 
35   switch (ink_errno) {
36   case ENET_THROTTLING:
37     return "ENET_THROTTLING";
38   case ENET_CONNECT_TIMEOUT:
39     return "ENET_CONNECT_TIMEOUT";
40   case ENET_CONNECT_FAILED:
41     return "ENET_CONNECT_FAILED";
42   case ENET_SSL_CONNECT_FAILED:
43     return "ENET_SSL_CONNECT_FAILED";
44   case ENET_SSL_FAILED:
45     return "ENET_SSL_FAILED";
46   case ESOCK_DENIED:
47     return "ESOCK_DENIED";
48   case ESOCK_TIMEOUT:
49     return "ESOCK_TIMEOUT";
50   case ESOCK_NO_SOCK_SERVER_CONN:
51     return "ESOCK_NO_SOCK_SERVER_CONN";
52   case ECACHE_NO_DOC:
53     return "ECACHE_NO_DOC";
54   case ECACHE_DOC_BUSY:
55     return "ECACHE_DOC_BUSY";
56   case ECACHE_DIR_BAD:
57     return "ECACHE_DIR_BAD";
58   case ECACHE_BAD_META_DATA:
59     return "ECACHE_BAD_META_DATA";
60   case ECACHE_READ_FAIL:
61     return "ECACHE_READ_FAIL";
62   case ECACHE_WRITE_FAIL:
63     return "ECACHE_WRITE_FAIL";
64   case ECACHE_MAX_ALT_EXCEEDED:
65     return "ECACHE_MAX_ALT_EXCEEDED";
66   case ECACHE_NOT_READY:
67     return "ECACHE_NOT_READY";
68   case ECACHE_ALT_MISS:
69     return "ECACHE_ALT_MISS";
70   case ECACHE_BAD_READ_REQUEST:
71     return "ECACHE_BAD_READ_REQUEST";
72   case EHTTP_ERROR:
73     return "EHTTP_ERROR";
74   }
75 
76   if (ink_errno > HTTP_ERRNO) {
77     return "EHTTP (unknown)";
78   }
79 
80   if (ink_errno > CACHE_ERRNO) {
81     return "ECACHE (unknown)";
82   }
83 
84   if (ink_errno > NET_ERRNO) {
85     return "ENET (unknown)";
86   }
87 
88   // Verify there are no holes in the error ranges.
89   ink_assert(INK_START_ERRNO == SOCK_ERRNO);
90   ink_assert(ink_errno > SOCK_ERRNO);
91 
92   return "ESOCK (unknown)";
93 }
94