2
0

errors.odin 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. package net
  2. /*
  3. Retrieve a platform specific error code, for when the categorized cross-platform errors are not enough.
  4. Platforms specific returns:
  5. - Darwin: `posix.Errno` (`core:sys/posix`)
  6. - Linux: `linux.Errno` (`core:sys/linux`)
  7. - FreeBSD: `freebsd.Errno` (`core:sys/freebsd`)
  8. - Windows: `windows.System_Error` (`core:sys/windows`)
  9. */
  10. @(require_results)
  11. last_platform_error :: proc() -> i32 {
  12. return _last_platform_error()
  13. }
  14. /*
  15. Retrieve a stringified version of the last platform error.
  16. */
  17. @(require_results)
  18. last_platform_error_string :: proc() -> string {
  19. return _last_platform_error_string()
  20. }
  21. set_last_platform_error :: proc(err: i32) {
  22. _set_last_platform_error(err)
  23. }
  24. Create_Socket_Error :: enum i32 {
  25. None,
  26. // No network connection, or the network stack is not initialized.
  27. Network_Unreachable,
  28. // Not enough space in internal tables/buffers to create a new socket, or an unsupported protocol is given.
  29. Insufficient_Resources,
  30. // Invalid/unsupported family or protocol.
  31. Invalid_Argument,
  32. // The user has no permission to create a socket of this type and/or protocol.
  33. Insufficient_Permissions,
  34. // An error unable to be categorized in above categories, `last_platform_error` may have more info.
  35. Unknown,
  36. }
  37. Dial_Error :: enum i32 {
  38. None,
  39. // No network connection, or the network stack is not initialized.
  40. Network_Unreachable,
  41. // Not enough space in internal tables/buffers to create a new socket, or an unsupported protocol is given.
  42. Insufficient_Resources,
  43. // Invalid endpoint and/or options.
  44. Invalid_Argument,
  45. // An attempt was made to connect to a broadcast socket on a socket that doesn't support it.
  46. Broadcast_Not_Supported,
  47. // The socket is already connected.
  48. Already_Connected,
  49. // The socket is already in the progress of making a connection.
  50. Already_Connecting,
  51. // The address is already in use.
  52. Address_In_Use,
  53. // Could not reach the remote host.
  54. Host_Unreachable,
  55. // The remote host refused the connection or isn't listening.
  56. Refused,
  57. // The connection was reset by the remote host.
  58. Reset,
  59. // Timed out before making a connection.
  60. Timeout,
  61. // Non-blocking socket that would need to block waiting to connect.
  62. Would_Block,
  63. // Interrupted by a signal or other method of cancellation like WSACancelBlockingCall on Windows.
  64. Interrupted,
  65. // Endpoint given without a port, which is required.
  66. Port_Required,
  67. // An error unable to be categorized in above categories, `last_platform_error` may have more info.
  68. Unknown,
  69. }
  70. Bind_Error :: enum i32 {
  71. None,
  72. // No network connection, or the network stack is not initialized.
  73. Network_Unreachable,
  74. // Not enough space in internal tables/buffers to create a new socket, or an unsupported protocol is given.
  75. Insufficient_Resources,
  76. // Invalid socket or endpoint, or invalid combination of the two.
  77. Invalid_Argument,
  78. // The socket is already bound to an address.
  79. Already_Bound,
  80. // The address is protected and the current user has insufficient permissions to access it.
  81. Insufficient_Permissions_For_Address,
  82. // The address is already in use.
  83. Address_In_Use,
  84. // An error unable to be categorized in above categories, `last_platform_error` may have more info.
  85. Unknown,
  86. }
  87. Listen_Error :: enum i32 {
  88. None,
  89. // No network connection, or the network stack is not initialized.
  90. Network_Unreachable,
  91. // Not enough space in internal tables/buffers to create a new socket, or an unsupported protocol is given.
  92. Insufficient_Resources,
  93. // The socket or backlog is invalid.
  94. Invalid_Argument,
  95. // The socket is valid, but does not support listening.
  96. Unsupported_Socket,
  97. // The socket is already connected.
  98. Already_Connected,
  99. // The address is already in use.
  100. Address_In_Use,
  101. // An error unable to be categorized in above categories, `last_platform_error` may have more info.
  102. Unknown,
  103. }
  104. Accept_Error :: enum i32 {
  105. None,
  106. // No network connection, or the network stack is not initialized.
  107. Network_Unreachable,
  108. // Not enough space in internal tables/buffers to create a new socket, or an unsupported protocol is given.
  109. Insufficient_Resources,
  110. // Invalid socket, or options.
  111. Invalid_Argument,
  112. // The given socket does not support accepting connections.
  113. Unsupported_Socket,
  114. // accept called on a socket which is not listening.
  115. Not_Listening,
  116. // A connection arrived but was closed while in the listen queue.
  117. Aborted,
  118. // Timed out before being able to accept a connection.
  119. Timeout,
  120. // Non-blocking socket that would need to block waiting for a connection.
  121. Would_Block,
  122. // Interrupted by a signal or other method of cancellation like WSACancelBlockingCall on Windows.
  123. Interrupted,
  124. // An error unable to be categorized in above categories, `last_platform_error` may have more info.
  125. Unknown,
  126. }
  127. TCP_Recv_Error :: enum i32 {
  128. None,
  129. // No network connection, or the network stack is not initialized.
  130. Network_Unreachable,
  131. // Not enough space in internal tables/buffers to create a new socket, or an unsupported protocol is given.
  132. Insufficient_Resources,
  133. // Invalid socket or buffer given.
  134. Invalid_Argument,
  135. // The socket is not connected.
  136. Not_Connected,
  137. // Connection was closed/broken/shutdown while receiving data.
  138. Connection_Closed,
  139. // Timed out before being able to receive any data.
  140. Timeout,
  141. // Non-blocking socket that would need to block waiting on data.
  142. Would_Block,
  143. // Interrupted by a signal or other method of cancellation like WSACancelBlockingCall on Windows.
  144. Interrupted,
  145. // An error unable to be categorized in above categories, `last_platform_error` may have more info.
  146. Unknown,
  147. }
  148. UDP_Recv_Error :: enum i32 {
  149. None,
  150. // No network connection, or the network stack is not initialized.
  151. Network_Unreachable,
  152. // Not enough space in internal tables/buffers to create a new socket, or an unsupported protocol is given.
  153. Insufficient_Resources,
  154. // Invalid socket or buffer given.
  155. Invalid_Argument,
  156. // "Connection" was refused by remote, or closed/broken/shutdown while receiving data.
  157. Connection_Refused,
  158. // Timed out before being able to receive any data.
  159. Timeout,
  160. // Non-blocking socket that would need to block waiting on data.
  161. Would_Block,
  162. // Interrupted by a signal or other method of cancellation like WSACancelBlockingCall on Windows.
  163. Interrupted,
  164. // Linux and UDP only: indicates the buffer was too small to receive all data, and the excess is truncated and discarded.
  165. Excess_Truncated,
  166. // An error unable to be categorized in above categories, `last_platform_error` may have more info.
  167. Unknown,
  168. }
  169. TCP_Send_Error :: enum i32 {
  170. None,
  171. // No network connection, or the network stack is not initialized.
  172. Network_Unreachable,
  173. // Not enough space in internal tables/buffers to create a new socket, or an unsupported protocol is given.
  174. Insufficient_Resources,
  175. // Invalid socket or buffer given.
  176. Invalid_Argument,
  177. // Connection was closed/broken/shutdown while receiving data.
  178. Connection_Closed,
  179. // The socket is not connected.
  180. Not_Connected,
  181. // Could not reach the remote host.
  182. Host_Unreachable,
  183. // Timed out before being able to send any data.
  184. Timeout,
  185. // Non-blocking socket that would need to block waiting on the remote to be able to receive the data.
  186. Would_Block,
  187. // Interrupted by a signal or other method of cancellation like WSACancelBlockingCall on Windows.
  188. Interrupted,
  189. // An error unable to be categorized in above categories, `last_platform_error` may have more info.
  190. Unknown,
  191. }
  192. UDP_Send_Error :: enum i32 {
  193. None,
  194. // No network connection, or the network stack is not initialized.
  195. Network_Unreachable,
  196. // Not enough space in internal tables/buffers to create a new socket, or an unsupported protocol is given.
  197. Insufficient_Resources,
  198. // Invalid socket or buffer given.
  199. Invalid_Argument,
  200. // Could not reach the remote host.
  201. Host_Unreachable,
  202. // "Connection" was refused by remote, or closed/broken/shutdown while sending data.
  203. Connection_Refused,
  204. // Timed out before being able to send any data.
  205. Timeout,
  206. // Non-blocking socket that would need to block waiting on the remote to be able to receive the data.
  207. Would_Block,
  208. // Interrupted by a signal or other method of cancellation like WSACancelBlockingCall on Windows.
  209. Interrupted,
  210. // An error unable to be categorized in above categories, `last_platform_error` may have more info.
  211. Unknown,
  212. }
  213. Shutdown_Error :: enum i32 {
  214. None,
  215. // No network connection, or the network stack is not initialized.
  216. Network_Unreachable,
  217. // Socket is invalid or not connected, or the manner given is invalid.
  218. Invalid_Argument,
  219. // Connection was closed/aborted/shutdown.
  220. Connection_Closed,
  221. // An error unable to be categorized in above categories, `last_platform_error` may have more info.
  222. Unknown,
  223. }
  224. Socket_Info_Error :: enum i32 {
  225. None,
  226. // No network connection, or the network stack is not initialized.
  227. Network_Unreachable,
  228. // Not enough space in internal tables/buffers to create a new socket, or an unsupported protocol is given.
  229. Insufficient_Resources,
  230. // Socket is invalid or not connected, or the manner given is invalid.
  231. Invalid_Argument,
  232. // The socket is valid, but unsupported by this opperation.
  233. Unsupported_Socket,
  234. // Connection was closed/aborted/shutdown.
  235. Connection_Closed,
  236. // An error unable to be categorized in above categories, `last_platform_error` may have more info.
  237. Unknown,
  238. }
  239. Socket_Option_Error :: enum i32 {
  240. None,
  241. // No network connection, or the network stack is not initialized.
  242. Network_Unreachable,
  243. // Not enough space in internal tables/buffers to create a new socket, or an unsupported protocol is given.
  244. Insufficient_Resources,
  245. // Socket is invalid, not connected, or the connection has been closed/reset/shutdown.
  246. Invalid_Socket,
  247. // Unknown or unsupported option for the socket.
  248. Invalid_Option,
  249. // Invalid level or value.
  250. Invalid_Value,
  251. // An error unable to be categorized in above categories, `last_platform_error` may have more info.
  252. Unknown,
  253. }
  254. Set_Blocking_Error :: enum i32 {
  255. None,
  256. // No network connection, or the network stack is not initialized.
  257. Network_Unreachable,
  258. // Socket is invalid.
  259. Invalid_Argument,
  260. // An error unable to be categorized in above categories, `last_platform_error` may have more info.
  261. Unknown,
  262. }