errors_darwin.odin 9.1 KB

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