Bug 12964

Summary: Outgoing data with stream sockets on FreeBSD
Product: Base System Reporter: ypoeluev <ypoeluev>
Component: i386Assignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
ypoeluev.vcf none

Description ypoeluev 1999-08-04 16:40:01 UTC
Hi,
I'm using stream sockets for client and server communications
and have found a problem with data sent from FreeBSD to
any other platform (Solaris,WinNT,BSDi,etc). When the data
has a size in the range 101-207 bytes, the receiver gets
only 100 bytes. By the way, I was using blocking sockets
and if I tried to read data again on the receiver side (other then FreeBSD),
read operation can't succeed because apparently no data left for reading.
There might have been some settings when we built our kernel,
but I couldn't find anything.
Your help will be appretiated.
Thanks.

How-To-Repeat: On the server side (FreeBSD)
=====================================
theSocket = socket(AF_INET, SOCK_STREAM, 0);
theAddress.sin_port = htons((unsigned short)kPort);
theAddress.sin_family = AF_INET;
bind(theSocket, (struct sockaddr *)&theAddress, sizeof(theAddress));
listen(theSocket, 5);
len = sizeof(theAddress);
hisSocket = accept(theSocket,(struct sockaddr*)&theAddress, &len);
send(hisSocket,buffer,105,0);
...


On the client side (any other platform)
=====================================
s = socket(AF_INET, SOCK_STREAM, 0);
ent = gethostbyname(kServer);
addressRec.sin_port = htons((unsigned short)kPort);
addressRec.sin_family = AF_INET;
addressRec.sin_addr = *((struct in_addr *)ent->h_addr);
connect(s, (struct sockaddr *) &addressRec, sizeof(addressRec));
l=recv(s,buffer,sizeof(buffer),0); /* only 100 bytes read */
...
Comment 1 Adrian Chadd freebsd_committer freebsd_triage 1999-08-10 14:53:58 UTC
This was fixed in src/sys/kern/uipc_socket.c v1.41 .. 
your best bet is to either hand patch the kernel and see if it works,
or just upgrade to a later release.

This PR can be closed. Someone?


Adrian
Comment 2 ypoeluev 1999-08-10 16:42:33 UTC
Hi Adrian,

Thanks for your reply. I have found a solution.
Apparently, stream sockets do not guarantee
that a packet at the application level will be
delivered in one piece. It was wrong for
me to say that I was losing data, that wasn't the case.
The application-sender was sending a
packet of 150 bytes, for instance,
first time the application-receiver got 100 bytes and
second time it got the rest 50 bytes. Anyway, my impression
of stream sockets was that if an application sends a packet,
an application-receiver would get the same
packet or bigger one if more data is available
from UDP. I guess, I was wrong to assume
that stream sockets will not break the
packets at the application level. But,
it's still interesting that only on FreeBSD stream
sockets break packets (101-207-byte long)
into two. In my case, I'd rather use packet
oriented sockets (datagram), that guarantees
packets delivery with possible loss of packets though.
Some people were saying that you can send a
delimiter (CR) to separate packets inside
the data stream, but if an application
sends binary data this is not a good choice of course.
It seems that an application cannot have
reliable and packet oriented protocol at the
same time.

Sorry for taking your time.
Please, close this PR.

Thanks,
Yuri Poeluev
Certicom Corp.
Comment 3 Adrian Chadd freebsd_committer freebsd_triage 1999-08-10 16:56:48 UTC
State Changed
From-To: open->closed

Submitter reports this can be closed.