util.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef __UTIL_H__
  2. #define __UTIL_H__
  3. #if defined(unix) || defined(__APPLE__)
  4. #include <errno.h>
  5. #include <sys/socket.h>
  6. #include <netinet/in.h>
  7. #include <arpa/inet.h>
  8. #define SOCKETTYPE long
  9. #define SOCKETFAIL(a) ((a) < 0)
  10. #define INVSOCK -1
  11. #define INVINETADDR -1
  12. #define CLOSESOCKET close
  13. #define SOCKERRMSG strerror(errno)
  14. #elif defined WIN32
  15. #include <ws2tcpip.h>
  16. #include <winsock2.h>
  17. #define SOCKETTYPE SOCKET
  18. #define SOCKETFAIL(a) ((int)(a) == SOCKET_ERROR)
  19. #define INVSOCK INVALID_SOCKET
  20. #define INVINETADDR INADDR_NONE
  21. #define CLOSESOCKET closesocket
  22. extern char *WSAErrorMsg(void);
  23. #define SOCKERRMSG WSAErrorMsg()
  24. #ifndef SHUT_RDWR
  25. #define SHUT_RDWR SD_BOTH
  26. #endif
  27. #ifndef in_addr_t
  28. #define in_addr_t uint32_t
  29. #endif
  30. #endif
  31. #if JANSSON_MAJOR_VERSION >= 2
  32. #define JSON_LOADS(str, err_ptr) json_loads((str), 0, (err_ptr))
  33. #else
  34. #define JSON_LOADS(str, err_ptr) json_loads((str), (err_ptr))
  35. #endif
  36. struct pool;
  37. bool stratum_send(struct pool *pool, char *s, ssize_t len);
  38. bool sock_full(struct pool *pool);
  39. char *recv_line(struct pool *pool);
  40. bool parse_method(struct pool *pool, char *s);
  41. bool extract_sockaddr(struct pool *pool, char *url);
  42. bool auth_stratum(struct pool *pool);
  43. bool initiate_stratum(struct pool *pool);
  44. #endif /* __UTIL_H__ */