Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Define uv_object_t, a base class for handles and requests
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Aug 26, 2011
1 parent 48f827f commit b087c21
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
2 changes: 2 additions & 0 deletions include/uv-unix.h
Expand Up @@ -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 */
Expand Down
3 changes: 3 additions & 0 deletions include/uv-win.h
Expand Up @@ -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 */ \
Expand Down
31 changes: 19 additions & 12 deletions include/uv.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -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 */ \
Expand Down Expand Up @@ -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
};
Expand Down
2 changes: 1 addition & 1 deletion src/uv-unix.c
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/win/req.c
Expand Up @@ -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);
}

Expand Down

0 comments on commit b087c21

Please sign in to comment.