#include #include #include #include #include #include #include #include #include void sock_read(int fd, short event, void *arg)
; int len;
struct event * ev = (struct event*)arg;
len = recv(fd, buf, sizeof(buf) - 1, 0);
if( len == -1)
return;
} else if(len == 0)
buf[len] = '\0';
printf("read:%s\n", buf);
event_add(ev, null);
}void sock_accept(int fd, short event, void *arg)
printf("accept socket:%d\n", s);
event_set(rev, s, ev_read, sock_read, rev);
event_add(rev, null);
event_add(ev, null);
}int main()
bzero(&addr, sizeof(addr));
addr.sin_family = af_inet;
addr.sin_port = htons(10000);
addr.sin_addr.s_addr = 0;
if(bind(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1)
if(listen(fd, 5) == -1)
event_init();
event_set(&ev, fd, ev_read, sock_accept, &ev);
event_add(&ev, null);
event_dispatch();
return 0;
}
LIBEVENT應用舉例2
include include include include include include include include define port 25341 define backlog 5 define mem size 1024 struct event base base struct ...
追溯法應用舉例1 素數環
uva524 模擬全排列過程即可。注意 由於輸出要求是從1開始,所以排列遞迴的第一層其實只允許填入1,這個操作節省了相當龐大的舉例過程。具體 如下 1 include2 include3 include4 include5 using namespace std 6int isp 50 7 int ...
Parcelable 應用舉例
首先,自定義物件必須實現parcelable,並且建立static final parcelable.creatorcreator物件 實現createfromparcel和newarray方法 自定義物件為 public static class contact implements parcel...