linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Javier Martinez Canillas <martinez.javier@gmail.com>
To: ratheesh kannoth <ratheesh.ksz@gmail.com>
Cc: "linux-c-programming@vger.kernel.org"
	<linux-c-programming@vger.kernel.org>
Subject: Re: close() on tcp socket.
Date: Wed, 6 Apr 2011 13:54:46 +0200	[thread overview]
Message-ID: <BANLkTi=kMZHoeef90BFNG-hmo-c4VAzR0w@mail.gmail.com> (raw)
In-Reply-To: <BANLkTimLJ4k1KzmzHkz10JvL9HTyb0y+WQ@mail.gmail.com>

On Wednesday, April 6, 2011, ratheesh kannoth <ratheesh.ksz@gmail.com> wrote:
> connect() system call establishes a connection as shown in below steps.
>
> 1.   |client |  ----------------- syn --------------->  | server |
>
> 2.  |Server|  --------------syn+ ack --------------> | client |
>
> 3.  | Client | -----------------ack --------------------> | Server |
>
>
> But establishing connection , client calls close() system call. Client
> is sending FIN+ ACK to server  [ i expected only FIN to be sent from
> client to server ]
>
> Is this a valid scenario.?  what could be the problem ?
>
>
> -Ratheesh

The problem is that both sides can never coordinate to close the
connection. So TCP does the best it can. It notifies the other side
that the connection will be closed and start a timer. If the othet
side gets the FIN + ACK its send an ACK. When the sender gets the ACK
closes the connection. If the ACK doesnt arrive and the timer expires,
it just close the connection, the other side will eventually will
notice that the connection was closed so it will also close its side.
So you dont need a handshacking protocol. In fact you cant design a
robust protocol. This is a particular case of a more general problem
known as the two army problem [1]

[1] http://en.m.wikipedia.org/wiki/Two_Generals'_Problem

Hope it helps,
Javier

-- 
-----------------------------------------
Javier Martínez Canillas
(+34) 682 39 81 69
PhD Student in High Performance Computing
Computer Architecture and Operating System Department (CAOS)
Universitat Autònoma de Barcelona
Barcelona, Spain
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2011-04-06 11:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-06 11:00 close() on tcp socket ratheesh kannoth
2011-04-06 11:54 ` Javier Martinez Canillas [this message]
2011-04-06 19:20 ` Glynn Clements
2011-04-17 12:26 ` Mahavir Jain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='BANLkTi=kMZHoeef90BFNG-hmo-c4VAzR0w@mail.gmail.com' \
    --to=martinez.javier@gmail.com \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=ratheesh.ksz@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).