• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Asynchronous sockets?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Asynchronous sockets?


  • Subject: Re: Asynchronous sockets?
  • From: Matt Slot <email@hidden>
  • Date: Thu, 7 Feb 2002 12:17:19 -0500

Tomas Zahradnicky, Jr. (email@hidden) wrote:
> I'd like to create asynchronous socket or at least something similar
> to OT notifier function to be notified of incoming data. I know I can
> use select with 0,0 timeout value to poll for data, but I'd really
> like to know when data income to fill them into my buffer to not poll
> every moment for an incoming data. Is there a way how to get notified
> of incoming data just like in OT?

Nobody seems to have mentioned that you *can* set a socket to asynchronous
operation:

signal(SIGIO, my_sigio_handler); /* Enable "pending I/O" signals */
signal(SIGURG, my_sigurg_handler); /* Enable "urgent I/O" signals */
signal(SIGPIPE, my_sigpipe_handler); /* Enable "broken pipe" signals */
fcntl(s, F_SETOWN, getpid());
fcntl(s, F_SETFL, FASYNC);

The problem is that the signal handlers are invoked in the UNIX equivalent
of a "software interrupt", so the operations you can perform are limited
to a handful of system routines, read and write, etc.

In addition, you don't know *which* socket the signal refers to, so you
still have to select() or something to properly dispatch the event. You'll
have to read Stevens to get all the details.

So, async sockets exist, but they are hardly worth the extra work involved,
since preemptive threads or other techniques offer very respectable
performance without the drawbacks.

Matt

/* Matt Slot, Bitwise Operator * <http://www.ambrosiasw.com/~fprefect/> */
/* "I never let schooling interfere with my education." -- Mark Twain */
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: MoreSCF1.0d3 and root privilege
  • Next by Date: Re: Asynchronous sockets?
  • Previous by thread: Re: Asynchronous sockets?
  • Next by thread: Re: Asynchronous sockets?
  • Index(es):
    • Date
    • Thread