Re: TCP-IP questions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



<quote sender="Bryan K.">
> I am implementing a server-client tcp-ip application and I would like to 
> know some things.
> 
> a) When read(2) returns, is it sure that the other side has recieved the 
> whole buffer passed to read(2)?

"On success, the number of bytes read is returned (zero indicates
end of file), and the file position  is advanced  by  this  number.   
It  is  not  an  error  if this number is smaller than the number of bytes
requested; this may happen for example because fewer bytes  are  actually 
available  right  now (maybe because  we  were  close  to end-of-file, or
because we are reading from a pipe, or from a terminal), or because read() 
was interrupted by a signal.  On error, -1 is returned, and errno is  set  
appropriately.  In this case it is left unspecified whether the file
position (if any) changes."

so, if the other side receive the whole buffer passed, read will return
the number of bytes.

> b) If i have a loop which write(2) one byte at each itteration, the kernel 
> sends many tcp packets each one containing one byte of userfull data?

what if the other host cannot receive your packet? the way you write it
is quite high-level, so you have to take care of packet loss, and all
that... so that it can resend lost packets, etc. try reading the RFC for
TFTP.

> c) An ACK is sent when the kernel receives a tcp packet or when a userspace 
> read(2) from the socket occurs?

when the kernel receive a packet, ip_rcv() captures it... but to know if
it is an ACK, then your application should check it. The kernel won't be
able to know because it depends on your data structure and
implementation of your user-land application.

Eugene
-- 
Eugene TEO @ Linux Users Group, Singapore <eugeneteo@lugs.org.sg>
GPG FP: D851 4574 E357 469C D308  A01E 7321 A38A 14A0 DDE5 
main(i){putchar(182623909>>(i-1)*5&31|!!(i<7)<<6)&&main(++i);}

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux