errors_darwin.odin 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. package net
  2. // +build darwin
  3. /*
  4. Package net implements cross-platform Berkeley Sockets, DNS resolution and associated procedures.
  5. For other protocols and their features, see subdirectories of this package.
  6. */
  7. /*
  8. Copyright 2022 Tetralux <[email protected]>
  9. Copyright 2022 Colin Davidson <[email protected]>
  10. Copyright 2022 Jeroen van Rijn <[email protected]>.
  11. Copyright 2024 Feoramund <[email protected]>.
  12. Made available under Odin's BSD-3 license.
  13. List of contributors:
  14. Tetralux: Initial implementation
  15. Colin Davidson: Linux platform code, OSX platform code, Odin-native DNS resolver
  16. Jeroen van Rijn: Cross platform unification, code style, documentation
  17. Feoramund: FreeBSD platform code
  18. */
  19. import "core:c"
  20. import "core:os"
  21. Create_Socket_Error :: enum c.int {
  22. None = 0,
  23. Family_Not_Supported_For_This_Socket = c.int(os.EAFNOSUPPORT),
  24. No_Socket_Descriptors_Available = c.int(os.EMFILE),
  25. No_Buffer_Space_Available = c.int(os.ENOBUFS),
  26. No_Memory_Available_Available = c.int(os.ENOMEM),
  27. Protocol_Unsupported_By_System = c.int(os.EPROTONOSUPPORT),
  28. Wrong_Protocol_For_Socket = c.int(os.EPROTONOSUPPORT),
  29. Family_And_Socket_Type_Mismatch = c.int(os.EPROTONOSUPPORT),
  30. }
  31. Dial_Error :: enum c.int {
  32. None = 0,
  33. Port_Required = -1, // Attempted to dial an endpointing without a port being set.
  34. Address_In_Use = c.int(os.EADDRINUSE),
  35. In_Progress = c.int(os.EINPROGRESS),
  36. Cannot_Use_Any_Address = c.int(os.EADDRNOTAVAIL),
  37. Wrong_Family_For_Socket = c.int(os.EAFNOSUPPORT),
  38. Refused = c.int(os.ECONNREFUSED),
  39. Is_Listening_Socket = c.int(os.EACCES),
  40. Already_Connected = c.int(os.EISCONN),
  41. Network_Unreachable = c.int(os.ENETUNREACH), // Device is offline
  42. Host_Unreachable = c.int(os.EHOSTUNREACH), // Remote host cannot be reached
  43. No_Buffer_Space_Available = c.int(os.ENOBUFS),
  44. Not_Socket = c.int(os.ENOTSOCK),
  45. Timeout = c.int(os.ETIMEDOUT),
  46. // TODO: we may need special handling for this; maybe make a socket a struct with metadata?
  47. Would_Block = c.int(os.EWOULDBLOCK),
  48. }
  49. Bind_Error :: enum c.int {
  50. None = 0,
  51. Privileged_Port_Without_Root = -1, // Attempted to bind to a port less than 1024 without root access.
  52. Address_In_Use = c.int(os.EADDRINUSE), // Another application is currently bound to this endpoint.
  53. Given_Nonlocal_Address = c.int(os.EADDRNOTAVAIL), // The address is not a local address on this machine.
  54. Broadcast_Disabled = c.int(os.EACCES), // To bind a UDP socket to the broadcast address, the appropriate socket option must be set.
  55. Address_Family_Mismatch = c.int(os.EFAULT), // The address family of the address does not match that of the socket.
  56. Already_Bound = c.int(os.EINVAL), // The socket is already bound to an address.
  57. No_Ports_Available = c.int(os.ENOBUFS), // There are not enough ephemeral ports available.
  58. }
  59. Listen_Error :: enum c.int {
  60. None = 0,
  61. Address_In_Use = c.int(os.EADDRINUSE),
  62. Already_Connected = c.int(os.EISCONN),
  63. No_Socket_Descriptors_Available = c.int(os.EMFILE),
  64. No_Buffer_Space_Available = c.int(os.ENOBUFS),
  65. Nonlocal_Address = c.int(os.EADDRNOTAVAIL),
  66. Not_Socket = c.int(os.ENOTSOCK),
  67. Listening_Not_Supported_For_This_Socket = c.int(os.EOPNOTSUPP),
  68. }
  69. Accept_Error :: enum c.int {
  70. None = 0,
  71. // TODO(tetra): Is this error actually possible here? Or is like Linux, in which case we can remove it.
  72. Reset = c.int(os.ECONNRESET),
  73. Not_Listening = c.int(os.EINVAL),
  74. No_Socket_Descriptors_Available_For_Client_Socket = c.int(os.EMFILE),
  75. No_Buffer_Space_Available = c.int(os.ENOBUFS),
  76. Not_Socket = c.int(os.ENOTSOCK),
  77. Not_Connection_Oriented_Socket = c.int(os.EOPNOTSUPP),
  78. // TODO: we may need special handling for this; maybe make a socket a struct with metadata?
  79. Would_Block = c.int(os.EWOULDBLOCK),
  80. }
  81. TCP_Recv_Error :: enum c.int {
  82. None = 0,
  83. Shutdown = c.int(os.ESHUTDOWN),
  84. Not_Connected = c.int(os.ENOTCONN),
  85. // TODO(tetra): Is this error actually possible here?
  86. Connection_Broken = c.int(os.ENETRESET),
  87. Not_Socket = c.int(os.ENOTSOCK),
  88. Aborted = c.int(os.ECONNABORTED),
  89. // TODO(tetra): Determine when this is different from the syscall returning n=0 and maybe normalize them?
  90. Connection_Closed = c.int(os.ECONNRESET),
  91. Offline = c.int(os.ENETDOWN),
  92. Host_Unreachable = c.int(os.EHOSTUNREACH),
  93. Interrupted = c.int(os.EINTR),
  94. // NOTE: No, really. Presumably this means something different for nonblocking sockets...
  95. Timeout = c.int(os.EWOULDBLOCK),
  96. }
  97. UDP_Recv_Error :: enum c.int {
  98. None = 0,
  99. Buffer_Too_Small = c.int(os.EMSGSIZE), // The buffer is too small to fit the entire message, and the message was truncated. When this happens, the rest of message is lost.
  100. Not_Socket = c.int(os.ENOTSOCK), // The so-called socket is not an open socket.
  101. Not_Descriptor = c.int(os.EBADF), // The so-called socket is, in fact, not even a valid descriptor.
  102. Bad_Buffer = c.int(os.EFAULT), // The buffer did not point to a valid location in memory.
  103. Interrupted = c.int(os.EINTR), // A signal occurred before any data was transmitted. See signal(7).
  104. // The send timeout duration passed before all data was sent. See Socket_Option.Send_Timeout.
  105. // NOTE: No, really. Presumably this means something different for nonblocking sockets...
  106. Timeout = c.int(os.EWOULDBLOCK),
  107. Socket_Not_Bound = c.int(os.EINVAL), // The socket must be bound for this operation, but isn't.
  108. }
  109. TCP_Send_Error :: enum c.int {
  110. None = 0,
  111. Aborted = c.int(os.ECONNABORTED),
  112. Connection_Closed = c.int(os.ECONNRESET),
  113. Not_Connected = c.int(os.ENOTCONN),
  114. Shutdown = c.int(os.ESHUTDOWN),
  115. // The send queue was full.
  116. // This is usually a transient issue.
  117. //
  118. // This also shouldn't normally happen on Linux, as data is dropped if it
  119. // doesn't fit in the send queue.
  120. No_Buffer_Space_Available = c.int(os.ENOBUFS),
  121. Offline = c.int(os.ENETDOWN),
  122. Host_Unreachable = c.int(os.EHOSTUNREACH),
  123. Interrupted = c.int(os.EINTR), // A signal occurred before any data was transmitted. See signal(7).
  124. // NOTE: No, really. Presumably this means something different for nonblocking sockets...
  125. // The send timeout duration passed before all data was sent. See Socket_Option.Send_Timeout.
  126. Timeout = c.int(os.EWOULDBLOCK),
  127. Not_Socket = c.int(os.ENOTSOCK), // The so-called socket is not an open socket.
  128. }
  129. // TODO
  130. UDP_Send_Error :: enum c.int {
  131. None = 0,
  132. Message_Too_Long = c.int(os.EMSGSIZE), // The message is larger than the maximum UDP packet size. No data was sent.
  133. // TODO: not sure what the exact circumstances for this is yet
  134. Network_Unreachable = c.int(os.ENETUNREACH),
  135. No_Outbound_Ports_Available = c.int(os.EAGAIN), // There are no more emphemeral outbound ports available to bind the socket to, in order to send.
  136. // The send timeout duration passed before all data was sent. See Socket_Option.Send_Timeout.
  137. // NOTE: No, really. Presumably this means something different for nonblocking sockets...
  138. Timeout = c.int(os.EWOULDBLOCK),
  139. Not_Socket = c.int(os.ENOTSOCK), // The so-called socket is not an open socket.
  140. Not_Descriptor = c.int(os.EBADF), // The so-called socket is, in fact, not even a valid descriptor.
  141. Bad_Buffer = c.int(os.EFAULT), // The buffer did not point to a valid location in memory.
  142. Interrupted = c.int(os.EINTR), // A signal occurred before any data was transmitted. See signal(7).
  143. // The send queue was full.
  144. // This is usually a transient issue.
  145. //
  146. // This also shouldn't normally happen on Linux, as data is dropped if it
  147. // doesn't fit in the send queue.
  148. No_Buffer_Space_Available = c.int(os.ENOBUFS),
  149. No_Memory_Available = c.int(os.ENOMEM), // No memory was available to properly manage the send queue.
  150. }
  151. Shutdown_Manner :: enum c.int {
  152. Receive = c.int(os.SHUT_RD),
  153. Send = c.int(os.SHUT_WR),
  154. Both = c.int(os.SHUT_RDWR),
  155. }
  156. Shutdown_Error :: enum c.int {
  157. None = 0,
  158. Aborted = c.int(os.ECONNABORTED),
  159. Reset = c.int(os.ECONNRESET),
  160. Offline = c.int(os.ENETDOWN),
  161. Not_Connected = c.int(os.ENOTCONN),
  162. Not_Socket = c.int(os.ENOTSOCK),
  163. Invalid_Manner = c.int(os.EINVAL),
  164. }
  165. Socket_Option_Error :: enum c.int {
  166. None = 0,
  167. Offline = c.int(os.ENETDOWN),
  168. Timeout_When_Keepalive_Set = c.int(os.ENETRESET),
  169. Invalid_Option_For_Socket = c.int(os.ENOPROTOOPT),
  170. Reset_When_Keepalive_Set = c.int(os.ENOTCONN),
  171. Not_Socket = c.int(os.ENOTSOCK),
  172. }
  173. Set_Blocking_Error :: enum c.int {
  174. None = 0,
  175. // TODO: Add errors for `set_blocking`
  176. }