libevent ã¯ãããªã«ä¾¿å©
ä¼ç¤¾ã®åä¿¡ã¡ã¼ã«ãµã¼ã㯠IMAP4 㨠POP3ã両æ¹ç¨æã¯ããã¦ããã¾ããã
SMTP ã®èªè¨¼ã«ã¯æªã POP Before SMTP ã使ããã¦ãã¾ãã
ããã«ã¯ã¡ãã£ã¨å¤ãã® PDA ãªã©ã§ã¯ SMTP èªè¨¼ã使ããªãã¨ããçç±ãããã¾ããã
å®éã¯ããµã¼ãé¡ããã¹ã¦èªä½ã®ã¢ããªã±ã¼ã·ã§ã³ã²ã¼ãã¦ã§ã¤ãéãã¦å¤é¨ã«å
¬éããã¦ãã¦ãSMTP ã®ã¢ã¸ã¥ã¼ã«ãèªè¨¼ã«å¯¾å¿ãã¦ããªããã¨ãåå ã§ãã»ã»ã»
ã§ãããã¯ã IMAP 4 ã使ãããã¨ãããã¨ã§ã
IMAP Before SMTP ã«å¯¾å¿ããã²ã¼ãã¦ã§ã¤ãã ãã¶ã¾ãã«ä½ã£ãã®ã§ããã
ã©ããåããä¸å®å®ã§ç¤¾å
ããé¿é£ã®å£°ãå¤ã
èããã¦ãã¦ãã¾ããã
社é·ãªããã¡ã¼ã«ãæ¸ãã¨ã㯠telnet 㧠pop3 ãµã¼ãã¨ä¼è©±ãã¦èªè¨¼ãã¦ãããããã§ã»ã»ã»
ããã§ä»¥å itojun ããã«æãã¦ããã£ã libevent ã使ã£ã¦å
¨é¢çã«æ¸ãç´ãã¦ã¿ã¾ããã
ãããããããã³ã£ãããããããç°¡åã« I/O ãå¤éåã§ãã¦ã¨ã¦ã便å©ï¼
ã©ããããç°¡åãã¯ä¸è¨ã®ãµã³ãã«ãã¿ã¦ããã ããã°ãããã¨ãããã¾ãã
ããããcc sample.c -levent -o sample ã¨ã§ããã¦ã³ã³ãã¤ã«ãã¦ãå®è¡ãã¾ãã
ãããã㨠2000çªãã¼ãã§å¾
ã¡åãã¦ãåãåã£ãæååã表示ããããã°ã©ã ã®ã§ããããã§ãã
ï¼ãã¡ããè¡èªã¿è¾¼ã¿ã¨ãåä¿¡ãããã¡ã®ä¸ã«ä½ãããã¨ãä½ã«ãèãã¦ããªãã®ã§ãã§ããããªè¡¨ç¤ºã«ãªãããããã¾ããããæ¬è³ªã§ã¯ãªãã®ã§è§¦ãã¦ãã¾ãã :-p
/*
* sample.c
*/
#include
#include
#include
#includestatic void
read_handler(int fd, short event, void *arg)
{
char buf[256];
struct event *ev=(struct event*)arg;if(event&EV_READ){
if(read(fd, buf, sizeof(buf))<=0){
event_del(ev);
free(ev);
close(fd);
}
else{
printf("read=%s\n", buf);
}
}
}static void
accept_handler(int fd, short event, void *arg)
{
struct sockaddr_in addr;
struct event *new_ev;
int new_fd;
socklen_t addrlen=sizeof(addr);if(event&EV_READ){
new_fd=accept(fd,(struct sockaddr*)&addr,&addrlen);
new_ev=malloc(sizeof(struct event));
event_set(new_ev,new_fd,EV_READ|EV_PERSIST,read_handler,new_ev);
event_add(new_ev,NULL);
}
}int
main(int argc, char *argv[])
{
struct event ev;
struct addrinfo hints, *res;
int fd;memset(&hints,0,sizeof(hints));
hints.ai_socktype=SOCK_STREAM;
hints.ai_flags=AI_PASSIVE;
getaddrinfo(NULL,"2000",&hints,&res);
fd=socket(res->ai_family,res->ai_socktype,res->ai_protocol);
bind(fd,res->ai_addr,res->ai_addrlen);
listen(fd,SOMAXCONN);
freeaddrinfo(res);event_init();
event_set(&ev,fd,EV_READ|EV_PERSIST,accept_handler,&ev);
event_add(&ev,NULL);event_dispatch();
}