資源描述:
《【精品】網(wǎng)絡(luò)協(xié)議棧函數(shù).doc》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、jsend:
2、[(write」readiiirccvii4??Sys.sendSys^rriteSys.readU、Sys.recvjSock_readv_writev.Sock.sendasif1Isoek.recvasgj4znTcpsendBigItcp.recvasgTcp.puihtcp^writtcp^transiit^skbI1tcp」4_do_n「tcp-rcv.itace^proceiitcp.v4.rcvip.local^delivertcp.rcv-established
3、iTp^outputTipITTnlsIFouFpuHil-"T--lidev^queue^ioitj】P」cv丨]necif^receite.skb[netif^riep^r/poll~Fcp^interrupt,圖2TCP協(xié)議棧在Linux±的實(shí)現(xiàn)(以下文件路徑都是在2.6.28.7內(nèi)核Z下,在其它內(nèi)核下有可能源碼的位置不一樣)輸出過程:1、(sock_sendmsg在kernel/net/socket.c)intsock_sendmsg(structsocket*sock,structm
4、sghdr*msg,size_tsize){structkiocbiocb;structsock_iocbsiocb;intret;init_sync_kiocb(&iocb,NULL);iocb.private=&siocb;ret=_sock_sendmsg(&iocb,sock,msg,size);if(-EIOCBQUEUED==ret)ret=wait_on_sync_kiocb(&iocb);returnret;}2、tcp_sendmsg在kernel/net/ipv4/tcp.c
5、Tinttcp_sendmsg(structkiocb*iocb,structsocket*sock,structmsghdr*msg,size_tsize){structsock*sk=sock->sk;structiovec*iov;structtcp_sock*tp=tcp_sk(sk);structsk_buff*skb;intiovlen,flags;intmss_now,size_goal;interr,copied;longtimeo;lock_sock(sk);TCP_CHECK
6、_TIMER(sk);flags=msg->msg_flags;timeo=sock_sndtimeo(sk,flags&MSG_DONTWAIT);/*Waitforaconnectiontofinish?*/if((l?sk->sk_state)&?(TCPF_ESTABLISHEDITCPF_CLOSE_WAIT))if((err=sk_stream_wait_connect(sk,&timeo))!=0)gotoout_err;/*Thisshouldbeinpoll*/clear_bi
7、t(SOCK_ASYNC_NOSPACE,&sk->sk_socket->flags);mss_now=tcp_current_mss(sk,!(flags&MSG_OOB));size_goal=tp->xmit_size_goal;/*Okcommencesending.*/iovlen=msg?>msg_iovlen;iov=msg->msg_iov;copied=0;err=-EPIPE;訐(sk->sk_errII(sk->sk_shutdown&SEND_SHUTDOWN))goto
8、do_error;while(—iovlen>=0){intseglen=iov->iov_len;unsignedchar_user*from=iov->iov_base;iov++;while(seglen>0){intcopy;skb=tcp_write_queue_tail(sk);if(!tcp_send_head(sk)II(copy=size_goal-skb->len)<=0){new_segment:/*Allocatenewsegment.IftheinterfaceisSG
9、*allocateskbfittingtosinglepage?*/if(!sk_stream_memory_free(sk))gotowait_for_sndbuf;skb=sk_stream_alloc_skb(sk,select_size(sk),sk->sk_allocation);if(!skb)gotowait_for_memory;/**CheckwhetherwecanuseHWchecksum.*/if(sk->sk_route_caps&NETIF_F_ALL_CSUM)sk