Guest User

Untitled

a guest
Jan 23rd, 2018
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. From f4cd2655fa103edba20ac0f34e612b70e5fbe261 Mon Sep 17 00:00:00 2001
  2. From: Bert Belder <bertbelder@gmail.com>
  3. Date: Wed, 24 Aug 2011 00:24:24 +0200
  4. Subject: [PATCH 1/1] Define uv_object_t, a base class for handles and
  5. requests
  6.  
  7. ---
  8. include/uv-unix.h | 2 ++
  9. include/uv-win.h | 3 +++
  10. include/uv.h | 31 +++++++++++++++++++------------
  11. src/uv-unix.c | 2 +-
  12. src/win/req.c | 2 +-
  13. 5 files changed, 26 insertions(+), 14 deletions(-)
  14.  
  15. diff --git a/include/uv-unix.h b/include/uv-unix.h
  16. index e918e4d..62498a7 100644
  17. --- a/include/uv-unix.h
  18. +++ b/include/uv-unix.h
  19. @@ -39,6 +39,8 @@ typedef struct {
  20. size_t len;
  21. } uv_buf_t;
  22.  
  23. +#define UV_OBJECT_PRIVATE_FIELDS /* empty */
  24. +
  25. #define UV_REQ_BUFSML_SIZE (4)
  26.  
  27. #define UV_REQ_PRIVATE_FIELDS /* empty */
  28. diff --git a/include/uv-win.h b/include/uv-win.h
  29. index a3ad457..a150011 100644
  30. --- a/include/uv-win.h
  31. +++ b/include/uv-win.h
  32. @@ -51,6 +51,9 @@ typedef struct uv_buf_t {
  33. UV_PROCESS_CLOSE, \
  34. UV_UDP_RECV
  35.  
  36. +#define UV_OBJECT_PRIVATE_FIELDS \
  37. + /* empty */
  38. +
  39. #define UV_REQ_PRIVATE_FIELDS \
  40. union { \
  41. /* Used by I/O operations */ \
  42. diff --git a/include/uv.h b/include/uv.h
  43. index 2dd5034..30334a0 100644
  44. --- a/include/uv.h
  45. +++ b/include/uv.h
  46. @@ -42,6 +42,7 @@ typedef intptr_t ssize_t;
  47. #endif
  48.  
  49. typedef struct uv_err_s uv_err_t;
  50. +typedef struct uv_object_s uv_object_t;
  51. typedef struct uv_handle_s uv_handle_t;
  52. typedef struct uv_stream_s uv_stream_t;
  53. typedef struct uv_tcp_s uv_tcp_t;
  54. @@ -173,7 +174,7 @@ typedef enum {
  55. } uv_err_code;
  56.  
  57. typedef enum {
  58. - UV_UNKNOWN_HANDLE = 0,
  59. + UV_UNKNOWN_OBJECT = 0,
  60. UV_TCP,
  61. UV_UDP,
  62. UV_NAMED_PIPE,
  63. @@ -187,11 +188,7 @@ typedef enum {
  64. UV_ARES_TASK,
  65. UV_ARES_EVENT,
  66. UV_GETADDRINFO,
  67. - UV_PROCESS
  68. -} uv_handle_type;
  69. -
  70. -typedef enum {
  71. - UV_UNKNOWN_REQ = 0,
  72. + UV_PROCESS,
  73. UV_CONNECT,
  74. UV_ACCEPT,
  75. UV_READ,
  76. @@ -200,7 +197,7 @@ typedef enum {
  77. UV_WAKEUP,
  78. UV_UDP_SEND,
  79. UV_REQ_TYPE_PRIVATE
  80. -} uv_req_type;
  81. +} uv_object_type;
  82.  
  83.  
  84. struct uv_err_s {
  85. @@ -221,9 +218,20 @@ char* uv_strerror(uv_err_t err);
  86. const char* uv_err_name(uv_err_t err);
  87.  
  88.  
  89. -#define UV_REQ_FIELDS \
  90. +#define UV_OBJECT_FIELDS \
  91. /* read-only */ \
  92. - uv_req_type type; \
  93. + uv_object_type type; \
  94. + /* private */ \
  95. + UV_OBJECT_PRIVATE_FIELDS
  96. +
  97. +/* Abstract base class of all requests and handles. */
  98. +struct uv_object_s {
  99. + UV_OBJECT_FIELDS
  100. +};
  101. +
  102. +
  103. +#define UV_REQ_FIELDS \
  104. + UV_OBJECT_FIELDS \
  105. /* public */ \
  106. void* data; \
  107. /* private */ \
  108. @@ -258,15 +266,14 @@ struct uv_shutdown_s {
  109.  
  110.  
  111. #define UV_HANDLE_FIELDS \
  112. - /* read-only */ \
  113. - uv_handle_type type; \
  114. + UV_OBJECT_FIELDS \
  115. /* public */ \
  116. uv_close_cb close_cb; \
  117. void* data; \
  118. /* private */ \
  119. UV_HANDLE_PRIVATE_FIELDS
  120.  
  121. -/* The abstract base class of all handles. */
  122. +/* The abstract base class of all handles. */
  123. struct uv_handle_s {
  124. UV_HANDLE_FIELDS
  125. };
  126. diff --git a/src/uv-unix.c b/src/uv-unix.c
  127. index 1cb418c..bb2d74e 100644
  128. --- a/src/uv-unix.c
  129. +++ b/src/uv-unix.c
  130. @@ -1824,7 +1824,7 @@ int uv_read_stop(uv_stream_t* stream) {
  131.  
  132. void uv__req_init(uv_req_t* req) {
  133. uv_counters()->req_init++;
  134. - req->type = UV_UNKNOWN_REQ;
  135. + req->type = UV_UNKNOWN_OBJECT;
  136. req->data = NULL;
  137. }
  138.  
  139. diff --git a/src/win/req.c b/src/win/req.c
  140. index 12c5346..62cbed9 100644
  141. --- a/src/win/req.c
  142. +++ b/src/win/req.c
  143. @@ -28,7 +28,7 @@
  144.  
  145. void uv_req_init(uv_req_t* req) {
  146. uv_counters()->req_init++;
  147. - req->type = UV_UNKNOWN_REQ;
  148. + req->type = UV_UNKNOWN_OBJECT;
  149. SET_REQ_SUCCESS(req);
  150. }
  151.  
  152. --
  153. 1.7.6.msysgit.0
Add Comment
Please, Sign In to add comment