﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-编写生产美金的代码...-最新评论</title><link>http://www.cppblog.com/go-benny/CommentsRSS.aspx</link><description>追求的境界</description><language>zh-cn</language><pubDate>Wed, 23 Apr 2008 06:05:31 GMT</pubDate><lastBuildDate>Wed, 23 Apr 2008 06:05:31 GMT</lastBuildDate><generator>cnblogs</generator><item><title>re: emacs使用简单说明</title><link>http://www.cppblog.com/go-benny/archive/2008/04/23/32850.html#47871</link><dc:creator>benny</dc:creator><author>benny</author><pubDate>Wed, 23 Apr 2008 02:02:00 GMT</pubDate><guid>http://www.cppblog.com/go-benny/archive/2008/04/23/32850.html#47871</guid><description><![CDATA[使用cscope/contrib/xcscope/cscope-indexer产生cscope.files和cscope.out文件。<br><br>M-x e         'shell交互模式<br><br>;;.emacs<br>(add-to-list  'load-path<br>              &quot;/usr/share/emacs/site-lisp&quot;)<br>(load-file    &quot;/app/cedet/cedet-1.0pre4/common/cedet.el&quot;)<br>(add-to-list  'load-path<br>              &quot;/app/ecb/ecb-2.32&quot;)<br>(require 'ecb)<br>(load-file    &quot;/app/cscope/contrib/xcscope/xcscope.el&quot;)<br><br>(defun benny-edit-mode-setup()<br>  (setq c-basic-offset 8)<br>  (setq default-tab-width 8)<br>  (setq intent-tabs-mode t))<br><br>(add-hook 'c-mode-hook   'benny-edit-mode-setup)<br>(add-hook 'c++-mode-hook 'benny-edit-mode-setup)<br><br>(global-set-key &quot;\M-g&quot;   'goto-line)<br>(global-set-key &quot;\M-m&quot;   'set-mark-command)<br><img src ="http://www.cppblog.com/go-benny/aggbug/47871.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/go-benny/" target="_blank">benny</a> 2008-04-23 10:02 <a href="http://www.cppblog.com/go-benny/archive/2008/04/23/32850.html#47871#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: 软RAID的简单用法</title><link>http://www.cppblog.com/go-benny/archive/2007/11/15/35141.html#36713</link><dc:creator>Benny</dc:creator><author>Benny</author><pubDate>Thu, 15 Nov 2007 12:40:00 GMT</pubDate><guid>http://www.cppblog.com/go-benny/archive/2007/11/15/35141.html#36713</guid><description><![CDATA[更正：--assume-clean选项是告诉md不要去检验校验盘是否正确<br>描述md的状态有clean,active,degraded,resyncing,recovering，<br>其中clean和active是一对的，active表示在有数据还留在缓存中，<br>而clean表示数据已经写入磁盘。active在以前的版本中是用dirty<br>描述的，但容易引起误解所以采用了active。resyncing表示在检查<br>校验数据是否正确，只有带奇偶校验的raid456才有这个状态，recovering<br>就是指重建的完成百分比<img src ="http://www.cppblog.com/go-benny/aggbug/36713.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/go-benny/" target="_blank">Benny</a> 2007-11-15 20:40 <a href="http://www.cppblog.com/go-benny/archive/2007/11/15/35141.html#36713#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: 模式编程见解</title><link>http://www.cppblog.com/go-benny/archive/2007/09/29/33207.html#33211</link><dc:creator>go-benny</dc:creator><author>go-benny</author><pubDate>Sat, 29 Sep 2007 09:37:00 GMT</pubDate><guid>http://www.cppblog.com/go-benny/archive/2007/09/29/33207.html#33211</guid><description><![CDATA[情景：网络编程时处理一对多的情况<br><br>方案：采用epoll模式实现。开源项目IET(iscsi enterprise target)采用了poll的模型，<br>据说epoll比poll更好，由于没有需求，所以我不深入研究。<br><br>以下是网上拷的代码片段<br><br>/*-------------------------------------------------------------------------------------------------<br>gcc -o httpd httpd.c -lpthread<br>author: wyezl<br>2006.4.28<br>---------------------------------------------------------------------------------------------------*/<br><br>#include &lt;sys/socket.h&gt;<br>#include &lt;sys/epoll.h&gt;<br>#include &lt;netinet/in.h&gt;<br>#include &lt;arpa/inet.h&gt;<br>#include &lt;fcntl.h&gt;<br>#include &lt;unistd.h&gt;<br>#include &lt;stdio.h&gt;<br>#include &lt;pthread.h&gt;<br>#include &lt;errno.h&gt;<br><br>#define PORT 8888<br>#define MAXFDS 5000<br>#define EVENTSIZE 100<br><br>#define BUFFER &quot;HTTP/1.1 200 OK\r\nContent-Length: 5\r\nConnection: close\r\nContent-Type: text/html\r\n\r\nHello&quot;<br><br>int epfd;<br>void *serv_epoll(void *p);<br>void setnonblocking(int fd)<br>{<br>    int opts;<br>    opts=fcntl(fd, F_GETFL);<br>    if (opts &lt; 0)<br>    {<br>          fprintf(stderr, &quot;fcntl failed\n&quot;);<br>          return;<br>    }<br>    opts = opts | O_NONBLOCK;<br>    if(fcntl(fd, F_SETFL, opts) &lt; 0)<br>    {<br>          fprintf(stderr, &quot;fcntl failed\n&quot;);<br>          return;<br>    }<br>    return;<br>}<br><br>int main(int argc, char *argv[])<br>{<br>    int fd, cfd,opt=1;<br>    struct epoll_event ev;<br>    struct sockaddr_in sin, cin;<br>    socklen_t sin_len = sizeof(struct sockaddr_in);<br>    pthread_t tid;<br>    pthread_attr_t attr;<br><br>    epfd = epoll_create(MAXFDS);<br>    if ((fd = socket(AF_INET, SOCK_STREAM, 0)) &lt;= 0)<br>    {<br>          fprintf(stderr, &quot;socket failed\n&quot;);<br>          return -1;<br>    }<br>    setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void*)&amp;opt, sizeof(opt));<br><br>    memset(&amp;sin, 0, sizeof(struct sockaddr_in));<br>    sin.sin_family = AF_INET;<br>    sin.sin_port = htons((short)(PORT));<br>    sin.sin_addr.s_addr = INADDR_ANY;<br>    if (bind(fd, (struct sockaddr *)&amp;sin, sizeof(sin)) != 0)<br>    {<br>          fprintf(stderr, &quot;bind failed\n&quot;);<br>          return -1;<br>    }<br>    if (listen(fd, 32) != 0)<br>    {<br>          fprintf(stderr, &quot;listen failed\n&quot;);<br>          return -1;<br>    }<br><br>    pthread_attr_init(&amp;attr);<br>    pthread_attr_setdetachstate(&amp;attr,PTHREAD_CREATE_DETACHED);<br>    if (pthread_create(&amp;tid, &amp;attr, serv_epoll, NULL) != 0)<br>    {<br>          fprintf(stderr, &quot;pthread_create failed\n&quot;);<br>          return -1;<br>    }<br><br>    while ((cfd = accept(fd, (struct sockaddr *)&amp;cin, &amp;sin_len)) &gt; 0)<br>    {<br>          setnonblocking(cfd);<br>          ev.data.fd = cfd;<br>          ev.events = EPOLLIN | EPOLLET;<br>          epoll_ctl(epfd, EPOLL_CTL_ADD, cfd, &amp;ev);<br>          //printf(&quot;connect from %s\n&quot;,inet_ntoa(cin.sin_addr));<br><br>          //printf(&quot;cfd=%d\n&quot;,cfd);<br><br>    }<br><br>    if (fd &gt; 0)<br>          close(fd);<br>    return 0;<br>}<br><br>void *serv_epoll(void *p)<br>{<br>    int i, ret, cfd, nfds;;<br>    struct epoll_event ev,events[EVENTSIZE];<br>    char buffer[512];<br><br>    while (1)<br>    {<br>          nfds = epoll_wait(epfd, events, EVENTSIZE , -1);<br>          //printf(&quot;nfds ........... %d\n&quot;,nfds);<br><br>          for (i=0; i&lt;nfds; i++)<br>          {<br>                if(events[i].events &amp; EPOLLIN)<br>                {<br>                    cfd = events[i].data.fd;<br>                    ret = recv(cfd, buffer, sizeof(buffer),0);<br>                    //printf(&quot;read ret..........= %d\n&quot;,ret);<br><br><br>                    ev.data.fd = cfd;<br>                    ev.events = EPOLLOUT | EPOLLET;<br>                    epoll_ctl(epfd, EPOLL_CTL_MOD, cfd, &amp;ev);<br>                }<br>                else if(events[i].events &amp; EPOLLOUT)<br>                {<br>                    cfd = events[i].data.fd;<br>                    ret = send(cfd, BUFFER, strlen(BUFFER), 0);<br>                    //printf(&quot;send ret...........= %d\n&quot;, ret);<br><br><br>                    ev.data.fd = cfd;<br>                    epoll_ctl(epfd, EPOLL_CTL_DEL, cfd, &amp;ev);<br>                    //shutdown(cfd, 1);<br><br>                    close(cfd);<br><br>                }<br>          }<br>    }<br>    return NULL;<br>}<br><img src ="http://www.cppblog.com/go-benny/aggbug/33211.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/go-benny/" target="_blank">go-benny</a> 2007-09-29 17:37 <a href="http://www.cppblog.com/go-benny/archive/2007/09/29/33207.html#33211#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux下用户态跟内核态交互的一个模式</title><link>http://www.cppblog.com/go-benny/archive/2007/09/29/33207.html#33209</link><dc:creator>go-benny</dc:creator><author>go-benny</author><pubDate>Sat, 29 Sep 2007 09:30:00 GMT</pubDate><guid>http://www.cppblog.com/go-benny/archive/2007/09/29/33207.html#33209</guid><description><![CDATA[情景：用户态下的cli程序，需要跟内核态下的软件模块交互<br>方案：编写一个字符设备作为控制设备，实现cli个内核模块的交互<br><br>代码：<br><br>1、控制设备驱动<br><br>/---------------------------Makefile-------------------------------/<br>EXTRA_CFLAGS := -I.<br>obj-m := chrdev.o<br><br>all:<br>make -C /lib/modules/`uname -r`/build M=`pwd`<br><br><br>/---------------------------chrdev.h-------------------------------/<br>#ifndef __CHRDEV_H__<br>#define __CHRDEV_H__<br>#define MAX_DESC_LEN 64<br>struct chrdev_ioctl {<br>    uint32_t cmd;<br>    char     desc[MAX_DESC_LEN];<br>};<br>#endif<br><br><br>/---------------------------chrdev.c-------------------------------/<br>#include &lt;linux/kernel.h&gt;<br>#include &lt;linux/init.h&gt;<br>#include &lt;linux/module.h&gt;<br>#include &lt;linux/miscdevice.h&gt;<br>#include &lt;linux/fs.h&gt;<br>#include &lt;asm/uaccess.h&gt;<br>#include &quot;chrdev.h&quot;<br><br><br>static int my_chrdev_ioctl(struct inode *inode, struct file *file,<br>unsigned int command, unsigned long u)<br>{<br>    int r = 0;<br>    unsigned int cmd;<br>    struct chrdev_ioctl param;<br>    struct chrdev_ioctl __user *user = (struct chrdev_ioctl __user *) u; <br>    r = copy_from_user(&amp;param, user, sizeof(param));<br>    if (!r)<br>        return -EFAULT;<br>    cmd = param.cmd;<br>    printk(&quot;cmd=%d\n&quot;, cmd);<br>    r = copy_to_user(user, &amp;param, sizeof(param));<br>    if (!r)<br>        r = -EFAULT;<br><br>    return r;<br>}<br><br>static const struct file_operations _ctl_fops= {<br>   .ioctl	 = my_chrdev_ioctl,<br>   .owner	 = THIS_MODULE,<br>};<br><br><br>static struct miscdevice _my_misc = {<br>   .minor 		= MISC_DYNAMIC_MINOR, <br>   .name  		= &quot;mychrdev&quot;,<br>   .fops  		= &amp;_ctl_fops<br>};<br><br><br>int __init chrdev_init(void)<br>{<br>    int r;<br>    r = misc_register(&amp;_my_misc);<br>    if (r) {<br>        printk(&quot;Failed to register a my chrdev.\n&quot;);<br>    }<br>    return 0;<br>}<br><br>void __exit chrdev_exit(void)<br>{<br>    misc_deregister(&amp;_my_misc);<br>}<br><br>module_init(chrdev_init);<br>module_exit(chrdev_exit);<br><br>2、用户态程序<br><br>/----------------------------main.c-----------------------------------/<br><br>#include &lt;stdio.h&gt;<br>#include &lt;fcntl.h&gt;<br><br>const char *ctl_dev = &quot;/dev/mychrdev&quot;;<br><br>struct chrdev_ioctl {<br>    unsigned int cmd;<br>    char     desc[64];<br>};<br><br>int main()<br>{<br>    int fd = -1;<br>    int cmd = 999;<br>    struct chrdev_ioctl param;<br>    param.cmd = cmd;<br><br>    if ((fd = open(ctl_dev, O_RDWR)) &lt; 0) {<br>         return -1;<br>    }<br>    ioctl(fd, cmd, &amp;param);<br>    close(fd);<br>    return 0;<br>}<br><br>[编辑]<br><br><img src ="http://www.cppblog.com/go-benny/aggbug/33209.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/go-benny/" target="_blank">go-benny</a> 2007-09-29 17:30 <a href="http://www.cppblog.com/go-benny/archive/2007/09/29/33207.html#33209#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: Linux kernel下实现Socket通讯</title><link>http://www.cppblog.com/go-benny/archive/2007/06/16/19468.html#26413</link><dc:creator>go-benny</dc:creator><author>go-benny</author><pubDate>Fri, 15 Jun 2007 16:20:00 GMT</pubDate><guid>http://www.cppblog.com/go-benny/archive/2007/06/16/19468.html#26413</guid><description><![CDATA[如果系统采用tcp通讯，socket通过3次握手建立起连接后，如果一端主动发起断开连接，tcp会通过4次握手把连接关闭，连接的另一方有个被动关闭连接的行为。但是如果一端是异常断开，比如系统突然kernel panic，此时另外一端为就会认它的连接仍然是正常的（tcp没有心跳的机制），只有等到它尝试发包失败后才知道。如何避免这种情况呢？我目前的解决方式就是人为的加个心跳检测机制，心跳是采用udp的方式实现，后来发现用udp实现心跳也有弊端，比如，当系统磁盘发生io错误导致系统接近死亡边缘的时候，由于cpu和中断都被占着，网络及容易丢包，从而导致误判。<img src ="http://www.cppblog.com/go-benny/aggbug/26413.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/go-benny/" target="_blank">go-benny</a> 2007-06-16 00:20 <a href="http://www.cppblog.com/go-benny/archive/2007/06/16/19468.html#26413#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: 关于Linux内核下调试代码的一些见解</title><link>http://www.cppblog.com/go-benny/archive/2007/06/15/18038.html#26409</link><dc:creator>benny</dc:creator><author>benny</author><pubDate>Fri, 15 Jun 2007 15:46:00 GMT</pubDate><guid>http://www.cppblog.com/go-benny/archive/2007/06/15/18038.html#26409</guid><description><![CDATA[补充一个 --  通过objdump来定位问题<br><br>    编译时在加上-g选项把代码编入.o文件，然后再通过下面的方式从.o文件中<br>导出机器码和汇编<br>    objdump -j .text -Sl xxx.o &gt; mydump.txt<br>    当内核打堆栈的时候这个文件mydump.txt就可以定为到具体代码的那一行<br>出现问题了。<img src ="http://www.cppblog.com/go-benny/aggbug/26409.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/go-benny/" target="_blank">benny</a> 2007-06-15 23:46 <a href="http://www.cppblog.com/go-benny/archive/2007/06/15/18038.html#26409#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: 多个工程时Makefile的组织方式</title><link>http://www.cppblog.com/go-benny/archive/2007/01/28/18110.html#18111</link><dc:creator>go-benny</dc:creator><author>go-benny</author><pubDate>Sun, 28 Jan 2007 06:24:00 GMT</pubDate><guid>http://www.cppblog.com/go-benny/archive/2007/01/28/18110.html#18111</guid><description><![CDATA[字体太难对齐了...<img src ="http://www.cppblog.com/go-benny/aggbug/18111.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/go-benny/" target="_blank">go-benny</a> 2007-01-28 14:24 <a href="http://www.cppblog.com/go-benny/archive/2007/01/28/18110.html#18111#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: 有序数组二分查找</title><link>http://www.cppblog.com/go-benny/archive/2006/09/11/12239.html#12302</link><dc:creator>benny</dc:creator><author>benny</author><pubDate>Mon, 11 Sep 2006 11:59:00 GMT</pubDate><guid>http://www.cppblog.com/go-benny/archive/2006/09/11/12239.html#12302</guid><description><![CDATA[练笔 :)<img src ="http://www.cppblog.com/go-benny/aggbug/12302.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/go-benny/" target="_blank">benny</a> 2006-09-11 19:59 <a href="http://www.cppblog.com/go-benny/archive/2006/09/11/12239.html#12302#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: 有序数组二分查找</title><link>http://www.cppblog.com/go-benny/archive/2006/09/11/12239.html#12246</link><dc:creator>周星星</dc:creator><author>周星星</author><pubDate>Mon, 11 Sep 2006 02:12:00 GMT</pubDate><guid>http://www.cppblog.com/go-benny/archive/2006/09/11/12239.html#12246</guid><description><![CDATA[C语言中有标准函数 bsearch<br>C++中有标准函数 binary_search<img src ="http://www.cppblog.com/go-benny/aggbug/12246.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/go-benny/" target="_blank">周星星</a> 2006-09-11 10:12 <a href="http://www.cppblog.com/go-benny/archive/2006/09/11/12239.html#12246#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>