home *** CD-ROM | disk | FTP | other *** search
- Organization: Sponsored account, Chemical Engineering, Carnegie Mellon, Pittsburgh, PA
- 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+
- Newsgroups: comp.protocols.tcp-ip
- Message-ID: <kfISQ0600YUn0aa2Uz@andrew.cmu.edu>
- Date: Mon, 11 Jan 1993 16:30:40 -0500
- From: Tod McQuillin <tm8t+@andrew.cmu.edu>
- Subject: Re: call routine when packet arrives?
- In-Reply-To: <4fIN9KG00iV3M1hYsF@andrew.cmu.edu>
- References: <4fIN9KG00iV3M1hYsF@andrew.cmu.edu>
- Lines: 29
-
- "Alex R.N. Wetmore" <aw2t+@andrew.cmu.edu> writes:
- > I was wondering if there is any way to have standard bsd sockets
- > automatically call a routine when a packet arrives (sort of like what
- > signal() does for signals). Basically, I have a program that isn't
- > event driven, but I would like for it to be able to get interrupted when
- > certain packets arrive (it is for a bbs, and I need to use it for system
- > messages, talk pages, etc). I used to implement them using signals, but
- > since I am moving to a client/server model, and the client can be on a
- > different machine, I can't use signals anymore.
-
- Sure. Use asynchronous I/O. You'll want to use
-
- int yes=1;
- fcntl(s, F_SETFL, FASYNC);
-
- Then enable a signal handler for SIGIO.
-
- signal(SIGIO, handler);
-
- > Otherwise, I could implement the packet waiting routine in where the
- > program waits for keystrokes, but I don't see a way of doing that
- > without polling (which means high cpu usage).
-
- You could do it this way too. Use the select(2) system call instead
- of polling.
-
- Both these techniqies are well explained in Richard Stevens' book,
- "Unix Network Programming," which I highly recommend.
-
-