util.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 thr_info;
  37. struct pool;
  38. enum dev_reason;
  39. struct cgpu_info;
  40. int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg);
  41. void thr_info_freeze(struct thr_info *thr);
  42. void thr_info_cancel(struct thr_info *thr);
  43. void nmsleep(unsigned int msecs);
  44. void cgtime(struct timeval *tv);
  45. void subtime(struct timeval *a, struct timeval *b);
  46. void addtime(struct timeval *a, struct timeval *b);
  47. bool time_more(struct timeval *a, struct timeval *b);
  48. bool time_less(struct timeval *a, struct timeval *b);
  49. void copy_time(struct timeval *dest, const struct timeval *src);
  50. double us_tdiff(struct timeval *end, struct timeval *start);
  51. double tdiff(struct timeval *end, struct timeval *start);
  52. bool stratum_send(struct pool *pool, char *s, ssize_t len);
  53. bool sock_full(struct pool *pool);
  54. char *recv_line(struct pool *pool);
  55. bool parse_method(struct pool *pool, char *s);
  56. bool extract_sockaddr(struct pool *pool, char *url);
  57. bool auth_stratum(struct pool *pool);
  58. bool initiate_stratum(struct pool *pool);
  59. bool restart_stratum(struct pool *pool);
  60. void suspend_stratum(struct pool *pool);
  61. void dev_error(struct cgpu_info *dev, enum dev_reason reason);
  62. void *realloc_strcat(char *ptr, char *s);
  63. void RenameThread(const char* name);
  64. /* Align a size_t to 4 byte boundaries for fussy arches */
  65. static inline void align_len(size_t *len)
  66. {
  67. if (*len % 4)
  68. *len += 4 - (*len % 4);
  69. }
  70. #endif /* __UTIL_H__ */