home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / programm / 6073 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  2.4 KB

  1. Path: sparky!uunet!ukma!asuvax!ncar!vexcel!copper!slate!mbarkah
  2. From: mbarkah@slate.mines.colorado.edu (Ade Barkah)
  3. Newsgroups: comp.unix.programmer
  4. Subject: Re: client/server question.....
  5. Message-ID: <1993Jan28.195545.30826@slate.mines.colorado.edu>
  6. Date: 28 Jan 93 19:55:45 GMT
  7. References: <1993Jan27.223124.22279@aosg.gsf.dec.com>
  8. Organization: Colorado School of Mines
  9. Lines: 48
  10.  
  11. Well, I don't know what the setup will look like (are you using
  12. sockets or STREAMS or non-of-the-above, will the clients be on
  13. the same machine, etc.) But, looking at the previous responses:
  14.  
  15. 1) Making the temp file might be dangerous, especially from the
  16.     original diagram it looks like there will be multiple main-
  17.    clients updating the file. Unless you adopt a locking protocol,
  18.    if two or more clients tries to update the file simultaneously,
  19.    the result could be disastrous.
  20.  
  21. 2) Same deal with threading, since it doesn't resolve simultaneous
  22.    writes between different threads. On the side note, can someone
  23.    email me about Unix threads ? I thought they didn't exists in
  24.    most Unixes. I know Solaris has them.
  25.  
  26. I guess there are really two problems here: a) communication between
  27. the clients and the server. b) interference between these when
  28. writing the datafile.
  29.  
  30. If the main clients (the ones which will write) will reside in the
  31. same machine as the server, then problem a) and perhaps b) is 
  32. easy to solve.
  33.  
  34. For each main-clients, you can simply create named-pipes. One end
  35. of each pipe connects to the client, the other connects to the
  36. server. The server can poll the pipes periodically, you might be
  37. able to use select() or poll() to do this efficiently.
  38.  
  39. But the server hangs when it tries to read the empty pipe. No
  40. problem. In unix, you can specify streams to be blocking when
  41. there is nothing to be read (default), or you can change the
  42. mode to non-blocking or no-delay. If you use the open() function
  43. call, then you can `open("named-pipe",PERMISSION|O_NONBLOCK)' or
  44. O_NDELAY as the case might be.
  45.  
  46. If you don't use open to set non-block/no-delay, then you can
  47. still use the fcntl() function call. I think the form is
  48. fcntl (fildes, F_SETFL, O_NONBLOCK) (or O_NDELAY).
  49.  
  50. It should be the server's responsibility to actually do the writing
  51. to the file. In that way, only one process performs writing, and
  52. thus you have resolved the concurrent interference problem.
  53.  
  54.  
  55. -Ade
  56. -- 
  57. Internet  : mbarkah@slate.mines.colorado.edu    (NeXT Mailable)
  58. CompuServe: 74160,3404
  59.