in Computer Networks
11,452 views
43 votes

A client process P needs to make a TCP connection to a server process S. Consider the following situation: the server process S executes a $\text{socket()}$, a $\text{bind()}$ and a $\text{listen()}$ system call in that order, following which it is preempted. Subsequently, the client process P executes a $\text{socket()}$ system call followed by $\text{connect()}$ system call to connect to the server process S. The server process has not executed any $\text{accept()}$ system call. Which one of the following events could take place?

  1. $\text{connect()}$ system call returns successfully

  2. $\text{connect()}$ system call blocks

  3. $\text{connect()}$ system call returns an error

  4. $\text{connect()}$ system call results in a core dump

in Computer Networks
11.5k views

8 Comments

moved by
CAN any1 explain in what cases the call is blocked and call results in core dump.....what is this core dump??
1
what is "CORE DUMP"

A core dump is the printing or the copying to a more permanent medium (such as a hard disk) the contents of random access memory ( RAM ) at one moment in time. One can think of it as a full-length "snapshot" of RAM. A core dump is taken mainly for the purpose of debugging a program
14
edited by

Diagram --> 

For explanation watch from time 6:00 --> 

1
edited by
so here both the client and server are deployed in the same machine ?? @reena_kandari

so here in this case if the premption takes place after calling accept() then the option would be B
0
1
0
edited by

Accept() call has nothing to do with connection phase, it's just move the next completed connection from completed queue to the process.

And also,

Data queued in the socket's receive buffer. Data that arrives after the three-way handshake completes, but before the server calls accept, should be queued by the server TCP, up to the size of the connected socket's receive buffer.

Reference : https://notes.shichao.io/unp/ch4/

Now coming back to the question, error of Destination port unreachable will come due to tcp server process being preempted and there's no socket listening to client's connection request.

 

0

1

3 Answers

99 votes
 
Best answer

First thing to note: All the sockets are by default in BLOCKING mode. What do we mean by blocking ??

Blocking mode means that when we make a system call, it blocks the caller for the time "when call() is made till the job is done OR an error returns ". We can set each socket to Non-blocking explicitly. Setting to Non-Blocking means we are telling the kernel that "If the system call cant be completed without putting process to sleep then DON'T put the process to sleep . Instead return with an ERROR immediately and continue the process" which can be checked for the completion by the caller in between the execution of other tasks.

Now coming to this question:

Suppose connect() is in default blocking mode then calling connect() sends SYN packet to the server. Since server has not executed any accept() call it can not acknowledge the SYN packet. Connect() in blocking mode keep sending SYN packets at fixed intervals(first after 6 sec, second after 24 sec typically until 75 sec latest). This is done until an error ETIMEDOUT is returned by the TCP.(in this case,else there are several other type of errors returned in case No port exists for that connection or server id not listening etc.)

Here, option (B) saying that connect() blocks is not entirely wrong but since we know that accept() call is not made by server, connect() WILL NOT WAIT FOREVER and SO IT CAN NOT BLOCK. It will ultimately return with an ERROR message.

So, option (C) is CORRECT.

Core dump thing I don't know about!

But once connect() returns error that socket can not be reused and must be CLOSED.

And a non-blocking connect() is never blocked and immediately returns with an error if connection is not successful although IT CONTINUES WITH TRYING TO CONNECT .Error here just means that it returns a message saying "I could not connect immediately BUT i am trying AND you can check it in between.

Hope it clears a bit.

edited by

7 Comments

Any references Sandeep ?
3
edited by

Since server has not executed any accept() call it can not acknowledge the SYN packet.

@Sandeep

How can we say above thing 

accept will only return the next waiting request which is in complete queue placed after successful 3 way handshake

Here IF in given question server is not preempted after listen , connect may have returned succesfully

https://stackoverflow.com/questions/2409277/can-connect-call-on-socket-return-successfully-without-server-calling-accept

But as server preempted after listen , port unreachable reply will come as response of connect and it return error.

 

2
Best and informative explanation.
0

Please can someone who downvoted to this explain reason..so that i can correct my concept if wrong ..

0

It will ultimately return with an ERROR message.

As the program responsible for the response of connect() of client is pre-empted,

Who will return this error message?

0

can you tell the source of this image?

0
38 votes

Simple it is. given that the server process is preempted before client requests anything. It means that calling the connect() system call will try to establish a TCP connection (will send SYN) but since the server at the expected port is not present at the destination, a host unreachable - port unreachable error will be returned by the ICMP.

5 votes
Everything is black.

if you will remember this proverb you will easily understand how a connection can be established in a TCP connection.

S B L A C

S STANDS FOR SOCKET.

B STANDS FOR BIND.

L STANDS FOR LISTEN.

A STANDS FOR ACKNOWLEDGE

C STANDS FOR CONNECT

Connection is always made via this series of steps.

now as you can see in the question it is given that the client process p executes a socket system call followed by directly connect now everyone knows that connect system call require bind and listen which has not occurred so this will return an error that's why this will return an error.
Answer:

Related questions