linux 2.6 kernel epoll
http://hi.baidu.com/j_fo/blog/item/a43fa60fa6e2f4eaab6457d5.html
Linux2.6ÄÚºËepoll½éÉÜ
2008-11-05 16:35
http://blog.csdn.net/rstevens/archive/2007/10/30/1858067.aspx
http://hi.baidu.com/jmlover/blog/item/24c28b131e6b48d7f7039ee6.html
http://hi.baidu.com/jmlover/blog/item/e64df724f12926348744f91b.html
Ãû´Ê½âÊÍ£ºman epollÖ®ºó£¬µÃµ½ÈçϽá¹û£º
NAME
epoll - I/O event notification facility
SYNOPSIS
#include <sys/epoll.h>
DEscrīptION
epoll is a variant of poll(2) that can be used either as Edge or Level
Triggered interface and scales well to large numbers of watched fds.
Three system calls are provided to set up and control an epoll set:
epoll_create(2), epoll_ctl(2), epoll_wait(2).
An epoll set is connected to a file descrīptor created by
epoll_create(2). Interest for certain file descrīptors is then
registered via
epoll_ctl(2). Finally, the actual wait is started by epoll_wait(2).
Æäʵ£¬Ò»ÇеĽâÊͶ¼ÊǶàÓàµÄ£¬°´ÕÕÎÒÄ¿Ç°µÄÁ˽⣬EPOLLÄ£ÐÍËƺõÖ»ÓÐÒ»ÖÖ¸ñʽ£¬ËùÒÔ´ó¼ÒÖ»Òª²Î¿¼ÎÒÏÂÃæµÄ´úÂ룬¾ÍÄܹ»¶ÔEPOLLÓÐËùÁ˽âÁË£¬´úÂëµÄ½âÊͶ¼ÒѾÔÚ×¢ÊÍÖУº
while (TRUE)
{
int nfds = epoll_wait (m_epoll_fd, m_events, MAX_EVENTS, EPOLL_TIME_OUT);//µÈ´ýEPOLLʼþµÄ·¢Éú£¬Ï൱ÓÚ¼àÌý£¬ÖÁÓÚÏà¹ØµÄ¶Ë¿Ú£¬ÐèÒªÔÚ³õʼ»¯EPOLLµÄʱºò°ó¶¨¡£
if (nfds <= 0)
continue;
m_bOnTimeChecking = FALSE;
G_CurTime = time(NULL);
for (int i=0; i<nfds; i++)
{
try
{
if (m_events[i].data.fd == m_listen_http_fd)//Èç¹ûмà²âµ½Ò»¸öHTTPÓû§Á¬½Óµ½°ó¶¨µÄHTTP¶Ë¿Ú£¬½¨Á¢ÐµÄÁ¬½Ó¡£ÓÉÓÚÎÒÃÇвÉÓÃÁËSOCKETÁ¬½Ó£¬ËùÒÔ»ù±¾Ã»Óá£
{
OnAcceptHttpEpoll ();
}
else if (m_events[i].data.fd == m_listen_sock_fd)//Èç¹ûмà²âµ½Ò»¸öSOCKETÓû§Á¬½Óµ½Á˰󶨵ÄSOCKET¶Ë¿Ú£¬½¨Á¢ÐµÄÁ¬½Ó¡£
{
OnAcceptSockEpoll ();
}
else if (m_events[i].events & EPOLLIN)//Èç¹ûÊÇÒѾÁ¬½ÓµÄÓû§£¬²¢ÇÒÊÕµ½Êý¾Ý£¬ÄÇô½øÐжÁÈë¡£
{
OnReadEpoll (i);
}
OnWriteEpoll (i);//²é¿´µ±Ç°µÄ»î¶¯Á¬½ÓÊÇ·ñÓÐÐèҪд³öµÄÊý¾Ý¡£
}
catch (int)
{
PRINTF ("CATCH²¶»ñ´íÎó\n");
Ïà¹ØÎĵµ£º
Ò»ÄêÒ»¶ÈµÄLinux¿ª·¢Õß´ó»áÉÏÖÜÔھɽðɽ¾ÙÐУ¬»áÉÏLinux»ù½ð»áÖ´ÐÐÀíÊÂJim Zemlin±íʾ£¬µÃÒæÓÚÔƼÆËãÒÔ¼°ÆäËü¿Æ¼¼³±Á÷µÄ³öÏÖ£¬LinuxµÄÊг¡µØλʮ·ÖÎȹ̣¬È»¶øһЩÖ÷ÒªµÄά»¤ÈËÔ±ÒѾÈÕ½¥²ÔÀÏ£¬ºó¼ÌÕßÈ´»¹Ã»ÓгÉÊì¡£
sysfsÄÚºË×Óϵͳά»¤ÕßGrey Kroah-HartmanÖ¸³ö£º“ÉϲãµÄÈËÔ±ÈÔȻà ......
Ŀ¼ºÍÎļþ²Ù×÷
²é¿´µ±Ç°Ä¿Â¼Ïà¶ÔÓÚ¸ùĿ¼µÄλÖÃ
¡¡
¡¡¡¡pwd
²é¿´µ±Ç°Ä¿Â¼ÄÚÈÝ
¡¡¡¡ls
ÒÔ³¤¸ñʽ²é¿´µ±Ç°Ä¿Â¼ÄÚÈÝ¡£¶ÔӦÿ¸öÎļþµÄÌõÄ¿½«°üÀ¨Á¬½ÓÊýÄ¿¡¢ËùÓÐÕß¡¢´óС¡¢×îºóÐÞ¸Äʱ¼ä¡¢È¨ÏÞµÈÄÚÈÝ
¡¡¡¡ls -l
¸Ä±äµ±Ç°Ä¿Â¼¡£Ä¿µÄĿ¼Ãû¿ÉÓÃÏà¶Ô·¾¶±íʾ£¬Ò²¿ÉÒÔÓþø¶Ô·¾¶±íʾ¡£
cd [Ä¿µÄĿ¼Ãû]
תÒƵ½ÉÏÒ»¼¶Ä¿Â¼
c ......
linuxÆô¶¯Á÷³Ì£º
ϵͳԤ´¦Àí³ÌÐò->GRUB (´Ë½×¶Î¿ÉÒÔÀí½âΪbootloader½×¶Î)
->kernel (´Ë½×¶ÎΪkernel)
->initrd->initÆô¶¯->inittab->rc.sysinit->functions(PATH)->modules->rcX.d(¶ÁÅäÖÃÎļþ)
1.->×Ö·ûģʽ->tty->bash
2.->ͼÐÎģʽ->½øÈëX Window-> ......
errno±äÁ¿(Ðèinclude errno.h)»á±»¸³Ò»¸öÕûÊýÖµ,²»Í¬µÄÖµ±íʾ²»Í¬µÄº¬Òå,
¿ÉÒÔͨ¹ý²é¿´¸ÃÖµÍƲâ³ö´íµÄÔÒò¡£µ«ÊÇerrnoÊÇÒ»¸öÊý×Ö£¬´ú±íµÄ¾ßÌ庬Òå
»¹Òªµ½errno.hÖÐÈ¥ÔĶÁºê¶¨Òå¡£ÓÐÏÂÃ漸ÖÖ·½·¨¿ÉÒÔ·½±ãµÄµÃµ½´íÎóÐÅÏ¢
(Ò»)
#include <stdio.h>
void perror(const char *s)
perror()ÓÃÀ´½«ÉÏÒ»¸öº¯Êý·¢Éú´íÎóµÄ ......