uv_errno.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
  2. * Copyright (c) 2016-2019 xiongziliang <771730766@qq.com>
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to
  5. * deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  7. * sell copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  18. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  19. * IN THE SOFTWARE.
  20. */
  21. #ifndef UV_ERRNO_H_
  22. #define UV_ERRNO_H_
  23. #include <errno.h>
  24. #define UV__EOF (-4095)
  25. #define UV__UNKNOWN (-4094)
  26. #define UV__EAI_ADDRFAMILY (-3000)
  27. #define UV__EAI_AGAIN (-3001)
  28. #define UV__EAI_BADFLAGS (-3002)
  29. #define UV__EAI_CANCELED (-3003)
  30. #define UV__EAI_FAIL (-3004)
  31. #define UV__EAI_FAMILY (-3005)
  32. #define UV__EAI_MEMORY (-3006)
  33. #define UV__EAI_NODATA (-3007)
  34. #define UV__EAI_NONAME (-3008)
  35. #define UV__EAI_OVERFLOW (-3009)
  36. #define UV__EAI_SERVICE (-3010)
  37. #define UV__EAI_SOCKTYPE (-3011)
  38. #define UV__EAI_BADHINTS (-3013)
  39. #define UV__EAI_PROTOCOL (-3014)
  40. /* Only map to the system errno on non-Windows platforms. It's apparently
  41. * a fairly common practice for Windows programmers to redefine errno codes.
  42. */
  43. #if defined(E2BIG) && !defined(_WIN32)
  44. # define UV__E2BIG (-E2BIG)
  45. #else
  46. # define UV__E2BIG (-4093)
  47. #endif
  48. #if defined(EACCES) && !defined(_WIN32)
  49. # define UV__EACCES (-EACCES)
  50. #else
  51. # define UV__EACCES (-4092)
  52. #endif
  53. #if defined(EADDRINUSE) && !defined(_WIN32)
  54. # define UV__EADDRINUSE (-EADDRINUSE)
  55. #else
  56. # define UV__EADDRINUSE (-4091)
  57. #endif
  58. #if defined(EADDRNOTAVAIL) && !defined(_WIN32)
  59. # define UV__EADDRNOTAVAIL (-EADDRNOTAVAIL)
  60. #else
  61. # define UV__EADDRNOTAVAIL (-4090)
  62. #endif
  63. #if defined(EAFNOSUPPORT) && !defined(_WIN32)
  64. # define UV__EAFNOSUPPORT (-EAFNOSUPPORT)
  65. #else
  66. # define UV__EAFNOSUPPORT (-4089)
  67. #endif
  68. #if defined(EAGAIN) && !defined(_WIN32)
  69. # define UV__EAGAIN (-EAGAIN)
  70. #else
  71. # define UV__EAGAIN (-4088)
  72. #endif
  73. #if defined(EALREADY) && !defined(_WIN32)
  74. # define UV__EALREADY (-EALREADY)
  75. #else
  76. # define UV__EALREADY (-4084)
  77. #endif
  78. #if defined(EBADF) && !defined(_WIN32)
  79. # define UV__EBADF (-EBADF)
  80. #else
  81. # define UV__EBADF (-4083)
  82. #endif
  83. #if defined(EBUSY) && !defined(_WIN32)
  84. # define UV__EBUSY (-EBUSY)
  85. #else
  86. # define UV__EBUSY (-4082)
  87. #endif
  88. #if defined(ECANCELED) && !defined(_WIN32)
  89. # define UV__ECANCELED (-ECANCELED)
  90. #else
  91. # define UV__ECANCELED (-4081)
  92. #endif
  93. #if defined(ECHARSET) && !defined(_WIN32)
  94. # define UV__ECHARSET (-ECHARSET)
  95. #else
  96. # define UV__ECHARSET (-4080)
  97. #endif
  98. #if defined(ECONNABORTED) && !defined(_WIN32)
  99. # define UV__ECONNABORTED (-ECONNABORTED)
  100. #else
  101. # define UV__ECONNABORTED (-4079)
  102. #endif
  103. #if defined(ECONNREFUSED) && !defined(_WIN32)
  104. # define UV__ECONNREFUSED (-ECONNREFUSED)
  105. #else
  106. # define UV__ECONNREFUSED (-4078)
  107. #endif
  108. #if defined(ECONNRESET) && !defined(_WIN32)
  109. # define UV__ECONNRESET (-ECONNRESET)
  110. #else
  111. # define UV__ECONNRESET (-4077)
  112. #endif
  113. #if defined(EDESTADDRREQ) && !defined(_WIN32)
  114. # define UV__EDESTADDRREQ (-EDESTADDRREQ)
  115. #else
  116. # define UV__EDESTADDRREQ (-4076)
  117. #endif
  118. #if defined(EEXIST) && !defined(_WIN32)
  119. # define UV__EEXIST (-EEXIST)
  120. #else
  121. # define UV__EEXIST (-4075)
  122. #endif
  123. #if defined(EFAULT) && !defined(_WIN32)
  124. # define UV__EFAULT (-EFAULT)
  125. #else
  126. # define UV__EFAULT (-4074)
  127. #endif
  128. #if defined(EHOSTUNREACH) && !defined(_WIN32)
  129. # define UV__EHOSTUNREACH (-EHOSTUNREACH)
  130. #else
  131. # define UV__EHOSTUNREACH (-4073)
  132. #endif
  133. #if defined(EINTR) && !defined(_WIN32)
  134. # define UV__EINTR (-EINTR)
  135. #else
  136. # define UV__EINTR (-4072)
  137. #endif
  138. #if defined(EINVAL) && !defined(_WIN32)
  139. # define UV__EINVAL (-EINVAL)
  140. #else
  141. # define UV__EINVAL (-4071)
  142. #endif
  143. #if defined(EIO) && !defined(_WIN32)
  144. # define UV__EIO (-EIO)
  145. #else
  146. # define UV__EIO (-4070)
  147. #endif
  148. #if defined(EISCONN) && !defined(_WIN32)
  149. # define UV__EISCONN (-EISCONN)
  150. #else
  151. # define UV__EISCONN (-4069)
  152. #endif
  153. #if defined(EISDIR) && !defined(_WIN32)
  154. # define UV__EISDIR (-EISDIR)
  155. #else
  156. # define UV__EISDIR (-4068)
  157. #endif
  158. #if defined(ELOOP) && !defined(_WIN32)
  159. # define UV__ELOOP (-ELOOP)
  160. #else
  161. # define UV__ELOOP (-4067)
  162. #endif
  163. #if defined(EMFILE) && !defined(_WIN32)
  164. # define UV__EMFILE (-EMFILE)
  165. #else
  166. # define UV__EMFILE (-4066)
  167. #endif
  168. #if defined(EMSGSIZE) && !defined(_WIN32)
  169. # define UV__EMSGSIZE (-EMSGSIZE)
  170. #else
  171. # define UV__EMSGSIZE (-4065)
  172. #endif
  173. #if defined(ENAMETOOLONG) && !defined(_WIN32)
  174. # define UV__ENAMETOOLONG (-ENAMETOOLONG)
  175. #else
  176. # define UV__ENAMETOOLONG (-4064)
  177. #endif
  178. #if defined(ENETDOWN) && !defined(_WIN32)
  179. # define UV__ENETDOWN (-ENETDOWN)
  180. #else
  181. # define UV__ENETDOWN (-4063)
  182. #endif
  183. #if defined(ENETUNREACH) && !defined(_WIN32)
  184. # define UV__ENETUNREACH (-ENETUNREACH)
  185. #else
  186. # define UV__ENETUNREACH (-4062)
  187. #endif
  188. #if defined(ENFILE) && !defined(_WIN32)
  189. # define UV__ENFILE (-ENFILE)
  190. #else
  191. # define UV__ENFILE (-4061)
  192. #endif
  193. #if defined(ENOBUFS) && !defined(_WIN32)
  194. # define UV__ENOBUFS (-ENOBUFS)
  195. #else
  196. # define UV__ENOBUFS (-4060)
  197. #endif
  198. #if defined(ENODEV) && !defined(_WIN32)
  199. # define UV__ENODEV (-ENODEV)
  200. #else
  201. # define UV__ENODEV (-4059)
  202. #endif
  203. #if defined(ENOENT) && !defined(_WIN32)
  204. # define UV__ENOENT (-ENOENT)
  205. #else
  206. # define UV__ENOENT (-4058)
  207. #endif
  208. #if defined(ENOMEM) && !defined(_WIN32)
  209. # define UV__ENOMEM (-ENOMEM)
  210. #else
  211. # define UV__ENOMEM (-4057)
  212. #endif
  213. #if defined(ENONET) && !defined(_WIN32)
  214. # define UV__ENONET (-ENONET)
  215. #else
  216. # define UV__ENONET (-4056)
  217. #endif
  218. #if defined(ENOSPC) && !defined(_WIN32)
  219. # define UV__ENOSPC (-ENOSPC)
  220. #else
  221. # define UV__ENOSPC (-4055)
  222. #endif
  223. #if defined(ENOSYS) && !defined(_WIN32)
  224. # define UV__ENOSYS (-ENOSYS)
  225. #else
  226. # define UV__ENOSYS (-4054)
  227. #endif
  228. #if defined(ENOTCONN) && !defined(_WIN32)
  229. # define UV__ENOTCONN (-ENOTCONN)
  230. #else
  231. # define UV__ENOTCONN (-4053)
  232. #endif
  233. #if defined(ENOTDIR) && !defined(_WIN32)
  234. # define UV__ENOTDIR (-ENOTDIR)
  235. #else
  236. # define UV__ENOTDIR (-4052)
  237. #endif
  238. #if defined(ENOTEMPTY) && !defined(_WIN32)
  239. # define UV__ENOTEMPTY (-ENOTEMPTY)
  240. #else
  241. # define UV__ENOTEMPTY (-4051)
  242. #endif
  243. #if defined(ENOTSOCK) && !defined(_WIN32)
  244. # define UV__ENOTSOCK (-ENOTSOCK)
  245. #else
  246. # define UV__ENOTSOCK (-4050)
  247. #endif
  248. #if defined(ENOTSUP) && !defined(_WIN32)
  249. # define UV__ENOTSUP (-ENOTSUP)
  250. #else
  251. # define UV__ENOTSUP (-4049)
  252. #endif
  253. #if defined(EPERM) && !defined(_WIN32)
  254. # define UV__EPERM (-EPERM)
  255. #else
  256. # define UV__EPERM (-4048)
  257. #endif
  258. #if defined(EPIPE) && !defined(_WIN32)
  259. # define UV__EPIPE (-EPIPE)
  260. #else
  261. # define UV__EPIPE (-4047)
  262. #endif
  263. #if defined(EPROTO) && !defined(_WIN32)
  264. # define UV__EPROTO (-EPROTO)
  265. #else
  266. # define UV__EPROTO (-4046)
  267. #endif
  268. #if defined(EPROTONOSUPPORT) && !defined(_WIN32)
  269. # define UV__EPROTONOSUPPORT (-EPROTONOSUPPORT)
  270. #else
  271. # define UV__EPROTONOSUPPORT (-4045)
  272. #endif
  273. #if defined(EPROTOTYPE) && !defined(_WIN32)
  274. # define UV__EPROTOTYPE (-EPROTOTYPE)
  275. #else
  276. # define UV__EPROTOTYPE (-4044)
  277. #endif
  278. #if defined(EROFS) && !defined(_WIN32)
  279. # define UV__EROFS (-EROFS)
  280. #else
  281. # define UV__EROFS (-4043)
  282. #endif
  283. #if defined(ESHUTDOWN) && !defined(_WIN32)
  284. # define UV__ESHUTDOWN (-ESHUTDOWN)
  285. #else
  286. # define UV__ESHUTDOWN (-4042)
  287. #endif
  288. #if defined(ESPIPE) && !defined(_WIN32)
  289. # define UV__ESPIPE (-ESPIPE)
  290. #else
  291. # define UV__ESPIPE (-4041)
  292. #endif
  293. #if defined(ESRCH) && !defined(_WIN32)
  294. # define UV__ESRCH (-ESRCH)
  295. #else
  296. # define UV__ESRCH (-4040)
  297. #endif
  298. #if defined(ETIMEDOUT) && !defined(_WIN32)
  299. # define UV__ETIMEDOUT (-ETIMEDOUT)
  300. #else
  301. # define UV__ETIMEDOUT (-4039)
  302. #endif
  303. #if defined(ETXTBSY) && !defined(_WIN32)
  304. # define UV__ETXTBSY (-ETXTBSY)
  305. #else
  306. # define UV__ETXTBSY (-4038)
  307. #endif
  308. #if defined(EXDEV) && !defined(_WIN32)
  309. # define UV__EXDEV (-EXDEV)
  310. #else
  311. # define UV__EXDEV (-4037)
  312. #endif
  313. #if defined(EFBIG) && !defined(_WIN32)
  314. # define UV__EFBIG (-EFBIG)
  315. #else
  316. # define UV__EFBIG (-4036)
  317. #endif
  318. #if defined(ENOPROTOOPT) && !defined(_WIN32)
  319. # define UV__ENOPROTOOPT (-ENOPROTOOPT)
  320. #else
  321. # define UV__ENOPROTOOPT (-4035)
  322. #endif
  323. #if defined(ERANGE) && !defined(_WIN32)
  324. # define UV__ERANGE (-ERANGE)
  325. #else
  326. # define UV__ERANGE (-4034)
  327. #endif
  328. #if defined(ENXIO) && !defined(_WIN32)
  329. # define UV__ENXIO (-ENXIO)
  330. #else
  331. # define UV__ENXIO (-4033)
  332. #endif
  333. #if defined(EMLINK) && !defined(_WIN32)
  334. # define UV__EMLINK (-EMLINK)
  335. #else
  336. # define UV__EMLINK (-4032)
  337. #endif
  338. /* EHOSTDOWN is not visible on BSD-like systems when _POSIX_C_SOURCE is
  339. * defined. Fortunately, its value is always 64 so it's possible albeit
  340. * icky to hard-code it.
  341. */
  342. #if defined(EHOSTDOWN) && !defined(_WIN32)
  343. # define UV__EHOSTDOWN (-EHOSTDOWN)
  344. #elif defined(__APPLE__) || \
  345. defined(__DragonFly__) || \
  346. defined(__FreeBSD__) || \
  347. defined(__FreeBSD_kernel__) || \
  348. defined(__NetBSD__) || \
  349. defined(__OpenBSD__)
  350. # define UV__EHOSTDOWN (-64)
  351. #else
  352. # define UV__EHOSTDOWN (-4031)
  353. #endif
  354. #if defined(EREMOTEIO) && !defined(_WIN32)
  355. # define UV__EREMOTEIO (-EREMOTEIO)
  356. #else
  357. # define UV__EREMOTEIO (-4030)
  358. #endif
  359. #define UV_ERRNO_MAP(XX) \
  360. XX(E2BIG, "argument list too long") \
  361. XX(EACCES, "permission denied") \
  362. XX(EADDRINUSE, "address already in use") \
  363. XX(EADDRNOTAVAIL, "address not available") \
  364. XX(EAFNOSUPPORT, "address family not supported") \
  365. XX(EAGAIN, "resource temporarily unavailable") \
  366. XX(EAI_ADDRFAMILY, "address family not supported") \
  367. XX(EAI_AGAIN, "temporary failure") \
  368. XX(EAI_BADFLAGS, "bad ai_flags value") \
  369. XX(EAI_BADHINTS, "invalid value for hints") \
  370. XX(EAI_CANCELED, "request canceled") \
  371. XX(EAI_FAIL, "permanent failure") \
  372. XX(EAI_FAMILY, "ai_family not supported") \
  373. XX(EAI_MEMORY, "out of memory") \
  374. XX(EAI_NODATA, "no address") \
  375. XX(EAI_NONAME, "unknown node or service") \
  376. XX(EAI_OVERFLOW, "argument buffer overflow") \
  377. XX(EAI_PROTOCOL, "resolved protocol is unknown") \
  378. XX(EAI_SERVICE, "service not available for socket type") \
  379. XX(EAI_SOCKTYPE, "socket type not supported") \
  380. XX(EALREADY, "connection already in progress") \
  381. XX(EBADF, "bad file descriptor") \
  382. XX(EBUSY, "resource busy or locked") \
  383. XX(ECANCELED, "operation canceled") \
  384. XX(ECHARSET, "invalid Unicode character") \
  385. XX(ECONNABORTED, "software caused connection abort") \
  386. XX(ECONNREFUSED, "connection refused") \
  387. XX(ECONNRESET, "connection reset by peer") \
  388. XX(EDESTADDRREQ, "destination address required") \
  389. XX(EEXIST, "file already exists") \
  390. XX(EFAULT, "bad address in system call argument") \
  391. XX(EFBIG, "file too large") \
  392. XX(EHOSTUNREACH, "host is unreachable") \
  393. XX(EINTR, "interrupted system call") \
  394. XX(EINVAL, "invalid argument") \
  395. XX(EIO, "i/o error") \
  396. XX(EISCONN, "socket is already connected") \
  397. XX(EISDIR, "illegal operation on a directory") \
  398. XX(ELOOP, "too many symbolic links encountered") \
  399. XX(EMFILE, "too many open files") \
  400. XX(EMSGSIZE, "message too long") \
  401. XX(ENAMETOOLONG, "name too long") \
  402. XX(ENETDOWN, "network is down") \
  403. XX(ENETUNREACH, "network is unreachable") \
  404. XX(ENFILE, "file table overflow") \
  405. XX(ENOBUFS, "no buffer space available") \
  406. XX(ENODEV, "no such device") \
  407. XX(ENOENT, "no such file or directory") \
  408. XX(ENOMEM, "not enough memory") \
  409. XX(ENONET, "machine is not on the network") \
  410. XX(ENOPROTOOPT, "protocol not available") \
  411. XX(ENOSPC, "no space left on device") \
  412. XX(ENOSYS, "function not implemented") \
  413. XX(ENOTCONN, "socket is not connected") \
  414. XX(ENOTDIR, "not a directory") \
  415. XX(ENOTEMPTY, "directory not empty") \
  416. XX(ENOTSOCK, "socket operation on non-socket") \
  417. XX(ENOTSUP, "operation not supported on socket") \
  418. XX(EPERM, "operation not permitted") \
  419. XX(EPIPE, "broken pipe") \
  420. XX(EPROTO, "protocol error") \
  421. XX(EPROTONOSUPPORT, "protocol not supported") \
  422. XX(EPROTOTYPE, "protocol wrong type for socket") \
  423. XX(ERANGE, "result too large") \
  424. XX(EROFS, "read-only file system") \
  425. XX(ESHUTDOWN, "cannot send after transport endpoint shutdown") \
  426. XX(ESPIPE, "invalid seek") \
  427. XX(ESRCH, "no such process") \
  428. XX(ETIMEDOUT, "connection timed out") \
  429. XX(ETXTBSY, "text file is busy") \
  430. XX(EXDEV, "cross-device link not permitted") \
  431. XX(UNKNOWN, "unknown error") \
  432. XX(EOF, "end of file") \
  433. XX(ENXIO, "no such device or address") \
  434. XX(EMLINK, "too many links") \
  435. XX(EHOSTDOWN, "host is down") \
  436. XX(EREMOTEIO, "remote I/O error") \
  437. typedef enum {
  438. #define XX(code, _) UV_ ## code = UV__ ## code,
  439. UV_ERRNO_MAP(XX)
  440. #undef XX
  441. UV_ERRNO_MAX = UV__EOF - 1
  442. } uv_errno_t;
  443. const char* uv_err_name(int err);
  444. const char* uv_strerror(int err);
  445. int uv_translate_posix_error(int err);
  446. //netErr参数在windows平台下才有效
  447. int get_uv_error(bool netErr = true);
  448. //netErr参数在windows平台下才有效
  449. const char* get_uv_errmsg(bool netErr = true);
  450. #endif /* UV_ERRNO_H_ */