Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libuv #50

Open
magicdawn opened this issue Nov 9, 2015 · 2 comments
Open

libuv #50

magicdawn opened this issue Nov 9, 2015 · 2 comments

Comments

@magicdawn
Copy link
Owner

resources

@magicdawn
Copy link
Owner Author

libuv watchers

/* Handle types. */
typedef struct uv_loop_s uv_loop_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;
typedef struct uv_udp_s uv_udp_t;
typedef struct uv_pipe_s uv_pipe_t;
typedef struct uv_tty_s uv_tty_t;
typedef struct uv_poll_s uv_poll_t;
typedef struct uv_timer_s uv_timer_t;
typedef struct uv_prepare_s uv_prepare_t;
typedef struct uv_check_s uv_check_t;
typedef struct uv_idle_s uv_idle_t;
typedef struct uv_async_s uv_async_t;
typedef struct uv_process_s uv_process_t;
typedef struct uv_fs_event_s uv_fs_event_t;
typedef struct uv_fs_poll_s uv_fs_poll_t;
typedef struct uv_signal_s uv_signal_t;

/* Request types. */
typedef struct uv_req_s uv_req_t;
typedef struct uv_getaddrinfo_s uv_getaddrinfo_t;
typedef struct uv_getnameinfo_s uv_getnameinfo_t;
typedef struct uv_shutdown_s uv_shutdown_t;
typedef struct uv_write_s uv_write_t;
typedef struct uv_connect_s uv_connect_t;
typedef struct uv_udp_send_s uv_udp_send_t;
typedef struct uv_fs_s uv_fs_t;
typedef struct uv_work_s uv_work_t;

/* None of the above. */
typedef struct uv_cpu_info_s uv_cpu_info_t;
typedef struct uv_interface_address_s uv_interface_address_t;
typedef struct uv_dirent_s uv_dirent_t;

Handles represent long-lived objects. Async operations on such handles are identified using requests. A request is short-lived (usually used across only one callback) and usually indicates one I/O operation on a handle. Requests are used to preserve context between the initiation and the callback of individual actions. For example, an UDP socket is represented by a uv_udp_t, while individual writes to the socket use a uv_udp_send_t structure that is passed to the callback after the write is done.

handles代表的是长期存在的objects, 在handles上进行的async操作通常用requests表示. requests代表这短期存在的(通常只跨一个callback) 而且通常表示着在一个handle上进行着IO操作. requests被用来在初始化操作和callback之间保持context上下文信息. 例如, 使用一个 uv_udp_t 实例来代表一个 UDP socket, 然而一个单独的socket 写操作使用一个 uv_udp_send_t实例, 在写操作完成后传递到callback.

@magicdawn
Copy link
Owner Author

loop

// new
// malloc / uv_loop_new / uv_default_loop 都可以
uv_loop_t _loop;
uv_loop_t* loop = &_loop;

// init
uv_loop_init(loop); 

// run
// signature: uv_run(uv_loop_t* , uv_run_mode)
// un_run_mode 应该是enum
// https://github.com/thlorenz/libuv-dox/blob/master/methods.md#uv_run
uv_run(loop, UV_RUN_DEFAULT);

// close
uv_loop_close(loop);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant