home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.wizards
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!usc!sdd.hp.com!uakari.primate.wisc.edu!usenet.coe.montana.edu!news.u.washington.edu!glia!hawkeye
- From: hawkeye@glia.biostr.washington.edu (Ken Keys - TF Dude)
- Subject: Re: Stevens Book/ Passing File descriptors
- Message-ID: <hawkeye.716222722@glia>
- Sender: news@u.washington.edu (USENET News System)
- Organization: University of Washington
- References: <1992Sep10.161335.26883@panther.mot.com>
- Date: Fri, 11 Sep 1992 14:45:22 GMT
- Lines: 49
-
- In <1992Sep10.161335.26883@panther.mot.com> asu@panther4.panther.mot.com (ASU Student) writes:
-
- >I've got a few questions for those who have tried the file descriptor
- >passing example in R. Stevens UNIX Network Programming. I've been having
- >problems getting this to work reliably,
- >In his example, he had a structure similar to this:
-
- > struct iovec iov;
- > iov.iov_base = (char *)0; iov.iov_len = 0;
- >
- > int fd;
- > struct msghdr msg;
- > msg.msg_name = (caddr_t)0; msg.msg_namelen = 0;
- > msg.msg_iov = iov; msg.msg_iovlen = 1;
-
- The way you defined iov, that last line should be:
- msg.msg_iov = &iov; msg.msg_iovlen = 1;
-
- > msg.msg_accrights = &fd; msg.msg_accrightslen = sizeof(int);
-
- >Now my first question...is the msg.msg_iov field required to be non-NULL?
- >I was trying this:
-
- > msg.msg_iov = (struct iovec *)0; msg.msg_iovlen = 0;
-
- It should be non-null. If you don't need it, just define a dummy
- struct iovec, and use a iovlen of 0.
-
- >But, it's unclear if this is the problem. Has anyone tried passing
- >file descriptors and gotten it to work reliably? My system is SunOS 4.1.2.
-
- >BTW, when I mean reliably, I mean that sometimes I get garbage messages
- >with invalid descriptors. But, the sendmsg()/recvmsg() would return no
- >error in this case.
-
- Remember that open descriptor passing only works for *open* descriptors.
- The descriptor is an index into the process' open file table. So if you
- give an invalid (e.g., closed) descriptor, it will cause a reference to
- an invalid portion of that table. When passing descriptors like this,
- I suggest first passing a flag indicating the success or failure of the
- opening procedure. If the flag indicate sucess, the receiving process
- should recvmsg() for the fd; otherwise, it should expect some error
- indication (errno would be useful) from the sender.
-
- --
- --
- Ken Keys, aka Hawkeye
- Master of the Fugue
- kkeys@ucsd.edu or hawkeye@ucsd.edu
-