🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #539

Re: Serial Port Question...

#539
From: Chris Lloyd
Date: Tue, 11 Aug 1992 22:50
35 lines
2244 bytes
In article <1992Aug11.154515.14514@svcdudes.com> moose@svcdudes.com writes:
>In article <1992Aug10.193155.14621@usenet.ins.cwru.edu>  
>aj681@cleveland.Freenet.Edu (Carlin Wiegner) writes:
>> 
>> Can multiple applications montior and read/write to the same
>> serial or ethernet port?
>
>Sure, for about 3 seconds.  DPSAddFD, which is glue for select(), does not
>like having stuff on the serial port stolen from it between spotting it and
>getting  your program to read it.  There are workarounds, but it will usually
>cause your program to hang.  

Ah, don't be such a pessimist :)  The devices are perfectly happy to have
any number of readers and writers, if the programs doing the reading and 
writing are aware (the programmer was aware) that other programs will be
reading or writing then there is no big deal, you just have to do your IO
correctly.

select() (which DPSAddFD() uses) is just an indicator that says "Ok, there
is something here", if your program hangs, it's in the handlers read().
writing is somewhat of a non-issue in most cases.

The best way to do this is to set the serial port to non-blocking IO
with { int i=1; ioctl(fd,FIONBIO,&i); }, in concert with select()/DPSAddFD(),
you will be notified of incoming data, then when your handler is called,
you check for errno being EWOULDBLOCK on error'ed read()'s and chalk them
up to someone else reading the data (ignore it). Otherwise processing
as usual...

There are a slew of ways to do this without hanging your program, if the
above doesn't suit the needs, I'd be happy to suggest several more.

la la la,
-- 
:: Christopher Lloyd :: a74k110@titan.ucc.umass.edu :: Yrrid, Inc. ::
Technical Details
Message-ID: <1992Aug11.225001.2618@nic.umass.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!caen!nic.umass.edu!titan.ucc.umass.edu!a74k110
References: <1992Aug10.193155.14621@usenet.ins.cwru.edu> <1992Aug11.154515.14514@svcdudes.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!caen!nic.umass.edu!titan.ucc.umass.edu!a74k110
From: a74k110@titan.ucc.umass.edu (Chris Lloyd)
Subject: Re: Serial Port Question...
Message-ID: <1992Aug11.225001.2618@nic.umass.edu>
Sender: usenet@nic.umass.edu (USENET News System)
Nntp-Posting-Host: titan.ucc.umass.edu
Organization: University of Massachusetts, Amherst
References: <1992Aug10.193155.14621@usenet.ins.cwru.edu> <1992Aug11.154515.14514@svcdudes.com>
Distribution: na
Date: Tue, 11 Aug 1992 22:50:01 GMT
Lines: 35