Cheapos Tcp/ip

一、Tcp/ip

Cheapos中的tcp/ip来看

int listen(int sockfd, int backlog)中的backlog

DESCRIPTION

       To  accept  connections, a socket is first created with socket(2), a willingness to accept incoming connections and a queue limit for incoming con-

       nections are specified with listen(), and then the connections are accepted with accept(2).  The listen() call applies  only  to  sockets  of  type

       SOCK_STREAM or SOCK_SEQPACKET.

 

       The backlog parameter defines the maximum length the queue of pending connections may grow to.  If a connection request arrives with the queue full

       the client may receive an error with an indication of ECONNREFUSED or, if the underlying protocol  supports  retransmission,  the  request  may  be

       ignored so that retries succeed.

五元组区分,包括源IP地址、源端口、传输层协议号(协议类型)、目的IP地址、目的端口

/proc/sys/net/ipv4/tcp_max_syn_backlog默认128调优1024

/proc/sys/net/core/somaxconn默认128调优1024

 

只讨论tcp的。

Socket可以为“index”也可以是“实例”【直接的资源】。本实现中即为“实例”。

 

ØSOCKET * socket(u16 af, u16 type, u16 protocol)

laf/type未用

lprotocoltcp/udp

此函数返回SOCKET TCP_Socket[MAX_TCP_LINKS]中未用的TCP_Socket[i]

 

Øu16 bind(SOCKET * sock, struct sockaddr * address, u8 len)

 

此函数把srv ip/port 赋值给socket[i]中的ip/port,即为绑定。

 

Øu16 listen(SOCKET * sock,  u16 QTY)

lQTY未用,backlog[The backlog parameter defines the maximum length the queue of pending connections may grow to]

 

此函数把socket[i].port 赋值给 为0TCP_PORT_Listening[i]。即把socket[i].port投入使用[listen]

 

u16 TCP_PORT_Listening[MAX_TCP_Listening_Ports];/*本地TCP监听端口表*/

u16 Local_PORT_Pool[MAX_Local_PORT_Pool_SIZE];/*本地端口分配表*/

 

Øu16 accept(SOCKET * sock, struct sockaddr * address, u16 *iii)

此函数返回一个已经握手OKsocket index,供recv/send使用。

 

 

到此简单的介绍就结束了,该采取倒叙的手法来归根溯源了。先从recv ethernet frame 说起

Øethernet

 

 

ØIP

 

8位协议中常用的

ICMP(1)ICMP(2)TCP(6)UDP(17)

ØTCP

 

 

 

 

 

 

 

 

 

ØARP

ARPreq=0x01resp=0x02

RARPreq=0x03resp=0x04

 

网卡enc28j60

 

先从第一握手讲起【SYN

准备:

主动connect的为cli

cli获取sock资源,bind(一般cli非必须,本例中也只是sock资源中的src.ip/src.port赋值而已)后就connect

 

 

握手

 

 

 

 

SN:握手场景正常send/recv数据场景是一样的。

1.peer0 send syn

 

2.peer1 recv syn

 

peer0 recv  syn+ack时,setup SN.peer1





posted @ 2016-05-11 19:04  自由度  Views(381)  Comments(0)    收藏  举报