Results 1 to 8 of 8
in a client server communication where both client and server are receiving
and sendng msgs .Suppose when the client is sending to the server that time it checkpointed (client) and ...
- 01-10-2012 #1Just Joined!
- Join Date
- Dec 2011
- Posts
- 29
client server communication
in a client server communication where both client and server are receiving
and sendng msgs .Suppose when the client is sending to the server that time it checkpointed (client) and the client is killed.
So what will happen to the connection??
is it that the after killing the client the fd for the socket is removed from the file descriptor table (similar to the case when close() system call is called which flushes the fd from the fdtable when the connection is supposed to be closed ) or the fd is marked as usless ..
When I restart the client what is the reason for getting error EBADF
Is this error because the fd for the socket is flushed off from the fd table when the client was checkpointed?????
If possible can any one please pass on a link which explains the source code for sockets in linux with every socket primitive expalined in detail.
Plzzzzzzzzzzzzz help me out ......
- 01-11-2012 #2Just Joined!
- Join Date
- Nov 2009
- Posts
- 53
Good Morning Innovator.
Many questions. First off, let's look at when the Client is terminated.
The FD table is a process-based structure so when the Client is killed, its FD Table also dies. If a new instance of the Client is run, a new FD Table is created for the process. There is no relationship between the "first" Client's FD Table and the "second" Client's FD Table.
EBADF indicates that you are trying to perform an operation on an FD (File Descriptor) that is invalid. Is the "file" in question open?
We would need to see your code etc in order to debug this some more.
HTH.
Regards - VP
- 01-11-2012 #3Just Joined!
- Join Date
- Aug 2008
- Posts
- 2
Hi innovator,
I agree with voidpointer69. Moreover, can you re-execute your client program after waiting for few minutes (say 2 or 3) and check the result?? Sometimes resources may not be released immediately by OS.
Regards,
- 01-13-2012 #4Just Joined!
- Join Date
- Dec 2011
- Posts
- 29
First of all thank you very much for your help...
Your rply has answered my questions..
But now I want to Know how to check the open file descriptors of a process.I mean when the server and the client communicate through the file where to which the socket is bind
like in my example it is /home/echo_socket.
when i do lsof command (command to dispay open file descriptor for a process) for client process --
i get that the FD for echo_socket is 3u
for server i get 4u
but as far as I know FD is an integer
Actually i am dealing with checkpoint restart mechanism in BLCR
and I want to know that when a client is checkpointed is its fd saved by blcr.... So, i am trying to find the Fd for echo_socket file for client and server using "lsof"command . But i am not exactly gettting it .
Can u please help me out..
- 01-13-2012 #5Just Joined!
- Join Date
- Nov 2009
- Posts
- 53
Hello,
Well, my knowledge of blcr in particular is not great but my understanding is that when it takes a checkpoint of a process, the checkpoint will contain everything that will be needed to restart the process at the point it was checkpointed. This would, of course, include the current FD Table.
As far as knowing which FD your program is using for for the "echo" socket, I assume you have something like FD EchoSocket = socket(.....
If you want to know what number it is the following is a bit clunky but might get what you want. If you run the program as a non-daemon, you will have already open FD 0, 1 and 2 being STDIN, STDOUT and STDERR.
If you are running as daemon, you will have shut those down soon after you started.
getdtablesize() will give you the maximum number of file descriptors. You could then issue fcntl() on each one (from 0 to togetdtablesize()) try to get some info or something. Any that return EBADF are not being used by your program so maybe the previous "good" one is your socket FD.
ls /proc/xxxx/fd | wc -l where "xxxx" is your PID will give how many FD are in use.
Re 3u and 4u I have no clue! You are right, FD is an integer - an index into the FD Table in fact.
/home/echo_socket - you using DOMAIN sockets here right?
When you establish the client to server connection, what you are actually using are two completely different channels from the one that you "connect()" to. That is, the server side accept() your inbound connection request and spawns off two more channels. One for the inbound traffic from the client and one for outbound from the server.
If you run netstat -a | egrep unix |more (assuming you are using DOMAIN sockets) that will list for you all the current connections on the box. Filter that by your echo_socket and you will see how many progs are connected to your server.
You might want to filter your lsof with unix also to just trap the DOMAIN sockets.
Cheers - VP
- 01-15-2012 #6Just Joined!
- Join Date
- Dec 2011
- Posts
- 29
fcntl function
According to your suggestion i using fcntl function to check the socket fd in use by the client process
I am using fcntl function in cr_dump_self.c file of blcr .This file is basically responsible for saving the fd and other related information of a checkpointed process.
But while using fcnt When i do make (since blcr is a kernel module to update the changes we need to "make" it)
I get the error : implicit declaration of fcntl()
I have also included the header file fcntl.h in cr_dump_self.c file of blcr
then too i am geting this error
To avoid this error is it that I will need to make changes in the Makefile of blcr???
If so, then how can I do that??
please help me
Also Sir,
when I deed strace of server and client process
that time server returned the fd as 3 (through socket function call)
but when the accept function is executed and the client connects to the server (client get the fd as 3)
that time accept function returns another fd (here it is 4) and then the server communicate with the client with fd as 4 and the
client communicates with the server with fd 3
what are this 2 connection
I remember that u had send that server has 2 connection for inbound and outbound traffic.
But I am not able to understand it .
Can u please explain how the accept function works and how this fds are assign??Last edited by Innovator; 01-16-2012 at 02:05 AM.
- 01-16-2012 #7Just Joined!
- Join Date
- Nov 2009
- Posts
- 53
Hi Innovator
"implicit declaration" errors are always because you are issuing the call to fcntl() before you have declared the prototype. Make sure that you are including fcntl.h et al in the same scope as you are calling fcntl(). See man fcntl.
As to the FD values you are reporting, they look spot on to me. The FD is an index into a series of data structures that the runtime uses to interface you to various data streams. That is, files sockets etc. The underlying runtime will use the first available one for all new streams.
Neither your server nor your client are running as daemon so they both have stdin, stdout and stderr open and these are assigned to FD = 0, 1 and 2 respectively.
When your server opens its server socket, ServerSock = socket(...). ServerSock will be attached to FD = 3.
Same on the clients side, ClientSock = socket(....). ClientSock will be assigned to FD = 3.
You then issue a connect() request on the client side which is received and accepted (accept()) on the server side. When your server does ClientConnection = accept(ServerSock,....). ClientConnection is assigned FD = 4 because that's the next one available.
Re the two channels, input and output. Yeps, they are referred to a queues and are part of the underlying data structure used by the runtime to manage the stream endpoints and accessed by you via the FD. Well, to be strict, you tell the underlying what endpoint to act upon by including the FD in whatever function call you use.
Take a look at the column headings when you issue netstat -a | more. You should see "Recv-Q Send-Q" or similar.
If both ends are doing their thing, the values of these columns will probably be zero. If one or both ends are blocking or falling behind, the values you see are the number of bytes waiting to be sent to the remote connection (Send-Q) or read by the local connection (Recv-Q).
Cheers - VP
- 01-16-2012 #8Just Joined!
- Join Date
- Nov 2009
- Posts
- 53
Innovator,
Just read my prev post.
Important to understand that when a server accepts the client connection, it does so by creating a new endpoint for it. Hence the new FD. If it did not do this, then a server could only ever accept and process one client at a time.
After the accept(), the server socket becomes available for new connections via the listen().
I assume your server handles > 1 client at a time and you are doing this using a "thread per connection" or asynchronous (select/poll) I/O model.
Cheers - VP


Reply With Quote
