home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / wizards / 3889 < prev    next >
Encoding:
Text File  |  1992-09-11  |  2.4 KB  |  61 lines

  1. Newsgroups: comp.unix.wizards
  2. 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
  3. From: hawkeye@glia.biostr.washington.edu (Ken Keys - TF Dude)
  4. Subject: Re: Stevens Book/ Passing File descriptors 
  5. Message-ID: <hawkeye.716222722@glia>
  6. Sender: news@u.washington.edu (USENET News System)
  7. Organization: University of Washington
  8. References: <1992Sep10.161335.26883@panther.mot.com>
  9. Date: Fri, 11 Sep 1992 14:45:22 GMT
  10. Lines: 49
  11.  
  12. In <1992Sep10.161335.26883@panther.mot.com> asu@panther4.panther.mot.com (ASU Student) writes:
  13.  
  14. >I've got a few questions for those who have tried the file descriptor
  15. >passing example in R. Stevens UNIX Network Programming.  I've been having
  16. >problems getting this to work reliably, 
  17. >In his example, he had a structure similar to this:
  18.  
  19. >            struct iovec iov;
  20. >            iov.iov_base = (char *)0; iov.iov_len = 0;
  21. >        
  22. >            int fd;    
  23. >            struct msghdr msg;
  24. >            msg.msg_name = (caddr_t)0; msg.msg_namelen = 0;
  25. >            msg.msg_iov = iov; msg.msg_iovlen = 1;
  26.  
  27. The way you defined iov, that last line should be:
  28.             msg.msg_iov = &iov; msg.msg_iovlen = 1;
  29.  
  30. >            msg.msg_accrights = &fd; msg.msg_accrightslen = sizeof(int); 
  31.  
  32. >Now my first question...is the msg.msg_iov field required to be non-NULL?
  33. >I was trying this:
  34.  
  35. >            msg.msg_iov = (struct iovec *)0; msg.msg_iovlen = 0;
  36.  
  37. It should be non-null.  If you don't need it, just define a dummy
  38. struct iovec, and use a iovlen of 0.
  39.  
  40. >But, it's unclear if this is the problem.   Has anyone tried passing
  41. >file descriptors and gotten it to work reliably?  My system is SunOS 4.1.2. 
  42.  
  43. >BTW, when I mean reliably, I mean that sometimes I get garbage messages
  44. >with invalid descriptors.  But, the sendmsg()/recvmsg() would return no
  45. >error in this case.
  46.  
  47. Remember that open descriptor passing only works for *open* descriptors.
  48. The descriptor is an index into the process' open file table.  So if you 
  49. give an invalid (e.g., closed) descriptor, it will cause a reference to
  50. an invalid portion of that table.  When passing descriptors like this,
  51. I suggest first passing a flag indicating the success or failure of the
  52. opening procedure.  If the flag indicate sucess, the receiving process
  53. should recvmsg() for the fd; otherwise, it should expect some error
  54. indication (errno would be useful) from the sender.
  55.  
  56. -- 
  57. --
  58. Ken Keys, aka Hawkeye
  59. Master of the Fugue
  60. kkeys@ucsd.edu or hawkeye@ucsd.edu
  61.