2 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01//EN">
5 <link type=
"text/css" rel=
"stylesheet" href=
"style.css" />
12 <img style=
"border:none" alt=
"Redis Documentation" src=
"redis.png">
16 <div id=
"pagecontent">
18 <!-- This is a (PRE) block. Make sure it's left aligned or your toc title will be off. -->
19 <b>EventLibray: Contents
</b><br> <a href=
"#Event Library">Event Library
</a><br> <a href=
"#Why is an Event Library needed at all?">Why is an Event Library needed at all?
</a>
22 <h1 class=
"wikiname">EventLibray
</h1>
30 <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
&As.
<br/><br/>Q: What do you expect a network server to be doing all the time?
<br/
>
31 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?
<br/
>
32 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?
<br/
>
33 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?
<br/
>
34 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?
<br/
>
35 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?
<br/
>
36 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?
<br/
>
37 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.