LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] tough programming q's (was: Re: [ILUG] Re: off-topic.....)

[ILUG] tough programming q's (was: Re: [ILUG] Re: off-topic.....)

Justin Mason jm at netnoteinc.com
Tue Apr 20 11:36:17 IST 1999


kevin lyda said:
> Harry Moreau burst across the net:
> >On Mon, 19 Apr 1999, kevin lyda wrote:
> >select() is probably your only option.  Using signals is indeed a bad
> >idea, because you can't control the exact point at which your read()
> >gets interrupted by the timeout.
> 
> that's what i'm thinking.  but there are performance issues to consider.
> 
> >>also, i'm looking for this for efficiency reasons.  if i did it
> >>with a select and then a read it will involve more data copying
> >>under linux, yes?  
> >I don't think so.  select() doesn't actually read data.
> 
> exactly, that's why there's more data copying.  if data is coming in to
> a nic, and the driver is notified that a process is waiting to read data
> (with a memory location), then the data can go straight from the card
> to the memory location (via dma if supported).  otherwise the data gets
> copied into buffers in the driver, and then again into userspace.
> 
> supposedly nt is capable of this.  true?  also, does any other unix
> system do this?

QNX I think, and recent versions of Solaris -- it's called zero-copy read
or zero-copy write. I think I saw a kernel mod for Linux ages ago that did
this. I can't remember seeing anything about NT doing it though!

Most OS'es do not support this AFAIK, and when they do it's going to be
unportable -- so you'd need to write a wrapper layer.

> >select() is available on most modern UNIX systems.  However,
> >you may find slight differences in implementation, especially in error
> >conditions.  Read the man pages carefully.
> 
> ACE can mask this, but select has a (supposed) penalty under nt.
> theoretically there would also be a loss of performance under linux if
> linux can xfer straight from nic to userspace.

Why not take a look at the ACE source!

btw select() etc. has enough problems on NT that you should consider
writing a pair of NonBlockingRead/NonBlockingWrite wrapper functions,
which you can implement differently on NT and UNIX, using select() only on
UNIX.

I think some UNIXes provide nbread()/nbwrite() functions, or similar, to
support non-blocking IO. However this is definitely unportable.  If you
ALWAYS will be reading this socket without ever wanting to block, use
non-blocking IO with fcntl(fd, F_SETFL, O_NONBLOCK). I think that is
reasonably portable across UNIXes.

However for portability and reliability I would ALWAYS recommend using
select() and read() for UNIX platforms -- they're always going to work,
and not going to get you with crap like non-building code or requiring
patches on blah platform, etc.

--j.





More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell