EventLibray.html 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
  2. <html>
  3. <head>
  4. <link type="text/css" rel="stylesheet" href="style.css" />
  5. </head>
  6. <body>
  7. <div id="page">
  8. <div id='header'>
  9. <a href="index.html">
  10. <img style="border:none" alt="Redis Documentation" src="redis.png">
  11. </a>
  12. </div>
  13. <div id="pagecontent">
  14. <div class="index">
  15. <!-- This is a (PRE) block. Make sure it's left aligned or your toc title will be off. -->
  16. <b>EventLibray: Contents</b><br>&nbsp;&nbsp;<a href="#Event Library">Event Library</a><br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="#Why is an Event Library needed at all?">Why is an Event Library needed at all?</a>
  17. </div>
  18. <h1 class="wikiname">EventLibray</h1>
  19. <div class="summary">
  20. </div>
  21. <div class="narrow">
  22. <h1><a name="Event Library">Event Library</a></h1><h2><a name="Why is an Event Library needed at all?">Why is an Event Library needed at all?</a></h2>Let us figure it out through a series of Q&amp;As.<br/><br/>Q: What do you expect a network server to be doing all the time? &lt;br/&gt;
  23. A: Watch for inbound connections on the port its listening and accept them.<br/><br/>Q: Calling <a href="http://man.cx/accept%282%29" target="_blank">accept</a> yields a descriptor. What do I do with it?&lt;br/&gt;
  24. A: Save the descriptor and do a non-blocking read/write operation on it.<br/><br/>Q: Why does the read/write have to be non-blocking?&lt;br/&gt;
  25. A: If the file operation ( even a socket in Unix is a file ) is blocking how could the server for example accept other connection requests when its blocked in a file I/O operation.<br/><br/>Q: I guess I have to do many such non-blocking operations on the socket to see when it's ready. Am I right?&lt;br/&gt;
  26. A: Yes. That is what an event library does for you. Now you get it.<br/><br/>Q: How do Event Libraries do what they do?&lt;br/&gt;
  27. A: They use the operating system's <a href="http://www.devshed.com/c/a/BrainDump/Linux-Files-and-the-Event-Poll-Interface/" target="_blank">polling</a> facility along with timers.<br/><br/>Q: So are there any open source event libraries that do what you just described? &lt;br/&gt;
  28. A: Yes. Libevent and Libev are two such event libraries that I can recall off the top of my head.<br/><br/>Q: Does Redis use such open source event libraries for handling socket I/O?&lt;br/&gt;
  29. A: No. For various <a href="http://groups.google.com/group/redis-db/browse_thread/thread/b52814e9ef15b8d0/" target="_blank">reasons</a> Redis uses its own event library.
  30. </div>
  31. </div>
  32. </div>
  33. </body>
  34. </html>