Networking Forums

Networking Forums > Computer Networking > Linux Networking > sharing sockets

Reply
Thread Tools Display Modes

sharing sockets

 
 
v
Guest
Posts: n/a

 
      04-23-2005, 05:02 AM
I read that
1. It is possible for two processes to share/own the same socket
2. For one process to handover a socket it owns to other process.

Is this really possible, if so how ?

For 1. I can think of forked processes sharing sockets created before
forking, Is there some other way to do this ? I cannot think of anyway
of doing 2.

thanks,
v

 
Reply With Quote
 
 
 
 
Loic Domaigne
Guest
Posts: n/a

 
      04-23-2005, 02:48 PM
Hi!

> I read that
> 1. It is possible for two processes to share/own the same socket


Correct.

> 2. For one process to handover a socket it owns to other process.
>
> Is this really possible, if so how ?


Yes it is. In fact, you might even pass any descriptor (which might
refer to a file, a pipe, a FIFO, a socket...) between processes.

The technic is described in Stevens, Unix Network Programming, Vol 1,
2nd ed, §14.7 (pp381-389)

If you want, we might give you an example how to do this.


> For 1. I can think of forked processes sharing sockets created before
> forking, Is there some other way to do this ?


On linux, yes. You might created a process using clone() with the flag
CLONE_FILES. Doing so, parent and child share the same descriptors, and
operation on a descriptor is visible in both processes. That is if you
close a descriptor in the child, it will be also closed in the parent
(this differs from a forked child: in a forked child, the descriptor
would be only closed in the child).


Cheers,
Loic.
 
Reply With Quote
 
Rick Ingham
Guest
Posts: n/a

 
      04-23-2005, 07:53 PM
Loic Domaigne wrote:
> Hi!
>
>> I read that
>> 1. It is possible for two processes to share/own the same socket

>
>
> Correct.
>
>> 2. For one process to handover a socket it owns to other process.
>>
>> Is this really possible, if so how ?

>
>
> Yes it is. In fact, you might even pass any descriptor (which might
> refer to a file, a pipe, a FIFO, a socket...) between processes.
>
> The technic is described in Stevens, Unix Network Programming, Vol 1,
> 2nd ed, §14.7 (pp381-389)
>
> If you want, we might give you an example how to do this.
>
>
>> For 1. I can think of forked processes sharing sockets created before
>> forking, Is there some other way to do this ?

>
>
> On linux, yes. You might created a process using clone() with the flag
> CLONE_FILES. Doing so, parent and child share the same descriptors, and
> operation on a descriptor is visible in both processes. That is if you
> close a descriptor in the child, it will be also closed in the parent
> (this differs from a forked child: in a forked child, the descriptor
> would be only closed in the child).
>
>
> Cheers,
> Loic.


What functions calls are used to pass a file descriptor to another
process without fork()'ing or clone()'ing the process?
 
Reply With Quote
 
v
Guest
Posts: n/a

 
      04-23-2005, 09:12 PM
You send it via a Unix domain socket(AF_UNIX) and sendmsg() call. There
are specific things you need to set in struct msghdr. The stevens book
contains sample code
thanks,
V

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Max TCP sockets CJS Windows Networking 1 02-28-2007 07:20 PM
RAW TCP/IP sockets George Valkov Windows Networking 1 09-22-2006 03:49 AM
sockets Sam Linux Networking 2 07-07-2004 09:54 AM
UDP sockets Sven Jacobs Linux Networking 0 05-10-2004 07:06 AM
Sockets Anthony T. Wilson Linux Networking 1 12-25-2003 08:45 PM



1 2 3 4 5 6 7 8 9 10 11