<!-- MHonArc v2.4.4 --> <!--X-Subject: Re: [MUD-Dev] Sockets --> <!--X-From-R13: Oyrk Egrjneg <evpurNpey.pbz> --> <!--X-Date: Wed, 21 Apr 1999 22:37:54 -0700 --> <!--X-Message-Id: 199904211946.AA09291#crl5,crl.com --> <!--X-Content-Type: text/plain --> <!--X-Reference: 000901be8be5$4d9785a0$11cb9cd1@k6 --> <!--X-Head-End--> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <html> <head> <title>MUD-Dev message, Re: [MUD-Dev] Sockets</title> <!-- meta name="robots" content="noindex,nofollow" --> <link rev="made" href="mailto:riche#crl,com"> </head> <body background="/backgrounds/paperback.gif" bgcolor="#ffffff" text="#000000" link="#0000FF" alink="#FF0000" vlink="#006000"> <font size="+4" color="#804040"> <strong><em>MUD-Dev<br>mailing list archive</em></strong> </font> <br> [ <a href="../">Other Periods</a> | <a href="../../">Other mailing lists</a> | <a href="/search.php3">Search</a> ] <br clear=all><hr> <!--X-Body-Begin--> <!--X-User-Header--> <!--X-User-Header-End--> <!--X-TopPNI--> Date: [ <a href="msg00097.html">Previous</a> | <a href="msg00099.html">Next</a> ] Thread: [ <a href="msg00094.html">Previous</a> | <a href="msg00100.html">Next</a> ] Index: [ <A HREF="author.html#00098">Author</A> | <A HREF="#00098">Date</A> | <A HREF="thread.html#00098">Thread</A> ] <!--X-TopPNI-End--> <!--X-MsgBody--> <!--X-Subject-Header-Begin--> <H1>Re: [MUD-Dev] Sockets</H1> <HR> <!--X-Subject-Header-End--> <!--X-Head-of-Message--> <UL> <LI><em>To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI> <LI><em>Subject</em>: Re: [MUD-Dev] Sockets</LI> <LI><em>From</em>: Alex Stewart <<A HREF="mailto:riche#crl,com">riche#crl,com</A>></LI> <LI><em>Date</em>: Wed, 21 Apr 1999 12:46:25 -0700 (PDT)</LI> <LI><em>Reply-To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI> <LI><em>Sender</em>: <A HREF="mailto:mud-dev-admin#kanga,nu">mud-dev-admin#kanga,nu</A></LI> </UL> <!--X-Head-of-Message-End--> <!--X-Head-Body-Sep-Begin--> <HR> <!--X-Head-Body-Sep-End--> <!--X-Body-of-Message--> <PRE> "Quzah [softhome]" <quzah#softhome,net> wrote: > What is the main difference between and benifit of using: > > (1) asynchronous notification > <versus> > (2) versus non-blocking > <versus> > (3) using select Technically, there are two different issues here, and you'll probably need some combination of the above options. First, some definitions: Blocking: (you didn't mention this in your list, but it's the most basic starting point for socket programming, so it should be discussed. It sounds like this is where you are currently with your program) When you write to a socket, it sends the data out. If there isn't enough buffer space in the output buffer for everything you feed it, it will send out as much as it can, wait for more space, send out more, etc, and not return until it's written everything. When you read from a socket, it returns any data which has come in. If there's no data in the input buffer, it will wait until there is some and then return that. This has some obvious drawbacks for handling multiple sockets in the same application. When you're reading/writing with one, your entire application is tied up until the operation completes on that socket. Non-Blocking: When a socket is set non-blocking, if you write to it and there isn't enough buffer space for all of the data you are writing, it writes as much as it can and returns the amount written. You can then try again to write the rest of it at a later time. When you read from a non-blocking socket, if data is available in the input buffer, it is returned. If no data is currently available, the call returns without any data. In this way, socket IO never suspends program execution any longer than absolutely necessary, but it does mean you need to do a bit more housekeeping on your end (knowing when to try writes again, making sure you pick up data in a timely manner when it comes in, etc). This is where notification methods come in: Repeated polling: This is the most obvious way to check for events on sockets. Just repeatedly loop through them and check to see if any are ready to do anything you want to do. While there are a few (very unusual) circumstances where this may actually be useful, in general this is a Bad Thing(tm), as it means even when your program is completely idle, it'll be using up huge amounts of procesing time just doing nothing. There are better ways. Asyncrhonous notification: This is essentially "interrupt driven" network handling. When a socket has data (or is available for writing more data out), the system notifies the application (typically via a signal or a pipe), at which point the application services the socket and then continues on with whatever it was doing when it was interrupted. The main problems with this are that as far as I know, nobody's come up with a very good implementation of this for unix (certainly not a portable one), and that this method (despite its somewhat cleaner conceptual model) doesn't really gain anything over other already well-accepted methods. In any case if you're starting out it's probably better to go with one of the more common methods which already have a lot more documentation and examples available. Select/poll: This is the most common way to deal with network events, and is probably what you want to use. This method involves setting up a structure indicating what sockets (or other file descriptors) you're interested in and what types of events (ready-for-write, data-available-for-read, etc) you're interested in for each socket. You then pass this information to the select() or poll() system call, which sleeps until something happens (or a timeout you specify expires). When one of the events you're waiting on occurs, it returns with an indication of what's happened to which sockets. Based on this information, you can then do whatever operations are appropriate, and then return to select() or poll() again to wait for the next event. In case you're wondering, select() is the BSD version and poll() is the SysV/POSIX version of more or less the same sort of thing. They use different types of structures and semantics for some things, but when it comes right down to it the difference between their functionality is basically trivial (particularly since in most modern OSes, the select() call is actually a wrapper around poll() anyway). Since poll() is now the standard for, you might want to become familiar with it, but on the other hand, select() has a lot more in the way of examples floating around to play with, so it's up to you. Anyway, so what you're probably looking for is using a combination of non-blocking sockets with select() or poll().. -alex ------------------------------------------------------------------------------- Alex Stewart - riche#crl,com - Richelieu @ Diversity University MOO <A HREF="http://www.crl.com/~riche">http://www.crl.com/~riche</A> "For the world is hollow, and I have touched the sky." _______________________________________________ MUD-Dev maillist - MUD-Dev#kanga,nu <A HREF="http://www.kanga.nu/lists/listinfo/mud-dev">http://www.kanga.nu/lists/listinfo/mud-dev</A> </PRE> <!--X-Body-of-Message-End--> <!--X-MsgBody-End--> <!--X-Follow-Ups--> <HR> <ul compact><li><strong>Follow-Ups</strong>: <ul> <li><strong><A NAME="00100" HREF="msg00100.html">Re: [MUD-Dev] Sockets</A></strong> <ul compact><li><em>From:</em> "Quzah [softhome]" <quzah#softhome,net></li></ul> </UL></LI></UL> <!--X-Follow-Ups-End--> <!--X-References--> <UL><LI><STRONG>References</STRONG>: <UL> <LI><STRONG><A NAME="00094" HREF="msg00094.html">[MUD-Dev] Sockets</A></STRONG> <UL><LI><EM>From:</EM> "Quzah [softhome]" <quzah#softhome,net></LI></UL></LI> </UL></LI></UL> <!--X-References-End--> <!--X-BotPNI--> <UL> <LI>Prev by Date: <STRONG><A HREF="msg00097.html">Re: [MUD-Dev] Virtual machine design</A></STRONG> </LI> <LI>Next by Date: <STRONG><A HREF="msg00099.html">Re: [MUD-Dev] Sockets</A></STRONG> </LI> <LI>Prev by thread: <STRONG><A HREF="msg00094.html">[MUD-Dev] Sockets</A></STRONG> </LI> <LI>Next by thread: <STRONG><A HREF="msg00100.html">Re: [MUD-Dev] Sockets</A></STRONG> </LI> <LI>Index(es): <UL> <LI><A HREF="index.html#00098"><STRONG>Date</STRONG></A></LI> <LI><A HREF="thread.html#00098"><STRONG>Thread</STRONG></A></LI> </UL> </LI> </UL> <!--X-BotPNI-End--> <!--X-User-Footer--> <!--X-User-Footer-End--> <ul><li>Thread context: <BLOCKQUOTE><UL> <LI><STRONG>[MUD-Dev] Monthly FAQ Posting</STRONG>, <EM>(continued)</EM> <ul compact> <LI><strong><A NAME="00796" HREF="msg00796.html">[MUD-Dev] Monthly FAQ Posting</A></strong>, Ling <a href="mailto:K.L.Lo-94#student,lboro.ac.uk">K.L.Lo-94#student,lboro.ac.uk</a>, Sun 13 Jun 1999, 17:38 GMT </LI> <LI><strong><A NAME="00897" HREF="msg00897.html">[MUD-Dev] Monthly FAQ Posting</A></strong>, Ling <a href="mailto:K.L.Lo-94#student,lboro.ac.uk">K.L.Lo-94#student,lboro.ac.uk</a>, Wed 14 Jul 1999, 02:31 GMT </LI> </ul> </LI> <LI><strong><A NAME="00101" HREF="msg00101.html">[MUD-Dev] ScryMUD 1.8.13 snapshot released.</A></strong>, Ben Greear <a href="mailto:greear#cyberhighway,net">greear#cyberhighway,net</a>, Tue 27 Apr 1999, 21:14 GMT <LI><strong><A NAME="00094" HREF="msg00094.html">[MUD-Dev] Sockets</A></strong>, Quzah [softhome] <a href="mailto:quzah#softhome,net">quzah#softhome,net</a>, Wed 21 Apr 1999, 05:29 GMT <UL> <LI><strong><A NAME="00098" HREF="msg00098.html">Re: [MUD-Dev] Sockets</A></strong>, Alex Stewart <a href="mailto:riche#crl,com">riche#crl,com</a>, Thu 22 Apr 1999, 05:37 GMT <UL> <LI><strong><A NAME="00100" HREF="msg00100.html">Re: [MUD-Dev] Sockets</A></strong>, Quzah [softhome] <a href="mailto:quzah#softhome,net">quzah#softhome,net</a>, Fri 23 Apr 1999, 07:14 GMT </LI> </UL> </LI> <LI><strong><A NAME="00099" HREF="msg00099.html">Re: [MUD-Dev] Sockets</A></strong>, Jo Dillon <a href="mailto:emily#thelonious,new.ox.ac.uk">emily#thelonious,new.ox.ac.uk</a>, Fri 23 Apr 1999, 07:06 GMT <UL> <LI><strong><A NAME="00131" HREF="msg00131.html">Re: [MUD-Dev] Sockets</A></strong>, Jon A. Lambert <a href="mailto:jlsysinc#ix,netcom.com">jlsysinc#ix,netcom.com</a>, Tue 04 May 1999, 05:47 GMT </LI> </UL> </LI> </UL> <UL> <li><Possible follow-up(s)><br> <LI><strong><A NAME="00164" HREF="msg00164.html">RE: [MUD-Dev] Sockets</A></strong>, Jon A. Lambert <a href="mailto:jlsysinc#ix,netcom.com">jlsysinc#ix,netcom.com</a>, Thu 06 May 1999, 15:24 GMT </LI> </UL> </LI> </UL></BLOCKQUOTE> </ul> <hr> <center> [ <a href="../">Other Periods</a> | <a href="../../">Other mailing lists</a> | <a href="/search.php3">Search</a> ] </center> <hr> </body> </html>