Tuesday, April 28, 2009

windows size 0 (flow control)

sunucumuz listen da kaldığı için tcp nın read bufferina aldığı veriyi okuyamıyor.ve buffer dolunca windows size ini 0 olarak veriyor.bu tcp nin flow control una örnek bi uygulamadır.

posta:~/ozan# cat serverv2.c
#include
#include
#include
#include
#include
#include
#include


int main(int argc, char *argv[]) {

int sockfd,i;
struct sockaddr_in server, client;
struct in_addr addr;
char buffer[100];
socklen_t addrlen;
char *ip = argv[1];
int port = atoi(argv[2]);
addrlen = sizeof(client);
sockfd = socket(PF_INET, SOCK_STREAM,IPPROTO_TCP);

server.sin_family = AF_INET;
server.sin_port = htons(port);
inet_aton(ip, &addr);
server.sin_addr = addr;

bind(sockfd, (struct sockaddr *)&server,sizeof(server));


listen(sockfd, 10);
while(1)
;
}


aşağıda istemcimiz

posta:~/ozan# cat clientv3.c
#include
#include
#include
#include
#include
#include
#include

int main(int argc, char *argv[]) {

int sockfd,i;
ssize_t okunan;
struct sockaddr_in server, addr1;
struct in_addr addr;
fd_set rfds,masters;
char buffer[100];
char *ip = argv[1];
int port = atoi(argv[2]);


sockfd = socket(PF_INET, SOCK_STREAM,IPPROTO_TCP);


server.sin_family = AF_INET;
server.sin_port = htons(port);
inet_aton(ip, &addr);
server.sin_addr = addr;


connect(sockfd,(struct sockaddr *) &server, sizeof(struct sockaddr_in));

FD_ZERO (&masters);
FD_SET(0,&masters);
FD_SET(sockfd, &masters);

for(;;) {
memcpy(&rfds, &masters, sizeof (fd_set));
select(sockfd+1, &rfds, NULL, NULL, NULL);
memset(buffer, 0, sizeof(buffer));
if (FD_ISSET(0, &rfds)) {
okunan = read(0, buffer, 100);
write(sockfd,buffer, okunan);
}
if (FD_ISSET(sockfd, &rfds)) {
okunan = read (sockfd, buffer, 100);
write(1, buffer, okunan);
}
}
}


posta:~/ozan# ./serverv2 10.0.100.250 8888
posta:~/ozan# ./clientv3 10.0.100.250 8888 < /boot/initrd.img-2.6.18-6-686
posta:~/ozan# netstat -tanp | grep 8888
tcp 0 0 10.0.100.250:8888 0.0.0.0:* LISTEN 15089/serverv2
tcp 0 193436 10.0.100.250:54243 10.0.100.250:8888 ESTABLISHED 15090/clientv3
tcp 70472 0 10.0.100.250:8888 10.0.100.250:54243 ESTABLISHED -




posta:~/ozan# nc 10.0.100.250 8888 < /boot/initrd.img-2.6.18-6-686
posta:~/ozan# tcpdump -n -i lo -S port 8888
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on lo, link-type EN10MB (Ethernet), capture size 96 bytes
22:21:00.932770 IP 10.0.100.250.54248 > 10.0.100.250.8888: S 2858027941:2858027941(0) win 32792
22:21:00.932832 IP 10.0.100.250.8888 > 10.0.100.250.54248: S 2851759867:2851759867(0) ack 2858027942 win 32768
22:21:00.932861 IP 10.0.100.250.54248 > 10.0.100.250.8888: . ack 2851759868 win 8198
22:21:00.933836 IP 10.0.100.250.54248 > 10.0.100.250.8888: P 2858027942:2858036134(8192) ack 2851759868 win 8198
22:21:00.933881 IP 10.0.100.250.8888 > 10.0.100.250.54248: . ack 2858036134 win 12311
22:21:00.933940 IP 10.0.100.250.54248 > 10.0.100.250.8888: P 2858036134:2858044326(8192) ack 2851759868 win 8198
22:21:00.933949 IP 10.0.100.250.8888 > 10.0.100.250.54248: . ack 2858044326 win 12311
22:21:00.934000 IP 10.0.100.250.54248 > 10.0.100.250.8888: P 2858044326:2858052518(8192) ack 2851759868 win 8198
22:21:00.934007 IP 10.0.100.250.8888 > 10.0.100.250.54248: . ack 2858052518 win 11518
22:21:00.934045 IP 10.0.100.250.54248 > 10.0.100.250.8888: P 2858052518:2858060710(8192) ack 2851759868 win 8198
22:21:00.934112 IP 10.0.100.250.54248 > 10.0.100.250.8888: P 2858060710:2858077094(16384) ack 2851759868 win 8198
22:21:00.973719 IP 10.0.100.250.8888 > 10.0.100.250.54248: . ack 2858093478 win 1278
22:21:01.181695 IP 10.0.100.250.54248 > 10.0.100.250.8888: P 2858093478:2858098590(5112) ack 2851759868 win 8198
22:21:01.181733 IP 10.0.100.250.8888 > 10.0.100.250.54248: . ack 2858098590 win 0
22:21:01.389694 IP 10.0.100.250.54248 > 10.0.100.250.8888: . ack 2851759868 win 8198
22:21:01.389720 IP 10.0.100.250.8888 > 10.0.100.250.54248: . ack 2858098590 win 0
22:21:01.805684 IP 10.0.100.250.54248 > 10.0.100.250.8888: . ack 2851759868 win 8198
22:21:01.805705 IP 10.0.100.250.8888 > 10.0.100.250.54248: . ack 2858098590 win 0
22:21:02.637701 IP 10.0.100.250.54248 > 10.0.100.250.8888: . ack 2851759868 win 8198
22:21:02.637741 IP 10.0.100.250.8888 > 10.0.100.250.54248: . ack 2858098590 win 0


posta:~/ozan# netstat -tanp | grep 8888
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

tcp 0 0 10.0.100.250:8888 0.0.0.0:* LISTEN 15099/serverv2
tcp 0 207880 10.0.100.250:54248 10.0.100.250:8888 ESTABLISHED 15125/nc
tcp 70648 0 10.0.100.250:8888 10.0.100.250:54248 ESTABLISHED -


This indicates that the serve side receive buffer has gotten full and that it cannot
accommodate any more data. All this is happening because there is no one to
consume the data in the server ’ s receive buffer. The only way these data are consumed
is when it is read by an application. Since the server application has not yet
accepted the connection fully by issuing accept(), the client can get connected to
the server and do very limited one - way data transfer from client to server. But this
study tells that the even though the connection request is in the accept queue in the
established state, the TCP connection is fully functional between the two ends, but
the absence of read/write at the server end makes this socket connection a very
limited one - way channel from client to server.

No comments: