Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Keeping an INET socket inside a shared object

by andal (Hermit)
on Jan 20, 2014 at 09:10 UTC ( [id://1071283]=note: print w/replies, xml ) Need Help??


in reply to Keeping an INET socket inside a shared object

I suspect, there's some confusion here. Within "threads" connections can be shared without problem. Well, there are issues with synchronization of access (and that can be very complex) but still, the IO::Socket::INET object is directly accessible. The same is true for forked processes if the fork has happened AFTER connection acceptance/creation.

In all other cases, connection information has to be passed from one process to another. I don't know about Windows, but in Unix this is done via IO::Socket::UNIX socket. As already mentioned, this involves passing of file descriptor only (fileno). Basically, when kernel gets request to pass file descriptor to the peer, it creates for the destination process new file descriptor that would point to kernel structures to which old file descriptor was pointing. The peer process just needs to wrap file descriptor into IO::Socket::INET structure using IO::Socket::INET->new_from_fd($fd, 'r').

Of course, simple writing of information into file and then reading it in another process won't do any good. Remember, it is kernel that takes file descriptor number and maps it to real connection data, and such mapping is process specific. So file descriptor 4 in one process has nothing in common with file descriptor 4 in another process. One has to ask kernel to allow for process X to have file descriptor that would point to the same connection data as in the current process.

  • Comment on Re: Keeping an INET socket inside a shared object

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1071283]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-20 06:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found