Created
April 6, 2016 16:12
-
-
Save saisasidhar/2929924682bdf47b6bb98d973eb4e559 to your computer and use it in GitHub Desktop.
Revisions
-
Sai Sasidhar Maddali created this gist
Apr 6, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ #include<stdio.h> #include<stdlib.h> #include<sys/types.h> #include"include/uv.h" struct my_data{ int fd; char *buf; }priv; void read_callback(uv_poll_t * handle, int status, int events) { uv_loop_t * my_loop = uv_default_loop(); if(!status) { // For only one read uv_poll_stop(handle); printf("Data available for reading\n"); struct my_data *temp = my_loop->data; temp->buf = (char *)malloc(sizeof(char)*10); read(temp->fd, temp->buf, 10); printf("%s\n", temp->buf); } else printf("False positive"); } int main() { uv_loop_t * my_default_loop; uv_poll_t * file_poll; struct my_data *ptr = &priv; file_poll = (uv_poll_t *)malloc(sizeof(uv_poll_t)); my_default_loop = uv_default_loop(); uv_loop_init(my_default_loop); my_default_loop->data = (void *)ptr; ptr->fd=open("pipe", O_RDONLY); uv_poll_init(my_default_loop, file_poll, ptr->fd); uv_poll_start(file_poll, UV_READABLE, read_callback); uv_run(my_default_loop, UV_RUN_DEFAULT); return 0; }