home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / protocol / tcpip / 5926 < prev    next >
Encoding:
Text File  |  1993-01-11  |  1.7 KB  |  41 lines

  1. Organization: Sponsored account, Chemical Engineering, Carnegie Mellon, Pittsburgh, PA
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!news.sei.cmu.edu!fs7.ece.cmu.edu!crabapple.srv.cs.cmu.edu!andrew.cmu.edu!tm8t+
  3. Newsgroups: comp.protocols.tcp-ip
  4. Message-ID: <kfISQ0600YUn0aa2Uz@andrew.cmu.edu>
  5. Date: Mon, 11 Jan 1993 16:30:40 -0500 
  6. From: Tod McQuillin <tm8t+@andrew.cmu.edu>
  7. Subject: Re: call routine when packet arrives?
  8. In-Reply-To: <4fIN9KG00iV3M1hYsF@andrew.cmu.edu>
  9. References: <4fIN9KG00iV3M1hYsF@andrew.cmu.edu>
  10. Lines: 29
  11.  
  12. "Alex R.N. Wetmore" <aw2t+@andrew.cmu.edu> writes:
  13. > I was wondering if there is any way to have standard bsd sockets
  14. > automatically call a routine when a packet arrives (sort of like what
  15. > signal() does for signals).  Basically, I have a program that isn't
  16. > event driven, but I would like for it to be able to get interrupted when
  17. > certain packets arrive (it is for a bbs, and I need to use it for system
  18. > messages, talk pages, etc).  I used to implement them using signals, but
  19. > since I am moving to a client/server model, and the client can be on a
  20. > different machine, I can't use signals anymore.
  21.  
  22. Sure.  Use asynchronous I/O.  You'll want to use
  23.  
  24.     int yes=1;
  25.     fcntl(s, F_SETFL, FASYNC);
  26.  
  27. Then enable a signal handler for SIGIO.
  28.  
  29.     signal(SIGIO, handler);
  30.  
  31. > Otherwise, I could implement the packet waiting routine in where the
  32. > program waits for keystrokes, but I don't see a way of doing that
  33. > without polling (which means high cpu usage).
  34.  
  35. You could do it this way too.  Use the select(2) system call instead
  36. of polling.
  37.  
  38. Both these techniqies are well explained in Richard Stevens' book,
  39. "Unix Network Programming," which I highly recommend.
  40.  
  41.