?? 2_4網(wǎng)絡(luò)代碼閱讀筆(3) - china linux forum.htm
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0111)http://www.linuxforum.net/forum/showflat.php?Cat=&Board=linuxK&Number=147051&page=120&view=collapsed&sb=5&o=all -->
<HTML><HEAD><TITLE>2.4網(wǎng)絡(luò)代碼閱讀筆(3) - China Linux Forum</TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<META content="MSHTML 5.00.2920.0" name=GENERATOR></HEAD>
<BODY>
<CENTER><FONT color=red>著名軟件中國鏡像:</FONT> <A
href="http://apache.linuxforum.net/"><FONT color=red>Apache|</FONT></A> <A
href="http://php.linuxforum.net/"><FONT color=red>Php|</FONT></A> <A
href="http://debian.linuxforum.net/"><FONT color=red>Debian|</FONT></A> <A
href="http://mysql.linuxforum.net/"><FONT color=red>Mysql|</FONT></A> <A
href="http://proftpd.linuxforum.net/"><FONT color=red>Proftp|</FONT></A> <A
href="http://qmail.linuxforum.net/top.html"><FONT color=red>Qmail|</FONT></A> <A
href="http://samba.linuxforum.net/samba.html"><FONT color=red>Samba|</FONT></A>
<A href="http://www1.cn.squid-cache.org/"><FONT color=red>Squid|</FONT></A> <A
href="http://xfree86.linuxforum.net/"><FONT color=red>Xfree86|</FONT></A> <A
href="http://cpan.linuxforum.net/"><FONT color=red>CPAN|</FONT></A> <A
href="http://ldp.linuxforum.net/"><FONT color=red>LDP|</FONT></A> <A
href="http://gnu.linuxforum.net/"><FONT
color=red>GNU|</FONT></A></CENTER><BR><LINK
href="2_4網(wǎng)絡(luò)代碼閱讀筆(3) - China Linux Forum.files/stylesheet2.css" rel=stylesheet
type=text/css><SPAN class=onbody>
<TABLE align=center border=0 cellPadding=3 cellSpacing=0 class=p9 width="95%">
<TBODY>
<TR align=right bgColor=#0099cc vAlign=center>
<TD align=left width="20%"><A
href="http://www.linuxforum.net/index.php"><FONT
color=#ffffff>中國Linux論壇首頁</FONT></A></TD>
<TD width="80%"><A
href="http://www.linuxforum.net/forum/ubbthreads.php"><FONT
color=#ffffff>技術(shù)論壇|</FONT></A><FON color="#FFFFFF" t> <A
href="http://www.linuxforum.net/docnew/index.php"><FONT
color=#ffffff>文章薈萃</FONT></A><FONT color=#ffffff>| <A
href="http://www.linuxforum.net/books/index.php"><FONT
color=#ffffff>藏經(jīng)閣</FONT></A>| <A href="http://mail.linuxforum.net/"><FONT
color=#ffffff>會員信箱</FONT></A>| <A href="http://sf.linuxforum.net/"><FONT
color=#ffffff>項目計劃</FONT></A>| <A
href="http://www.linuxforum.net/poll2/index.php"><FONT
color=#ffffff>在線調(diào)查</FONT></A>| <A href="ftp://ftp.linuxforum.net/"><FONT
color=#ffffff>軟件倉庫</FONT></A>| <A
href="http://www.linuxforum.net/about.php"><FONT
color=#ffffff>關(guān)于本站</FONT></A>| </FONT></TD></TR></TBODY></TABLE><BR></SPAN>
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 width="95%">
<TBODY>
<TR>
<TD class=tableborders>
<TABLE border=0 cellPadding=3 cellSpacing=1 width="100%">
<TBODY>
<TR>
<TD align=right class=menubar><A
href="http://www.linuxforum.net/forum/ubbthreads.php?Cat=">討論區(qū)列表</A>
| <A href="http://www.linuxforum.net/forum/search.php?Cat=">搜尋文章</A>
| <A
href="http://www.linuxforum.net/forum/newuser.php?Cat=">新用戶注冊</A> |
<A href="http://www.linuxforum.net/forum/login.php?Cat=">登入論壇</A> |
<A href="http://www.linuxforum.net/forum/online.php?Cat=">在線用戶</A> |
<A
href="http://www.linuxforum.net/forum/faq_chinese.php?Cat=">常見問題</A>
</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<P>
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 width="95%">
<TBODY>
<TR>
<TD class=tableborders>
<TABLE border=0 cellPadding=3 cellSpacing=1 width="100%">
<TBODY>
<TR class=darktable>
<TD>
<TABLE cellPadding=0 cellSpacing=0 width="100%">
<TBODY>
<TR class=darktable>
<TD align=left width="33%"><SPAN class=catandforum><A
href="http://www.linuxforum.net/forum/ubbthreads.php?Cat=&C=4">Linux
高級應(yīng)用</A> <BR> >> <A
href="http://www.linuxforum.net/forum/postlist.php?Cat=&Board=linuxK&page=120&view=collapsed&sb=5&o=all">Linux內(nèi)核技術(shù)</A>
</SPAN></TD>
<TD align=middle width="33%">此話題閱讀次數(shù): 369 </TD>
<TD align=right width="33%">
<TABLE border=0>
<TBODY>
<TR>
<TD class=navigation noWrap><IMG align=absMiddle alt=*
src="2_4網(wǎng)絡(luò)代碼閱讀筆(3) - China Linux Forum.files/greyflat.gif">平坦模式
</TD>
<TD class=navigation noWrap><A
href="http://www.linuxforum.net/forum/showthreaded.php?Cat=&Board=linuxK&Number=147051&page=120&view=collapsed&sb=5&o=all&vc=1"><IMG
align=absMiddle alt=樹狀模式,一封一封讀 border=0
src="2_4網(wǎng)絡(luò)代碼閱讀筆(3) - China Linux Forum.files/threaded.gif">樹狀模式</A>
</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<TABLE align=center border=0 cellPadding=4 cellSpacing=0 width="95%">
<TBODY>
<TR>
<TD align=left class=small> </TD>
<TD align=right class=small><A
href="http://www.linuxforum.net/forum/printthread.php?Cat=&Board=linuxK&main=147051&type=thread"
target=_blank><IMG align=top border=0
src="2_4網(wǎng)絡(luò)代碼閱讀筆(3) - China Linux Forum.files/printthread.gif"> 打印</A>
</TD></TR></TBODY></TABLE>
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 width="95%">
<TBODY>
<TR>
<TD class=tableborders>
<TABLE border=0 cellPadding=3 cellSpacing=1 width="100%">
<TBODY>
<TR>
<TD class=darktable rowSpan=2 vAlign=top width="17%"><A
name=Post147051></A><A
href="http://www.linuxforum.net/forum/showprofile.php?Cat=&User=ysqcn&Number=147051&Board=linuxK&what=showflat&page=120&view=collapsed&sb=5&o=all&fpart=1&vc=1">ysqcn</A><BR><SPAN
class=small>(newbie)<BR>08/01/01 20:26<BR></SPAN></TD>
<TD class=subjecttable width="83%">
<TABLE border=0 class=subjecttable width="100%">
<TBODY>
<TR>
<TD align=left width="70%"><IMG height=15
src="2_4網(wǎng)絡(luò)代碼閱讀筆(3) - China Linux Forum.files/book.gif"
width=15> <B>2.4網(wǎng)絡(luò)代碼閱讀筆(3)</B> </TD>
<TD align=right width="30%"> </TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD class=lighttable width="83%"><BR>
<P class=post>發(fā)信人: ysqcn (歲月無聲), 信區(qū): llkm <BR>標(biāo) 題: 2.4網(wǎng)絡(luò)代碼閱讀筆(3)
<BR>發(fā)信站: UNIX編程 (2001年06月13日15:04:42 星期三), 站內(nèi)信件
<BR><BR>在就是sys_listen了,這個函數(shù)更簡單: <BR>asmlinkage long sys_listen(int
fd, int backlog) <BR>{ <BR>struct socket *sock; <BR>int err;
<BR><BR>if ((sock = sockfd_lookup(fd, &err)) != NULL) { <BR>if
((unsigned) backlog > SOMAXCONN) <BR>backlog = SOMAXCONN;
<BR>>>>>這里調(diào)用BSD層的inet_listen
<BR>err=sock->ops->listen(sock, backlog);
<BR>sockfd_put(sock); <BR>} <BR>return err; <BR>} <BR><BR>int
inet_listen(struct socket *sock, int backlog) <BR>{ <BR>struct sock
*sk = sock->sk; <BR>unsigned char old_state; <BR>int err;
<BR>lock_sock(sk); <BR>err = -EINVAL; <BR>if (sock->state !=
SS_UNCONNECTED || sock->type != SOCK_STREAM) <BR>goto out;
<BR>old_state = sk->state; <BR>if
(!((1<<OLD_STATE)&(TCPF_CLOSE|TCPF_LISTEN))) <br> goto out;
<BR>/* Really, if the socket is already in listen state <BR>* we can
only allow the backlog to be adjusted. <BR>*/ <BR>if (old_state !=
TCP_LISTEN) { <BR>err = tcp_listen_start(sk); <BR>if (err) <BR>goto
out; <BR>} <BR>>>>>保存backlog到struct sock結(jié)構(gòu)中去
<BR>sk->max_ack_backlog = backlog; <BR>err = 0; <BR>out:
<BR>release_sock(sk); <BR>return err; <BR>} <BR><BR>int
tcp_listen_start(struct sock *sk) <BR>{ <BR>struct tcp_opt *tp =
&(sk->tp_pinfo.af_tcp); <BR>struct tcp_listen_opt *lopt;
<BR>>>>>先做一些初始化 <BR>sk->max_ack_backlog = 0;
<BR>sk->ack_backlog = 0; <BR>tp->accept_queue =
tp->accept_queue_tail = NULL; <BR>tp->syn_wait_lock =
RW_LOCK_UNLOCKED; <BR>>>>>memset(&tp->ack, 0,
sizeof(tp->ack)); <BR>tcp_delack_init(tp); <BR>lopt =
kmalloc(sizeof(struct tcp_listen_opt), GFP_KERNEL); <BR>if (!lopt)
<BR>return -ENOMEM; <BR>memset(lopt, 0, sizeof(struct
tcp_listen_opt)); <BR>for (lopt->max_qlen_log = 6; ;
lopt->max_qlen_log++) <BR>if ((1<<LOPT->max_qlen_log) >=
sysctl_max_syn_backlog) <BR>break;
<BR>write_lock_bh(&tp->syn_wait_lock); <BR>tp->listen_opt
= lopt; <BR>write_unlock_bh(&tp->syn_wait_lock); <BR>/* There
is race window here: we announce ourselves listening, <BR>* but this
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -