Permalink
Browse files

Define uv_object_t, a base class for handles and requests

  • Loading branch information...
1 parent 48f827f commit b087c21e52f462521da639d406d1ffe94359577c @piscisaureus piscisaureus committed Aug 23, 2011
Showing with 26 additions and 14 deletions.
  1. +2 −0 include/uv-unix.h
  2. +3 −0 include/uv-win.h
  3. +19 −12 include/uv.h
  4. +1 −1 src/uv-unix.c
  5. +1 −1 src/win/req.c
View
@@ -39,6 +39,8 @@ typedef struct {
size_t len;
} uv_buf_t;
+#define UV_OBJECT_PRIVATE_FIELDS /* empty */
+
#define UV_REQ_BUFSML_SIZE (4)
#define UV_REQ_PRIVATE_FIELDS /* empty */
View
@@ -51,6 +51,9 @@ typedef struct uv_buf_t {
UV_PROCESS_CLOSE, \
UV_UDP_RECV
+#define UV_OBJECT_PRIVATE_FIELDS \
+ /* empty */
+
#define UV_REQ_PRIVATE_FIELDS \
union { \
/* Used by I/O operations */ \
View
@@ -42,6 +42,7 @@ typedef intptr_t ssize_t;
#endif
typedef struct uv_err_s uv_err_t;
+typedef struct uv_object_s uv_object_t;
typedef struct uv_handle_s uv_handle_t;
typedef struct uv_stream_s uv_stream_t;
typedef struct uv_tcp_s uv_tcp_t;
@@ -173,7 +174,7 @@ typedef enum {
} uv_err_code;
typedef enum {
- UV_UNKNOWN_HANDLE = 0,
+ UV_UNKNOWN_OBJECT = 0,
UV_TCP,
UV_UDP,
UV_NAMED_PIPE,
@@ -187,11 +188,7 @@ typedef enum {
UV_ARES_TASK,
UV_ARES_EVENT,
UV_GETADDRINFO,
- UV_PROCESS
-} uv_handle_type;
-
-typedef enum {
- UV_UNKNOWN_REQ = 0,
+ UV_PROCESS,
UV_CONNECT,
UV_ACCEPT,
UV_READ,
@@ -200,7 +197,7 @@ typedef enum {
UV_WAKEUP,
UV_UDP_SEND,
UV_REQ_TYPE_PRIVATE
-} uv_req_type;
+} uv_object_type;
struct uv_err_s {
@@ -221,9 +218,20 @@ char* uv_strerror(uv_err_t err);
const char* uv_err_name(uv_err_t err);
-#define UV_REQ_FIELDS \
+#define UV_OBJECT_FIELDS \
/* read-only */ \
- uv_req_type type; \
+ uv_object_type type; \
+ /* private */ \
+ UV_OBJECT_PRIVATE_FIELDS
+
+/* Abstract base class of all requests and handles. */
+struct uv_object_s {
+ UV_OBJECT_FIELDS
+};
+
+
+#define UV_REQ_FIELDS \
+ UV_OBJECT_FIELDS \
/* public */ \
void* data; \
/* private */ \
@@ -258,15 +266,14 @@ struct uv_shutdown_s {
#define UV_HANDLE_FIELDS \
- /* read-only */ \
- uv_handle_type type; \
+ UV_OBJECT_FIELDS \
/* public */ \
uv_close_cb close_cb; \
void* data; \
/* private */ \
UV_HANDLE_PRIVATE_FIELDS
-/* The abstract base class of all handles. */
+/* The abstract base class of all handles. */
struct uv_handle_s {
UV_HANDLE_FIELDS
};
View
@@ -1837,7 +1837,7 @@ int uv_read_stop(uv_stream_t* stream) {
void uv__req_init(uv_req_t* req) {
uv_counters()->req_init++;
- req->type = UV_UNKNOWN_REQ;
+ req->type = UV_UNKNOWN_OBJECT;
req->data = NULL;
}
View
@@ -28,7 +28,7 @@
void uv_req_init(uv_req_t* req) {
uv_counters()->req_init++;
- req->type = UV_UNKNOWN_REQ;
+ req->type = UV_UNKNOWN_OBJECT;
SET_REQ_SUCCESS(req);
}

0 comments on commit b087c21

Please sign in to comment.