PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/platform/FNET/fnet_stack/stack/fnet_error.h

https://gitlab.com/fuggles/ucos
C Header | 251 lines | 40 code | 9 blank | 202 comment | 0 complexity | 7851b48de938736910e9b6ad887228ff MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0
  1. /**************************************************************************
  2. *
  3. * Copyright 2011-2015 by Andrey Butok. FNET Community.
  4. * Copyright 2008-2010 by Andrey Butok. Freescale Semiconductor, Inc.
  5. *
  6. ***************************************************************************
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License Version 3
  9. * or later (the "LGPL").
  10. *
  11. * As a special exception, the copyright holders of the FNET project give you
  12. * permission to link the FNET sources with independent modules to produce an
  13. * executable, regardless of the license terms of these independent modules,
  14. * and to copy and distribute the resulting executable under terms of your
  15. * choice, provided that you also meet, for each linked independent module,
  16. * the terms and conditions of the license of that module.
  17. * An independent module is a module which is not derived from or based
  18. * on this library.
  19. * If you modify the FNET sources, you may extend this exception
  20. * to your version of the FNET sources, but you are not obligated
  21. * to do so. If you do not wish to do so, delete this
  22. * exception statement from your version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  27. *
  28. * You should have received a copy of the GNU General Public License
  29. * and the GNU Lesser General Public License along with this program.
  30. * If not, see <http://www.gnu.org/licenses/>.
  31. *
  32. **********************************************************************/ /*!
  33. *
  34. * @file fnet_error.h
  35. *
  36. * @author Andrey Butok
  37. *
  38. * @brief Socket error API definitions.
  39. *
  40. ***************************************************************************/
  41. #ifndef _FNET_ERROR_H_
  42. #define _FNET_ERROR_H_
  43. /*! @addtogroup fnet_error
  44. * When a socket call indicates a failure, it is possible to call the @ref
  45. * fnet_error_get() function to determine the error value.@n
  46. * Another way to determine the error value for a socket is to examine its
  47. * @ref SO_ERROR option.@n
  48. * Possible values for socket errors are defined by the @ref fnet_error_t.
  49. */
  50. /*! @{ */
  51. /**************************************************************************/ /*!
  52. * @brief General return codes, used by most of API functions.
  53. ******************************************************************************/
  54. typedef enum
  55. {
  56. FNET_OK = (int)(0), /**< No error.
  57. */
  58. FNET_ERR = (int)(-1) /**< There is error.
  59. */
  60. } fnet_return_t;
  61. /**************************************************************************/ /*!
  62. * @brief Possible socket error codes, returned by the @ref fnet_error_get(),
  63. * or used by the @ref SO_ERROR option.
  64. ******************************************************************************/
  65. typedef enum
  66. {
  67. FNET_ERR_OK = (int)(0), /**< @brief There is no error.
  68. */
  69. FNET_ERR_BAD_DESC = (int)(1), /**< @brief Bad socket descriptor.@n
  70. * An operation was attempted on a socket descriptor
  71. * that does not refer to a valid socket.
  72. */
  73. FNET_ERR_NO_DESC = (int)(2), /**< @brief No more socket descriptors are available.@n
  74. * An application has opened too many sockets.
  75. * The maximum number of available socket descriptors
  76. * is defined by the @ref FNET_CFG_SOCKET_MAX.
  77. */
  78. FNET_ERR_NOMEM = (int)(3), /**< @brief Cannot allocate the memory.@n
  79. * The error is indicating a lack of required
  80. * memory resources.
  81. */
  82. FNET_ERR_AGAIN = (int)(4), /**< @brief Try again, a retry at some time later may be successful.@n
  83. * This error is returned from operations on sockets
  84. * that cannot be completed immediately. It is a non-fatal error
  85. * and the operation should be retried later.@n
  86. * For example, it is normal for the @ref FNET_ERR_AGAIN to be reported as
  87. * the result from the @ref connect() calling on a @ref SOCK_STREAM socket,
  88. * since some time must elapse for the connection to be established.
  89. */
  90. FNET_ERR_BOUNDREQ = (int)(5), /**< @brief The socket has not been bound with @ref bind().@n
  91. * A socket must be bound to an address before calling
  92. * @ref getsockname(), @ref recvfrom(), @ref recv(), and @ref listen().
  93. */
  94. FNET_ERR_INVAL = (int)(6), /**< @brief Invalid argument.@n
  95. * An invalid argument was supplied.
  96. */
  97. FNET_ERR_DESTADDRREQ = (int)(7), /**< @brief Destination address required.@n
  98. * A required address was omitted from an operation on a socket.
  99. * For example, this error will be returned, if the @ref sendto()
  100. * or @ref connect() is called with the remote address of @ref INADDR_ANY.
  101. */
  102. FNET_ERR_MSGSIZE = (int)(8), /**< @brief Message too long.@n
  103. * A message sent on a datagram socket was larger than the internal
  104. * message buffer, or some other network limit, or the buffer,
  105. * which is used to receive a datagram was smaller than the datagram itself.
  106. */
  107. FNET_ERR_NOPROTOOPT = (int)(9), /**< @brief Bad protocol option. @n
  108. * An unknown, invalid, or unsupported option or level was specified
  109. * in the @ref getsockopt(), or @ref setsockopt() call, or a socket
  110. * received Parameter Problem ICMP Error Message.
  111. */
  112. FNET_ERR_PROTONOSUPPORT = (int)(10), /**< @brief Protocol not supported.@n
  113. * This error occurs if an application attempts to call @ref socket()
  114. * and the requested protocol has not been configured into the system,
  115. * or no implementation for it exists.
  116. */
  117. FNET_ERR_OPNOTSUPP = (int)(11), /**< @brief Operation not supported.@n
  118. * The attempted operation is not supported for the type
  119. * of socket referenced. This occurs, when socket cannot support
  120. * the requested operation, for example trying to accept
  121. * a connection on a datagram socket.
  122. */
  123. FNET_ERR_AFNOSUPPORT = (int)(12), /**< @brief Address family not supported by the protocol family.@n
  124. * The stack supports only the @ref AF_INET family.
  125. * This error will be returned, if an address of a wrong family
  126. * is used for a socket in @ref socket(), @ref sendto(), @ref connect(),
  127. * @ref bind(), @ref getsockname(), and in @ref getpeername().
  128. */
  129. FNET_ERR_ADDRINUSE = (int)(14), /**< @brief Address already in use.@n
  130. * This error occurs, if an application attempts to @ref bind() or
  131. * @ref connect() a socket to an IP address and port that has
  132. * already been used for an existing socket, or a socket that
  133. * wasn't closed properly, or one that is still in the process of closing.
  134. * Only one usage of each socket address is permitted.
  135. */
  136. FNET_ERR_ADDRNOTAVAIL = (int)(15), /**< @brief Cannot assign the requested address.@n
  137. * The requested address is not valid in its context.
  138. * It normally results from an attempt to @ref bind() to an address
  139. * that is not valid for the local machine. This may also result
  140. * from @ref connect(), when the remote address or port is not
  141. * valid for a remote machine (for example address or port is 0).
  142. */
  143. FNET_ERR_NETUNREACH = (int)(16), /**< @brief The network is unreachable.@n
  144. * This error occurs, if socket cannot function at this time,
  145. * because the underlying network interface it uses to provide
  146. * the network services is unavailable.
  147. */
  148. FNET_ERR_CONNABORTED = (int)(17), /**< @brief Software caused the connection abort.@n
  149. * An established connection was aborted due to a data
  150. * transmission or connection timeouts.
  151. */
  152. FNET_ERR_CONNRESET = (int)(18), /**< @brief Connection reset by peer. @n
  153. * A connection was forcibly closed by the remote host.
  154. * This normally results, if the peer application on the remote
  155. * host has suddenly stopped, the host has rebooted, or the
  156. * remote host used a "hard close" on the remote socket.@n
  157. * For the UDP sockets, the remote host was unable to deliver
  158. * a previously sent UDP datagram and responded with
  159. * a "Port Unreachable" ICMP packet. The application
  160. * should close the socket as it is no longer usable.
  161. */
  162. FNET_ERR_ISCONN = (int)(19), /**< @brief Socket is already connected.@n
  163. * A @ref connect() or @ref listen() request was made on
  164. * an already connected socket.
  165. */
  166. FNET_ERR_NOTCONN = (int)(20), /**< @brief Socket is not connected.@n
  167. * A request to send or receive data was not allowed
  168. * because the socket is not connected.
  169. */
  170. FNET_ERR_SHUTDOWN = (int)(21), /**< @brief The socket has been shut down.@n
  171. * A request to send or receive data was not allowed because
  172. * the socket had already been shut down in that direction
  173. * with a previous @ref shutdown() call.
  174. */
  175. FNET_ERR_INPROGRESS = (int)(22), /**< @brief The action is in progress.@n
  176. * An operation was attempted on a
  177. * socket that already had an operation in
  178. * progress - in other words calling @ref connect() a second time on a
  179. * socket that is already connecting.
  180. */
  181. FNET_ERR_TIMEDOUT = (int)(23), /**< @brief The connection has timed out.@n
  182. * A connection attempt failed because the connected party did
  183. * not properly respond after a period of time.
  184. */
  185. FNET_ERR_HOSTUNREACH = (int)(24), /**< @brief No route to a host.@n
  186. * A socket operation was attempted to an unreachable host.
  187. */
  188. FNET_ERR_SYSNOTREADY = (int)(25), /**< @brief Network subsystem is unavailable.@n
  189. * The stack is not initialized.
  190. */
  191. FNET_ERR_CONNCLOSED = (int)(26), /**< @brief Connection closed by peer. @n
  192. * The final (FIN) segment arrived and there is no data
  193. * in the socket receive buffer.
  194. * The remote host closed connection and will
  195. * not send any data in the current connection. @n
  196. * The application should close the socket as it
  197. * is no longer usable.
  198. */
  199. FNET_ERR_IPDISABLED = (int)(27) /**< @brief IP operation is disabled. @n
  200. * It happens when Duplicate Address Detection
  201. * fails for interface link-local address,
  202. * formed from an interface identifier based on the hardware address.
  203. */
  204. } fnet_error_t;
  205. /***************************************************************************/ /*!
  206. *
  207. * @brief Returns the last error that occurred.
  208. *
  209. * @return This function returns the error code for the last socket
  210. * operation that failed.@n
  211. * The error codes are defined by the @ref fnet_error_t.
  212. *
  213. * @see fnet_error_set()
  214. *
  215. ******************************************************************************
  216. *
  217. * When a particular socket function indicates that an error has occurred,
  218. * this function should be called to retrieve the appropriate error code.@n
  219. * A successful socket function call, or a call to @ref fnet_error_get(),
  220. * does not reset the error code. To reset the error code, use the fnet_error_set()
  221. * function call with error set to zero (@ref FNET_ERR_OK).
  222. *
  223. ******************************************************************************/
  224. int fnet_error_get( void );
  225. /***************************************************************************/ /*!
  226. *
  227. * @brief Sets the error code.
  228. *
  229. * @param error Error code.
  230. *
  231. * @see fnet_error_get()
  232. *
  233. ******************************************************************************
  234. *
  235. * This function is used to set or reset the error code. @n
  236. * Note that any subsequent socket routine called by the application will
  237. * override the error code, as set by this routine.
  238. *
  239. ******************************************************************************/
  240. void fnet_error_set( int error );
  241. /*! @} */
  242. #endif