kindy / libev Goto Github PK
View Code? Open in Web Editor NEWlibev sync from http://cvs.schmorp.de/libev/
libev sync from http://cvs.schmorp.de/libev/
I want to build libev on windows,but got some trouble when I try to do this.can this project be done or do you have any good Suggestions? thanks.
i have write a code:
#include <stdio.h>
#include <unistd.h>
#include<arpa/inet.h>
#include<netinet/in.h>
#include<sys/types.h>
#include<sys/socket.h>
ev_io stdin_watcher;
ev_timer timeout_watcher;
static void timeout_cb (EV_P_ ev_timer *w, int revents) ;
static void udp_cb (EV_P_ ev_io *w, int revents)
{
char buf[101] = {0};
read(w->fd,buf,100);
printf("read data---->%s\n",buf);
ev_io_stop (EV_A_ w);
ev_break (EV_A_ EVBREAK_ALL);
}
static int flag = 0;
struct ev_loop *loop;
static void timeout_cb (EV_P_ ev_timer *w, int revents)
{
if(flag == 0){
sleep(30);
flag = 1;
}
ev_timer_stop (loop, w);
ev_timer_set (w, 1, 0.0);
ev_timer_start (loop, w);
printf("2-----ev_now=%d,ev_time=%d\n",ev_now(EV_A),ev_time());
printf("end\n");
}
int main (void)
{
loop = EV_DEFAULT;
int sock = socket(AF_INET,SOCK_DGRAM,0);
if(sock<0){
perror("socket");
exit(1);
}
struct sockaddr_in local;
local.sin_family = AF_INET;
local.sin_port = htons(7777);
local.sin_addr.s_addr = inet_addr("0.0.0.0");
if(bind(sock,(struct sockaddr*)&local,sizeof(local))<0){
perror("bind");
exit(0);
}
ev_io_init (&stdin_watcher, udp_cb,sock, EV_READ);
ev_io_start (loop, &stdin_watcher);
ev_timer_init (&timeout_watcher, timeout_cb, 1,0.0);
ev_timer_start(loop, &timeout_watcher);
ev_run (loop, 0);
return 0;
}
compile : gcc -o test 1.c -lev
test it and the result is : before the timeout happy and udp sock recived data in this period. this timeout_cb always trigger twice and quit. i cannot decide this is bug? Why it triggers twice instead of once?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.