<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-10398581</id><updated>2011-12-14T19:12:29.666-08:00</updated><category term='gdb ruby'/><category term='cron test debug'/><category term='xruby'/><title type='text'>X.Y.Z</title><subtitle type='html'>Ruby, XRuby, ANTLR, Security and else</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>71</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-10398581.post-1921999323562320925</id><published>2011-08-11T09:55:00.000-07:00</published><updated>2011-08-11T09:57:33.522-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='gdb ruby'/><title type='text'>Inspect Ruby Process From gdb</title><content type='html'>If you have been developing in Ruby and Ruby on Rails for any length of time, it is very likely that you have encountered a 'Segmentation fault' from Ruby without any information about where the error is coming from.&lt;br /&gt;&lt;br /&gt;Normally, a gem written in C extension is to blame. If pure Ruby code meets an error, a nice stacktrace with a line number will be there to point you in the right direction, but not for code in C extension. You won't find more information about the error unless you fire up gdb.&lt;br /&gt;&lt;br /&gt;Assuming the code that crashes is bug.rb, instead of doing 'ruby bug.rb', just do:&lt;br /&gt;$gdb ruby&lt;br /&gt;(gdb) run bug.rb&lt;br /&gt;&lt;br /&gt;Once the the crash is reproduced, type:&lt;br /&gt;(gdb) bt&lt;br /&gt;&lt;br /&gt;'bt' means 'backtrace'. A C callstack will show up. And you will find some valuable information there. If 'bt' does not give you function name and line# you want, it normally means it can not locate the source code, and you can use the 'dir' command to help gdb locate the source code (Ruby's source code is freely available, just download the one that matches the binary):&lt;br /&gt;(gdb) dir /root/downloaded/ruby-1.8.6-p111&lt;br /&gt;&lt;br /&gt;If the program that crashed is a rake task, just do some thing similar. Rake itself is a Ruby script:&lt;br /&gt;$gdb ruby&lt;br /&gt;(gdb) run /usr/bin/rake -T&lt;br /&gt;&lt;br /&gt;If you have a daemon written in Ruby, sometimes you might see that it hangs (does nothing) or uses too many resources (100% cpu usage). To inspect a live process with process id 12345, do this:&lt;br /&gt;$gdb ruby &lt;br /&gt;(gdb) attach 12345&lt;br /&gt;(gdb) bt&lt;br /&gt;&lt;br /&gt;For Rails applications, a bug may only happen in the production environment. Before you enter 'run', use this to setup the environment:&lt;br /&gt;(gdb) set environment RAILS_ENV = production&lt;br /&gt;&lt;br /&gt; Here are some tips to get more from a C stacktrace. &lt;br /&gt;You can call a C function with a 'call' command under gdb shell -- yep, that makes C feel like an interpreted language. For example, you have a stack trace entry like this: &lt;br /&gt;rb_call0 (klass=47110398570320, recv=47110462241640, id=22977, &lt;br /&gt; oid=, argc=0, argv=0x7fffee0453c8, body=0x2ad8be3946c8, &lt;br /&gt; flags=) at eval.c:5998&lt;br /&gt;You can find out what 'klass' is by using its memory address: &lt;br /&gt;(gdb) call rb_class2name(47110398570320)&lt;br /&gt;Or you can look up a Ruby function's name: &lt;br /&gt;(gdb) call rb_id2name(22977)&lt;br /&gt;&lt;br /&gt;This GDB QUICK REFERENCE and Extending Ruby chapter of 'Programming Ruby' book are great references if you want to know more!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-1921999323562320925?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/1921999323562320925/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=1921999323562320925' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/1921999323562320925'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/1921999323562320925'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2011/08/inspect-ruby-process-from-gdb.html' title='Inspect Ruby Process From gdb'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-4090013000828096332</id><published>2009-01-12T13:31:00.000-08:00</published><updated>2009-01-12T13:54:18.656-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='cron test debug'/><title type='text'>How to debug or test cron script</title><content type='html'>If your simple cron script (/etc/cron.daily, etc/cron.hourly etc) does not run as expected, do the following:&lt;br /&gt;&lt;br /&gt;1. be sure to have '#!/bin/sh' as the first line&lt;br /&gt;2. make sure the script's name does not contains '.'. for example, you should rename 'yourscript.sh' to 'yourscript'.&lt;br /&gt;3. use absolute path if you need to read/write files in the script&lt;br /&gt;4. try run the script in the shell to make sure there is no obvious problem&lt;br /&gt;5. 'run-parts --test /etc/cron.hourly/' will tell you what scripts will run, you should see your script in the list&lt;br /&gt;6. next try to run it like cron does, for example:&lt;br /&gt;cd / &amp;&amp; run-parts --report /etc/cron.hourly&lt;br /&gt;7. cron uses syslog for logging. Check your syslog config file ( /etc/syslog.conf) to see where the log is, and check the log for errors.&lt;br /&gt;&lt;br /&gt;Ref:&lt;br /&gt;[1] Why are cron.hourly files not running? SOLVED&lt;br /&gt;&lt;a href="https://lists.ubuntu.com/archives/ubuntu-users/2007-July/118973.html"&gt;https://lists.ubuntu.com/archives/ubuntu-users/2007-July/118973.html&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-4090013000828096332?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/4090013000828096332/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=4090013000828096332' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/4090013000828096332'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/4090013000828096332'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2009/01/how-to-debug-or-test-cron-script.html' title='How to debug or test cron script'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-325777667672184618</id><published>2008-03-24T18:40:00.000-07:00</published><updated>2008-03-24T18:41:27.047-07:00</updated><title type='text'>Google Summer of Code with Ruby Central</title><content type='html'>Ruby Central will once again participate the Google Summer of Code in 2008 as a mentoring organization:&lt;br /&gt;&lt;a href="http://code.google.com/soc/2008/ruby/about.html"&gt;http://code.google.com/soc/2008/ruby/about.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://on-ruby.blogspot.com"&gt;Pat Eyler&lt;/a&gt; has put together an &lt;a href="http://rubycentral.com/projects/gsoc-2008/ideas-for-gsoc-2008"&gt; idea page&lt;/a&gt;, which is a great reference. While every organization may have different policy, Ruby Central has been happy to see students' own ideas in the past, and I believe this year is not an exception. Feel free to submit your own exciting ideas so that the mentors can pick the best ones.&lt;br /&gt;&lt;br /&gt;Today is the first day for Google to accept student applications. For student who are interested in participating, my advise is to apply as early as possible: normally students who apply early has a slight advantage because mentors will have more time to read their applications. &lt;br /&gt;&lt;br /&gt;And another advise for future GSOC students is: once accepted, please make sure you are well prepared for the program. Google and mentors normally assume you to work near fulltime in the summer, but unfortunately every year we saw 'disappearing' students during the program. If for some reasons you can not make it after being accepted, please communicate with your mentor organization early so that they can make better adjustment.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-325777667672184618?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/325777667672184618/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=325777667672184618' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/325777667672184618'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/325777667672184618'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2008/03/google-summer-of-code-with-ruby-central.html' title='Google Summer of Code with Ruby Central'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-7819666222444989529</id><published>2008-03-24T17:57:00.001-07:00</published><updated>2008-03-24T17:57:52.161-07:00</updated><title type='text'>XRuby license changed to BSD</title><content type='html'>XRuby had been licensed under GNU General Public License v2. For people who want to create solutions based on XRuby, this means they had to adopt GPL as well, which is not always possible. So since &lt;a href="http://code.google.com/p/xruby/downloads/list"&gt;0.3.3&lt;/a&gt;, we changed the license to BSD. Hopefully this will help XRuby gain more acceptance, especially from the corporate world.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-7819666222444989529?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/7819666222444989529/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=7819666222444989529' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/7819666222444989529'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/7819666222444989529'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2008/03/xruby-license-changed-to-bsd.html' title='XRuby license changed to BSD'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-5608027927927871346</id><published>2007-09-24T07:45:00.001-07:00</published><updated>2007-09-24T07:45:52.155-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='xruby'/><title type='text'>XRuby 0.3.1 released</title><content type='html'>XRuby 0.3.1 is released today and you can download the latest version here:&lt;br /&gt;&lt;a href="http://code.google.com/p/xruby/downloads/list"&gt;http://code.google.com/p/xruby/downloads/list&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The major changes in this version are:&lt;br /&gt;&lt;br /&gt;1. &lt;span style="font-weight: bold;"&gt;Ruby standard libraries are now pre-compiled&lt;/span&gt; and the compilation results (java bytecode) are shipped as part of the xruby.jar. This makes deployment really easy, as there is one jar file to deal with. Pre-compiled libraries means it isn't necessary to compile these code every time by the user which is helpful to performance.&lt;br /&gt;&lt;br /&gt;The size of the final jar may cause some concerns: while the number of ruby stdlib supported by the current version of XRuby is still limited, the size of the compiled stdlib has already reached 2,000 KB (the entire xruby-0.3.1.jar is over 4,000 KB). Maybe we will ship ruby stdlib in a separated jar files in the future.&lt;br /&gt;&lt;br /&gt;2. Use annotation and code generation to bind Java level method to Ruby level method. We started to make this change in 0.3.0 and finished it in 0.3.1. It helped us to get rid of lots of redundant code. For more information about this change, please read our &lt;a href="http://xruby.blogspot.com/2007/08/xruby-030-released.html"&gt;last announcement&lt;/a&gt; and dreamhead's articles(&lt;a href="http://dreamhead.blogbus.com/logs/7226338.html"&gt;1&lt;/a&gt;, &lt;a href="http://dreamhead.blogbus.com/logs/7502504.html"&gt;2&lt;/a&gt;) on his blogs (in Chinese).&lt;br /&gt;&lt;br /&gt;Thank everyone who has contributed to this release.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-5608027927927871346?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/5608027927927871346/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=5608027927927871346' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/5608027927927871346'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/5608027927927871346'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2007/09/xruby-031-released.html' title='XRuby 0.3.1 released'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-3256385091342192863</id><published>2007-08-07T22:05:00.000-07:00</published><updated>2007-08-07T22:06:16.796-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='xruby'/><title type='text'>xruby 0.3.0 released</title><content type='html'>I am pleased to announce that XRuby 0.3.0 is released:&lt;br /&gt;&lt;a href="http://code.google.com/p/xruby/downloads/list"&gt;http://code.google.com/p/xruby/downloads/list&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;We have fixed lots of bugs and made significant improvement in the code.&lt;br /&gt;&lt;br /&gt;Changes from 0.2.1 to 0.3.0:&lt;br /&gt;1. Use annotation and code generation to bind Java level method to Ruby level method (I will talk more about this later).&lt;br /&gt;&lt;br /&gt;2. More unit tests passed. We have not eliminated all test failures in test/ruby. But as most of the failures are caused by the implementation of builtin libraries, we will be able to fixed them soon in 0.4.0.&lt;br /&gt;&lt;br /&gt;Changes from 0.2.0 to 0.2.1:&lt;br /&gt;1) Dreamhead optimized method/block calls for methods with zero/one&lt;br /&gt;arguments. It makes our performance even better.&lt;br /&gt;&lt;br /&gt;2) ZhangYu improved Java integration significantly, he also created a wiki page with lots of good examples:&lt;br /&gt;&lt;a href="http://code.google.com/p/xruby/wiki/JavaIntegration"&gt;http://code.google.com/p/xruby/wiki/JavaIntegration &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;3) Mechiland and I made more ruby unit tests pass.&lt;br /&gt;&lt;br /&gt;The most significant change of 0.3.0 is the using of annotation and code generation to bind Java level method to ruby level method. The idea was inspired by the discussions about Java 5 on &lt;a href="http://archive.jruby.codehaus.org/dev"&gt;jruby's maillist&lt;/a&gt;, and dreamhead turned it into reality quickly.&lt;br /&gt;&lt;br /&gt;As we know, a Ruby method does a little bit more than a Java method. So if we have a method like this in Java:&lt;br /&gt;&lt;pre&gt;public class RubyString {&lt;br /&gt;   public RubyFloat to_f() {&lt;br /&gt;       ...&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;To turn it (RubyString.to_f) into a Ruby level method, we have to add a few more code to 'wrap' into a class (extends RubyMethod) and 'register' it (defineMethod), e.g:&lt;br /&gt;&lt;pre&gt;public class String_to_f extends RubyNoArgMethod {&lt;br /&gt;   protected RubyValue run(RubyValue receiver, RubyBlock block) {&lt;br /&gt;       return ((RubyString)receiver).to_f();&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;...&lt;br /&gt;RubyRuntime.StringClass.defineMethod("to_f", new String_to_f());&lt;br /&gt;&lt;/pre&gt;For every method, we need to write similar code and it is not fun to repeat yourself. In 0.3.0, we no longer have to do this anymore. As as long as you add annotation like this:&lt;br /&gt;&lt;pre&gt;@RubyLevelClass(name="String")&lt;br /&gt;public class RubyString {&lt;br /&gt;   @RubyLevelMethod(name="to_f")&lt;br /&gt;   public RubyFloat to_f() {&lt;br /&gt;       ...&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;XRuby will turn it into a Ruby level method automatically (using ASM to generate Java bytecode).&lt;br /&gt;&lt;br /&gt;I have not used Java 5's annotation feature before, but this looks like an very elegant solution.&lt;br /&gt;&lt;br /&gt;Thank everyone who has contributed to this release.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-3256385091342192863?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/3256385091342192863/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=3256385091342192863' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/3256385091342192863'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/3256385091342192863'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2007/08/xruby-030-released.html' title='xruby 0.3.0 released'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-2842362357185648651</id><published>2007-06-12T08:15:00.001-07:00</published><updated>2007-06-12T08:15:11.232-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='xruby'/><title type='text'>ruby -y</title><content type='html'>For people who are interested in how ruby's yacc parser works, there is an undocumented command line option("-y") that may be helpful. It will display a trace of the parser's operations. &lt;br /&gt;&lt;br /&gt;To use it, you need to clear your RUBYOPT environment variable to NOT use "rubygems" (this will break some ruby applications), otherwise it will make too much noise.&lt;br /&gt;&lt;br /&gt;Here is an example:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;$ruby -y -e "a=1"&lt;br /&gt;Starting parse&lt;br /&gt;Entering state 0&lt;br /&gt;Reducing stack by rule 1 (line 328), -&gt; @1&lt;br /&gt;Stack now 0&lt;br /&gt;Entering state 2&lt;br /&gt;Reading a token: Next token is token tIDENTIFIER ()&lt;br /&gt;Shifting token tIDENTIFIER, Entering state 34&lt;br /&gt;Reading a token: Next token is token '=' ()&lt;br /&gt;Reducing stack by rule 418 (line 2146), tIDENTIFIER -&gt; variable&lt;br /&gt;Stack now 0 2&lt;br /&gt;Entering state 90&lt;br /&gt;Next token is token '=' ()&lt;br /&gt;Reducing stack by rule 83 (line 827), variable -&gt; lhs&lt;br /&gt;Stack now 0 2&lt;br /&gt;Entering state 73&lt;br /&gt;Next token is token '=' ()&lt;br /&gt;Shifting token '=', Entering state 315&lt;br /&gt;Reading a token: Next token is token tINTEGER ()&lt;br /&gt;Shifting token tINTEGER, Entering state 40&lt;br /&gt;Reducing stack by rule 414 (line 2134), tINTEGER -&gt; numeric&lt;br /&gt;Stack now 0 2 73 315&lt;br /&gt;Entering state 89&lt;br /&gt;Reducing stack by rule 376 (line 1899), numeric -&gt; literal&lt;br /&gt;Stack now 0 2 73 315&lt;br /&gt;Entering state 79&lt;br /&gt;Reducing stack by rule 267 (line 1421), literal -&gt; primary&lt;br /&gt;Stack now 0 2 73 315&lt;br /&gt;Entering state 75&lt;br /&gt;Reading a token: Next token is token '\n' ()&lt;br /&gt;Reducing stack by rule 217 (line 1199), primary -&gt; arg&lt;br /&gt;Stack now 0 2 73 315&lt;br /&gt;Entering state 488&lt;br /&gt;Next token is token '\n' ()&lt;br /&gt;Reducing stack by rule 173 (line 953), lhs '=' arg -&gt; arg&lt;br /&gt;Stack now 0 2&lt;br /&gt;Entering state 74&lt;br /&gt;Next token is token '\n' ()&lt;br /&gt;Reducing stack by rule 40 (line 616), arg -&gt; expr&lt;br /&gt;Stack now 0 2&lt;br /&gt;Entering state 64&lt;br /&gt;Next token is token '\n' ()&lt;br /&gt;Reducing stack by rule 34 (line 596), expr -&gt; stmt&lt;br /&gt;Stack now 0 2&lt;br /&gt;Entering state 63&lt;br /&gt;Next token is token '\n' ()&lt;br /&gt;Reducing stack by rule 6 (line 381), stmt -&gt; stmts&lt;br /&gt;Stack now 0 2&lt;br /&gt;Entering state 62&lt;br /&gt;Next token is token '\n' ()&lt;br /&gt;Shifting token '\n', Entering state 216&lt;br /&gt;Reducing stack by rule 496 (line 2429), '\n' -&gt; term&lt;br /&gt;Stack now 0 2 62&lt;br /&gt;Entering state 220&lt;br /&gt;Reducing stack by rule 497 (line 2432), term -&gt; terms&lt;br /&gt;Stack now 0 2 62&lt;br /&gt;Entering state 300&lt;br /&gt;Reading a token: Now at end of input.&lt;br /&gt;Reducing stack by rule 489 (line 2416), terms -&gt; opt_terms&lt;br /&gt;Stack now 0 2 62&lt;br /&gt;Entering state 299&lt;br /&gt;Reducing stack by rule 4 (line 373), stmts opt_terms -&gt; compstmt&lt;br /&gt;Stack now 0 2&lt;br /&gt;Entering state 61&lt;br /&gt;Reducing stack by rule 2 (line 328), @1 compstmt -&gt; program&lt;br /&gt;Stack now 0&lt;br /&gt;Entering state 1&lt;br /&gt;Now at end of input.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;XRuby's ANTLR parser does not have this option. But as ANRLE produces human readable code, you can just read the generated code or step through it in a debugger to learn how it works.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-2842362357185648651?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/2842362357185648651/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=2842362357185648651' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/2842362357185648651'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/2842362357185648651'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2007/06/ruby-y.html' title='ruby -y'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-7695307076536751076</id><published>2007-05-15T08:18:00.001-07:00</published><updated>2007-05-15T08:19:20.679-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='xruby'/><title type='text'>XRuby 0.2.0 released</title><content type='html'>I am glad to announce that XRuby 0.2.0 is now available for download at: &lt;br /&gt;&lt;a href="http://code.google.com/p/xruby/downloads/list"&gt;http://code.google.com/p/xruby/downloads/list&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Here is a summary of major changes in this release:&lt;br /&gt;&lt;br /&gt;1. Beanworms started to work on the debugging support and we now have a basic debugger in trunk.&lt;br /&gt;2. Zhang Yu and Haofei Wang added/fixed lots of builtin methods&lt;br /&gt;3. Dreamhead rewrote RubySymbol as the old one was plain wrong&lt;br /&gt;4. As test::unit works on XRuby, we imported unit tests from c ruby (test\ruby) to test our implementation. The result was not very impressive so far, less than half of the tests passed. We are planning to make all tests pass in the coming weeks.&lt;br /&gt;5. Meanwhile, Femto is leading our efforts to create an ANTLR v3 based ruby parser in another branch. Upgrading our parser from ANTLR v2 to v3 is indeed challenging, but he has make very impressive progress.&lt;br /&gt;&lt;br /&gt;Thank you everybody who contributed to this release!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-7695307076536751076?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/7695307076536751076/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=7695307076536751076' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/7695307076536751076'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/7695307076536751076'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2007/05/xruby-020-released.html' title='XRuby 0.2.0 released'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-3092927218827532150</id><published>2007-04-17T04:16:00.001-07:00</published><updated>2007-04-27T04:27:53.454-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='xruby'/><title type='text'>InfoQ article on XRuby</title><content type='html'>Werner Schuster from InfoQ has a very nice article about XRuby, you can &lt;a href="http://www.infoq.com/news/2007/04/xruby-another-ruby-on-jvm"&gt;read it here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;UPDATE 04/27/2007: InfoQ China had an interview with our core developer Dreamhead. You can read it &lt;a href="http://www.infoq.com/cn/news/2007/04/interview-xruby-developer"&gt;here (in Chinese)&lt;/a&gt;. And congratulations to Dreamhead for joining Thoughtworks.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-3092927218827532150?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/3092927218827532150/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=3092927218827532150' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/3092927218827532150'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/3092927218827532150'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2007/04/infoq-article-on-xruby.html' title='InfoQ article on XRuby'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-5479505336169999604</id><published>2007-04-10T09:15:00.000-07:00</published><updated>2007-04-10T17:31:34.857-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='xruby'/><title type='text'>XRuby 0.1.4 released</title><content type='html'>I am glad to announce that XRuby 0.1.4 is now available for download at: &lt;a href="http://code.google.com/p/xruby/downloads/list"&gt;http://code.google.com/p/xruby/downloads/list&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The most significant change in this release is: one of our team member, dreamhead, single-handly created a new runtime (the core of the system that manages ruby types, methods...) to make it very close to the classic C ruby, and therefore fixed several compatibility issues with C ruby. As a translator of the Chinese version Ruby Hacking Guide, dreamhead has very good knowledge of the ruby internal and gives a great lift on the XRuby's development.&lt;br /&gt;&lt;br /&gt;As we have learned rewriting is very difficult, we learned it again in a hard way. Dreamhead wrote most of code last year, several months before 0.1.0 release. First we tried to make a wholesale replacement of the runtime, but problems were here and there and lots of unit tests broke. Since we do not want to have a broken system in the SVN trunk, we decided to take 'refactoring' approach and merge changes step by step. It is still very hard, but dreamhead made lots of efforts and finished the merge yesterday.&lt;br /&gt;&lt;br /&gt;Actually it may take less time if we insist on following the 'rewrite' approach (replace all the old code and fix broken tests), but the benefit of 'refactoring' is significant: it gives us a stable code base so that we made several releases during this big change.&lt;br /&gt;&lt;br /&gt;There are more exciting news behind the scene now: Beanworms is working on the debugger support, and Femto and Yuesefa have showed interest to migrate our ruby parser to ANTLR 3.0.&lt;br /&gt;&lt;br /&gt;Thank you for people who helps us on making this release. It has been a great learning experience working with the project.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-5479505336169999604?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/5479505336169999604/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=5479505336169999604' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/5479505336169999604'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/5479505336169999604'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2007/04/xruby-014-released.html' title='XRuby 0.1.4 released'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-5349122123675144026</id><published>2007-03-11T20:15:00.000-07:00</published><updated>2007-03-11T20:16:18.211-07:00</updated><title type='text'>Ruby builtin in pure Ruby</title><content type='html'>One of the best things I love about rubinius project is: their developers try to keep the dependency on system language (C in their case) minimal, and they take it seriously. Take a look of &lt;a href="http://code.fallingsnow.net/svn/rubinius/trunk/kernel/core/"&gt;http://code.fallingsnow.net/svn/rubinius/trunk/kernel/core/&lt;/a&gt;, you will find out lots of buitlin libraries are implemented in pure ruby, even lots of string functions.&lt;br /&gt;&lt;br /&gt;Pure ruby builtin has some drawbacks, though. One is performance penalty, the other is potential side effects. For example, basically &lt;b&gt;Integer#times&lt;/b&gt; can be implemented as simple as this in pure ruby:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;class Integer&lt;br /&gt; def times  &lt;br /&gt;  i = 0  &lt;br /&gt;  while i &lt; self&lt;br /&gt;   yield i&lt;br /&gt;   i += 1;  &lt;br /&gt;  end &lt;br /&gt;  self&lt;br /&gt; end&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;But this version of Integer#times does not work exactly the same as Ruby 1.8.5. If an user want to override Fixnum#+ (this may never happen in real life):&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;class Fixnum&lt;br /&gt;  def + x&lt;br /&gt;    return 9999&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Our Integer#times's behavior will change, while Ruby 1.8.5 won't. That is because Ruby 1.8.5's implementation (int_dotimes() in Numeric.c) optimizes for Fixnum: it does not  call '+' method dynamically for Fixnum, instead, it just increases the integer directly.  If you want to implement this method as same as Ruby 1.8.5 then you have to write code in system language.&lt;br /&gt;&lt;br /&gt;This kind of optimization is all over the place in c ruby. I am not clear about its motivation, but I guess performance is one of the reasons. For example, "&lt;b&gt;30000000.times {|x|}&lt;/b&gt;" is about twice faster than "&lt;b&gt;i = 0; while i &lt; 30000000; i +=1; end&lt;/b&gt;" in Ruby 1.8.5.&lt;br /&gt;&lt;br /&gt;Difference people may have different opinions on what the 'right' behavior should be. As for me, I like the behavior of the pure ruby implementation better.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-5349122123675144026?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/5349122123675144026/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=5349122123675144026' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/5349122123675144026'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/5349122123675144026'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2007/03/ruby-builtin-in-pure-ruby.html' title='Ruby builtin in pure Ruby'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-5966502233960701190</id><published>2007-03-06T19:18:00.001-08:00</published><updated>2007-03-07T06:34:52.776-08:00</updated><title type='text'>XRuby is faster than Ruby 1.8.5 in most benchmarks</title><content type='html'>Two weeks ago, Antonio Cangiano compared the &lt;a href="http://www.antoniocangiano.com/articles/2007/02/19/ruby-implementations-shootout-ruby-vs-yarv-vs-jruby-vs-gardens-point-ruby-net-vs-rubinius-vs-cardinal"&gt;performance of different ruby implementations&lt;/a&gt; using Ruby 1.9 (YARV)'s benchmark suite. His numbers got me thinking: all alternative implementations performed badly -- most are even way slower than ruby 1.8.5. Does it signal that JVM and .NET are bad platform for Ruby language? &lt;br /&gt;&lt;br /&gt;With this doubt I tried the benchmark with XRuby. XRuby is a ruby compiler. Unlike other implementations, it generates Java bytecode that run directly on JVM. But at first the numbers are not impressive: the 0.1.2 version is still slower than Ruby 1.8.5 in most of the cases.&lt;br /&gt;&lt;br /&gt;Maybe I should mention that the XRuby team had done virtually nothing for performance before, and we would avoid optimization as long as possible if it makes our code complicated. But after doing some measurements, it turns out our bad performance are largely caused by a logic 'error': as we know Ruby Fixnum can not have singleton methods, but in 0.1.2 it still lookup an empty method table. And along with some bad code practices (iterating an empty ArrayList without checking if it is empty first etc), it makes method lookup much slower than it should be. &lt;br /&gt;&lt;br /&gt;I fixed the problem by adding about 10 lines of code, and got great result: &lt;b&gt;In most benchmarks, XRuby 0.1.3 is faster than Ruby 1.8.5. For some, faster in a significant way&lt;/b&gt;. There are still some tests in which we are slower, but it looks like caused by poorly implemented builtin.&lt;br /&gt;&lt;br /&gt;The following table shows the benchmark result for XRuby 0.1.3. The best part is: &lt;b&gt;we did it without a method cache&lt;/b&gt;. YARV is still faster than XRuby, but we have lots of room to improve too.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&gt;java -Xmx512m -jar xruby-0.1.3.jar benchmark\run.rb&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;Test&lt;/td&gt;&lt;td&gt;Ruby 1.8.5&lt;/td&gt;&lt;td&gt;XRuby 0.1.3&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_app_answer.rb&lt;/td&gt;&lt;td&gt;fail&lt;/td&gt;&lt;td&gt;fail&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_app_factorial.rb&lt;/td&gt;&lt;td&gt;fail&lt;/td&gt;&lt;td&gt;fail&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_app_fib.rb&lt;/td&gt;&lt;td&gt;20.02&lt;/td&gt;&lt;td BGCOLOR=green&gt;12.29&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_app_mandelbrot.rb&lt;/td&gt;&lt;td BGCOLOR=green&gt;7.099&lt;/td&gt;&lt;td&gt;8.252&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_app_pentomino.rb&lt;/td&gt;&lt;td BGCOLOR=green&gt;289.8&lt;/td&gt;&lt;td&gt;538.5&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_app_raise.rb&lt;/td&gt;&lt;td&gt;4.846&lt;/td&gt;&lt;td BGCOLOR=green&gt;3.986&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_app_strconcat.rb&lt;/td&gt;&lt;td&gt;5.898&lt;/td&gt;&lt;td BGCOLOR=green&gt;3.234&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_app_tak.rb&lt;/td&gt;&lt;td&gt;26.14&lt;/td&gt;&lt;td BGCOLOR=green&gt;22.12&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_app_tarai.rb&lt;/td&gt;&lt;td&gt;20.89&lt;/td&gt;&lt;td BGCOLOR=green&gt;18.35&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_loop_times.rb&lt;/td&gt;&lt;td BGCOLOR=green&gt;14.28&lt;/td&gt;&lt;td&gt;19.30&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_loop_whileloop.rb&lt;/td&gt;&lt;td&gt;26.03&lt;/td&gt;&lt;td BGCOLOR=green&gt;19.27&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_loop_whileloop2.rb&lt;/td&gt;&lt;td&gt;5.257&lt;/td&gt;&lt;td BGCOLOR=green&gt;4.786&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_so_ackermann.rb&lt;/td&gt;&lt;td&gt;fail&lt;/td&gt;&lt;td&gt;fail&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_so_array.rb&lt;/td&gt;&lt;td BGCOLOR=green&gt;19.17&lt;/td&gt;&lt;td&gt;46.84&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_so_concatenate.rb&lt;/td&gt;&lt;td BGCOLOR=green&gt;5.727&lt;/td&gt;&lt;td&gt;9.684&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_so_count_words.rb&lt;/td&gt;&lt;td BGCOLOR=green&gt;2.944&lt;/td&gt;&lt;td&gt;45.50&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_so_exception.rb&lt;/td&gt;&lt;td&gt;9.793&lt;/td&gt;&lt;td BGCOLOR=green&gt;7.399&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_so_lists.rb&lt;/td&gt;&lt;td BGCOLOR=green&gt;3.666&lt;/td&gt;&lt;td&gt;24.59&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_so_matrix.rb&lt;/td&gt;&lt;td BGCOLOR=green&gt;6.249&lt;/td&gt;&lt;td&gt;8.452&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_so_nested_loop.rb&lt;/td&gt;&lt;td&gt;15.17&lt;/td&gt;&lt;td BGCOLOR=green&gt;13.45&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_so_object.rb&lt;/td&gt;&lt;td&gt;21.49&lt;/td&gt;&lt;td BGCOLOR=green&gt;7.991&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_so_random.rb&lt;/td&gt;&lt;td&gt;6.169&lt;/td&gt;&lt;td BGCOLOR=green&gt;5.888&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_so_sieve.rb&lt;/td&gt;&lt;td BGCOLOR=green&gt;2.042&lt;/td&gt;&lt;td&gt;2.753&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm1_block.rb&lt;/td&gt;&lt;td&gt;64.57&lt;/td&gt;&lt;td BGCOLOR=green&gt;38.69&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm1_const.rb&lt;/td&gt;&lt;td&gt;47.47&lt;/td&gt;&lt;td BGCOLOR=green&gt;25.57&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm1_ensure.rb&lt;/td&gt;&lt;td&gt;45.54&lt;/td&gt;&lt;td BGCOLOR=green&gt;20.01&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm1_length.rb&lt;/td&gt;&lt;td&gt;55.50&lt;/td&gt;&lt;td BGCOLOR=green&gt;40.89&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm1_rescue.rb&lt;/td&gt;&lt;td&gt;39.61&lt;/td&gt;&lt;td BGCOLOR=green&gt;20.64&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm1_simplereturn.rb&lt;/td&gt;&lt;td&gt;56.02&lt;/td&gt;&lt;td BGCOLOR=green&gt;29.06&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm1_swap.rb&lt;/td&gt;&lt;td&gt;76.35&lt;/td&gt;&lt;td BGCOLOR=green&gt;30.52&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm2_array.rb&lt;/td&gt;&lt;td&gt;19.34&lt;/td&gt;&lt;td BGCOLOR=green&gt;8.532&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm2_method.rb&lt;/td&gt;&lt;td&gt;33.72&lt;/td&gt;&lt;td BGCOLOR=green&gt;19.63&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm2_poly_method.rb&lt;/td&gt;&lt;td&gt;45.23&lt;/td&gt;&lt;td BGCOLOR=green&gt;20.62&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm2_poly_method_ov.rb&lt;/td&gt;&lt;td&gt;12.64&lt;/td&gt;&lt;td BGCOLOR=green&gt;8.261&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm2_proc.rb&lt;/td&gt;&lt;td&gt;21.08&lt;/td&gt;&lt;td BGCOLOR=green&gt;17.86&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm2_regexp.rb&lt;/td&gt;&lt;td BGCOLOR=green&gt;13.09&lt;/td&gt;&lt;td&gt;30.87&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm2_send.rb&lt;/td&gt;&lt;td BGCOLOR=green&gt;11.71&lt;/td&gt;&lt;td&gt;15.75&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm2_super.rb&lt;/td&gt;&lt;td&gt;13.92&lt;/td&gt;&lt;td BGCOLOR=green&gt;7.510&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm2_unif1.rb&lt;/td&gt;&lt;td&gt;11.30&lt;/td&gt;&lt;td BGCOLOR=green&gt;8.292&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm2_zsuper.rb&lt;/td&gt;&lt;td&gt;15.71&lt;/td&gt;&lt;td BGCOLOR=green&gt;7.740&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm3_thread_create_join.rb&lt;/td&gt;&lt;td BGCOLOR=green&gt;0.110&lt;/td&gt;&lt;td&gt;1.331&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;* The test environment is Intel Pentium M 1G CPU, 1G Memory, Windows XP SP2, Java 1.5.0_09.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-5966502233960701190?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/5966502233960701190/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=5966502233960701190' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/5966502233960701190'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/5966502233960701190'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2007/03/xruby-runs-most-benchmark-faster-than.html' title='XRuby is faster than Ruby 1.8.5 in most benchmarks'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-4321104369681836049</id><published>2007-02-28T19:13:00.001-08:00</published><updated>2007-03-01T21:59:43.043-08:00</updated><title type='text'>XRuby 0.1.2 released</title><content type='html'>XRuby 0.1.2 is now available for download from the project download page: &lt;a href="http://code.google.com/p/xruby/downloads/list"&gt;http://code.google.com/p/xruby/downloads/list&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This latest release contains more built-in libraries and a few bug fixes for the compiler. We expect to release a new stable version every month.&lt;br /&gt;&lt;br /&gt;Last week, Antonio Cangiano did a very interesting job to&lt;a href="http://www.antoniocangiano.com/articles/2007/02/19/ruby-implementations-shootout-ruby-vs-yarv-vs-jruby-vs-gardens-point-ruby-net-vs-rubinius-vs-cardinal"&gt; compare the performance of different ruby implementations&lt;/a&gt; using YARV's benchmark suite. XRuby is not included in his test as Antonio may not know our project exists. For people who are interested, here is the XRuby's performance data (due to my limited resource, only ruby 1.8.5 interpreter was compared):&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&gt;java -Xmx512m -jar xruby-0.1.2.jar benchmark\run.rb&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;tr&gt;&lt;td&gt;Test&lt;/td&gt;&lt;td&gt;Ruby 1.8.5&lt;/td&gt;&lt;td&gt;XRuby 0.1.2&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_app_answer.rb&lt;/td&gt;&lt;td&gt;fail&lt;/td&gt;&lt;td&gt;fail&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_app_factorial.rb&lt;/td&gt;&lt;td&gt;fail&lt;/td&gt;&lt;td&gt;fail&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_app_fib.rb&lt;/td&gt;&lt;td&gt;20.42&lt;/td&gt;&lt;td&gt;33.84&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_app_mandelbrot.rb&lt;/td&gt;&lt;td&gt;7.270&lt;/td&gt;&lt;td&gt;15.33&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_app_pentomino.rb&lt;/td&gt;&lt;td&gt;294.2&lt;/td&gt;&lt;td&gt;956.9&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_app_raise.rb&lt;/td&gt;&lt;td&gt;4.906&lt;/td&gt;&lt;td&gt;4.597&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_app_strconcat.rb&lt;/td&gt;&lt;td&gt;5.917&lt;/td&gt;&lt;td&gt;5.858&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_app_tak.rb&lt;/td&gt;&lt;td&gt;26.46&lt;/td&gt;&lt;td&gt;38.95&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_app_tarai.rb&lt;/td&gt;&lt;td&gt;21.08&lt;/td&gt;&lt;td&gt;35.51&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_loop_times.rb&lt;/td&gt;&lt;td&gt;14.83&lt;/td&gt;&lt;td&gt;93.55&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_loop_whileloop.rb&lt;/td&gt;&lt;td&gt;26.26&lt;/td&gt;&lt;td&gt;76.5&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_loop_whileloop2.rb&lt;/td&gt;&lt;td&gt;5.327&lt;/td&gt;&lt;td&gt;16.15&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_so_ackermann.rb&lt;/td&gt;&lt;td&gt;fail&lt;/td&gt;&lt;td&gt;fail&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_so_array.rb&lt;/td&gt;&lt;td&gt;19.35&lt;/td&gt;&lt;td&gt;300.2&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_so_concatenate.rb&lt;/td&gt;&lt;td&gt;5.868&lt;/td&gt;&lt;td&gt;26.58&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_so_count_words.rb&lt;/td&gt;&lt;td&gt;2.253&lt;/td&gt;&lt;td&gt;46.43&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_so_exception.rb&lt;/td&gt;&lt;td&gt;9.893&lt;/td&gt;&lt;td&gt;9.973&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_so_lists.rb&lt;/td&gt;&lt;td&gt;3.696&lt;/td&gt;&lt;td&gt;41.04&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_so_matrix.rb&lt;/td&gt;&lt;td&gt;6.328&lt;/td&gt;&lt;td&gt;21.29&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_so_nested_loop.rb&lt;/td&gt;&lt;td&gt;15.38&lt;/td&gt;&lt;td&gt;68.20&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_so_object.rb&lt;/td&gt;&lt;td&gt;21.97&lt;/td&gt;&lt;td&gt;20.77&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_so_random.rb&lt;/td&gt;&lt;td&gt;6.269&lt;/td&gt;&lt;td&gt;15.69&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_so_sieve.rb&lt;/td&gt;&lt;td&gt;1.992&lt;/td&gt;&lt;td&gt;5.476&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm1_block.rb&lt;/td&gt;&lt;td&gt;65.67&lt;/td&gt;&lt;td&gt;98.91&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm1_const.rb&lt;/td&gt;&lt;td&gt;48.05&lt;/td&gt;&lt;td&gt;82.31&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm1_ensure.rb&lt;/td&gt;&lt;td&gt;46.19&lt;/td&gt;&lt;td&gt;75.38&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm1_length.rb&lt;/td&gt;&lt;td&gt;55.62&lt;/td&gt;&lt;td&gt;105.6&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm1_rescue.rb&lt;/td&gt;&lt;td&gt;36.47&lt;/td&gt;&lt;td&gt;80.91&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm1_simplereturn.rb&lt;/td&gt;&lt;td&gt;57.12&lt;/td&gt;&lt;td&gt;88.16&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm1_swap.rb&lt;/td&gt;&lt;td&gt;76.21&lt;/td&gt;&lt;td&gt;85.73&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm2_array.rb&lt;/td&gt;&lt;td&gt;18.64&lt;/td&gt;&lt;td&gt;19.65&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm2_method.rb&lt;/td&gt;&lt;td&gt;33.41&lt;/td&gt;&lt;td&gt;35.32&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm2_poly_method.rb&lt;/td&gt;&lt;td&gt;45.42&lt;/td&gt;&lt;td&gt;47.78&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm2_poly_method_ov.rb&lt;/td&gt;&lt;td&gt;12.81&lt;/td&gt;&lt;td&gt;25.98&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm2_proc.rb&lt;/td&gt;&lt;td&gt;21.54&lt;/td&gt;&lt;td&gt;31.23&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm2_regexp.rb&lt;/td&gt;&lt;td&gt;13.40&lt;/td&gt;&lt;td&gt;52.35&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm2_send.rb&lt;/td&gt;&lt;td&gt;11.87&lt;/td&gt;&lt;td&gt;31.60&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm2_super.rb&lt;/td&gt;&lt;td&gt;13.98&lt;/td&gt;&lt;td&gt;20.25&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm2_unif1.rb&lt;/td&gt;&lt;td&gt;11.46&lt;/td&gt;&lt;td&gt;19.95&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm2_zsuper.rb&lt;/td&gt;&lt;td&gt;15.84&lt;/td&gt;&lt;td&gt;21.92&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bm_vm3_thread_create_join.rb&lt;/td&gt;&lt;td&gt;0.120&lt;/td&gt;&lt;td&gt;1.402&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;The test environment is Intel Pentium M 1G CPU, 1G Memory, Windows XP SP2, Java 1.5.0_09. It may be worth to mention we have done almost nothing for optimization, not even a simple method cache. I think it is quite possible for a JVM based ruby compiler to beat the classic Ruby interpreter on performance, while YARV's number is going to be very hard for us to reach.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-4321104369681836049?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/4321104369681836049/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=4321104369681836049' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/4321104369681836049'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/4321104369681836049'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2007/02/xruby-012-released.html' title='XRuby 0.1.2 released'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-6900737948665511027</id><published>2007-02-18T19:33:00.001-08:00</published><updated>2007-02-18T19:33:58.753-08:00</updated><title type='text'>On-Ruby interview</title><content type='html'>Pat Eyler recently interviewed XRuby team, the first episode is  now posted on his popular On-Ruby blog: &lt;a href="http://on-ruby.blogspot.com/2007/02/serial-xruby-interview-episode-i.html"&gt;http://on-ruby.blogspot.com/2007/02/serial-xruby-interview-episode-i.html&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-6900737948665511027?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/6900737948665511027/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=6900737948665511027' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/6900737948665511027'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/6900737948665511027'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2007/02/on-ruby-interview.html' title='On-Ruby interview'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-312769520467144627</id><published>2007-01-29T14:16:00.000-08:00</published><updated>2007-01-29T14:18:23.215-08:00</updated><title type='text'>XRuby 0.1.0 released</title><content type='html'>[Link of this article: &lt;a href="http://xruby.blogspot.com/2007/01/xruby-010-released.html"&gt;http://xruby.blogspot.com/2007/01/xruby-010-released.html&lt;/a&gt;]&lt;br/&gt;&lt;br/&gt;Today I am glad to announce the release XRuby 0.1.0 , a ruby compiler which compiles ruby script (.rb) to java bytecode (.class).  You can download it from here: &lt;a href="http://code.google.com/p/xruby/downloads/list"&gt;http://code.google.com/p/xruby/downloads/list&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;XRuby 0.1.0 is the first release of XRuby. It is able to pass all tests in samples/test.rb - a decent test suite that comes with ruby installation.&lt;br/&gt;&lt;br/&gt;As a compiler, XRuby compiles ruby source code so that your program can run on top of Java Virtual Machine.  For example, if you have a ruby script like this:&lt;br/&gt;&lt;br/&gt;&lt;i&gt;class MyClass&lt;br/&gt;   def say_hello_three_times&lt;br/&gt;      3.times {puts "hello"}&lt;br/&gt;   end&lt;br/&gt;end&lt;br/&gt;&lt;br/&gt;MyClass.new.say_hello_three_times&lt;/i&gt;&lt;br/&gt;&lt;br/&gt;You can compile it with XRuby (assuming its name is test.rb):&lt;br/&gt;&lt;br/&gt;&lt;i&gt;&gt;java -jar xruby-0.1.0.jar -c test.rb&lt;/i&gt;&lt;br/&gt;&lt;br/&gt;The compiler will generate a test.jar. It can be launched as a regular java application, with the following command: &lt;br/&gt;&lt;br/&gt;&lt;i&gt;&gt;java -jar test.jar&lt;br/&gt;hello&lt;br/&gt;hello&lt;br/&gt;hello&lt;/i&gt;&lt;br/&gt;&lt;br/&gt;For your convenience, you can also run the script directly (without -c option), just like the classic ruby interpreter. Under the hood it compiles the script then run the bytecode:&lt;br/&gt;&lt;br/&gt;&lt;i&gt;&gt;java -jar xruby-0.1.0.jar test.rb&lt;br/&gt;hello&lt;br/&gt;hello&lt;br/&gt;hello&lt;/i&gt;&lt;br/&gt;&lt;br/&gt;While little known, this project has been under active development for one year and eight months. I started the project around mid 2005, and it took me about eight months to write a ruby parser with Antlr, and then one year to implement the compiler and runtime. Some people joined me during the second half of 2006 and made great contribution. It is just the beginning of an exciting journey.&lt;br/&gt;&lt;br/&gt;We still have a long way to go before claiming XRuby is a very competent alternative implementation of ruby. And comparing with our peers we lag behind in implementing ruby's built-in libraries and do not have Ruby-Java bridge. Our next focus is to improve this situation and make major ruby libraries and framework work under XRuby. And we hope by end of 2007 you can use XRuby to compile your Ruby On Rails application to a .war file and run it directly on a J2EE server. &lt;br/&gt;&lt;br/&gt;We appreciate your feedback. Our development maillist is at:&lt;br/&gt;&lt;a href="http://groups.google.com/group/xruby-devel"&gt;http://groups.google.com/group/xruby-devel&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;I also setup a new blog to be used as XRuby's team blog: &lt;a href="http://xruby.blogspot.com/"&gt;http://xruby.blogspot.com&lt;/a&gt; . While  new articles will be cross posted for quite a while, I encourage you to subscribe &lt;a href="http://feeds.feedburner.com/xruby"&gt;http://feeds.feedburner.com/xruby &lt;/a&gt;if have not done so.&lt;br/&gt;&lt;br/&gt;Thank you and have fun.&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-312769520467144627?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/312769520467144627/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=312769520467144627' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/312769520467144627'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/312769520467144627'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2007/01/xruby-010-released.html' title='XRuby 0.1.0 released'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-2715483769101644330</id><published>2007-01-02T08:45:00.000-08:00</published><updated>2007-01-02T09:12:44.490-08:00</updated><title type='text'>XRuby 0.1.0 will be released in January, 2007</title><content type='html'>Well, the release date of xruby 0.1.0  (our first release) has to be pushed back a little due to the lack of time of our projects members.&lt;br/&gt;&lt;br/&gt;The goal of the xruby 0.1.0 is to pass all the tests in ruby's sample\test.rb,  and we are very close to the goal. Right now we still have a few failed tests to be fixed, the majority of them are serialization (Array#pack, Marshal) and eval related.  Most technical obstacles of compiling ruby have been solved, it just takes time to do the implementation (especially for the large amount of builtin libraries).&lt;br/&gt;&lt;br/&gt;2007 is going to be an exciting year:)&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt; &lt;style&gt;&lt;/style&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-2715483769101644330?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/2715483769101644330/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=2715483769101644330' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/2715483769101644330'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/2715483769101644330'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2007/01/xruby-010-will-be-released-in-january.html' title='XRuby 0.1.0 will be released in January, 2007'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-116171439809318822</id><published>2006-10-24T11:05:00.000-07:00</published><updated>2006-12-21T14:08:34.886-08:00</updated><title type='text'>XRuby Hacking Guide on wiki</title><content type='html'>Update 12/20/2006: As &lt;a href="http://google-code-updates.blogspot.com/2006/12/happy-holidays-open-source-developers.html"&gt;Google Code now provides Wiki by itself&lt;/a&gt;, I just move the project wiki over there as it is better integrated.&lt;br /&gt;&lt;br /&gt;Update 12/21/2006: Oops, now I regret what I did...Google Code only allow project members and owners add and edit wiki pages, which make it almost useless.&lt;br /&gt;&lt;br /&gt;Right now the only document we have is &lt;a href="http://code.google.com/p/xruby/wiki/XRubyHackingGuide"&gt;XRuby Hacking Guide&lt;/a&gt;. The goal of this guide is to help users/developers understand XRuby's implementation.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-116171439809318822?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/116171439809318822/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=116171439809318822' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/116171439809318822'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/116171439809318822'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2006/10/xruby-hacking-guide-on-wiki.html' title='XRuby Hacking Guide on wiki'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-115791288118067817</id><published>2006-09-10T10:51:00.000-07:00</published><updated>2006-09-10T11:47:31.796-07:00</updated><title type='text'>XRuby project is now hosted on Google Code</title><content type='html'>XRuby is an open source Ruby compiler which compiles Ruby source code (.rb) to Java bytecode (.class). On last Friday I moved the source code from my local Subversion server to Google Code(&lt;a href="http://code.google.com/p/xruby"&gt;code.google.com/p/xruby/&lt;/a&gt;), so the project is now public available (GPL license).&lt;br /&gt;&lt;br /&gt;Although I have never announced this project, I have been working on it for more than one year. This February I &lt;a href="http://seclib.blogspot.com/2006/02/first-release-of-rubyfront.html"&gt;made the parser public available&lt;/a&gt;, now the main effort is on the compiler backend (java bytecode generation). I expect to release the first stable version at the end of 2006.&lt;br /&gt;&lt;br /&gt;So far I am not very satisfied with my progress. I have a busy day job which has nothing related to Ruby and Java, so can only manage to work on XRuby about one hour a day(except weekends and holidays). When I started the project I thought XRuby is going to be the first ruby compiler in the world. But now &lt;a href="http://plas.fit.qut.edu.au/Ruby.NET/"&gt;Gardens Point Ruby.NET&lt;/a&gt; has released their first alpha version, and I expect JRuby will start to do their compiler in a few months (since &lt;a href="http://www.tbray.org/ongoing/When/200x/2006/09/07/JRuby-guys"&gt;they have been hired by Sun to work on JRuby full time&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;Anyway, the project gives me lots of fun and the implementation starts to gain momentum. It looks very promising to see the first stable release around this new year, stay tuned:)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-115791288118067817?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/115791288118067817/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=115791288118067817' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/115791288118067817'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/115791288118067817'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2006/09/xruby-project-is-now-hosted-on-google.html' title='XRuby project is now hosted on Google Code'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-115514731519460891</id><published>2006-08-09T10:37:00.000-07:00</published><updated>2006-09-12T12:07:00.903-07:00</updated><title type='text'>Operator overloading in ruby</title><content type='html'>Most operators in ruby (e.g. &lt;i&gt;+, -, *, /, %&lt;/i&gt; etc) are actually method calls, and they can be overloaded just like other method calls. But unlike C++, Ruby does not have operators like &lt;i&gt;+=, -=, *=, /=&lt;/i&gt; etc, so &lt;b&gt;a += 1&lt;/b&gt; is translated directly to &lt;b&gt;a = a + 1&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;This involves some performance penalty in some cases, for example:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;a1 = [1, 2, 3]&lt;br /&gt;a2 = [4, 5, 6]&lt;br /&gt;a1 += a2&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Behind the scenes, a new array is created (as a1 += a2 is equivalent to a1 = a1 + a2, operator + will create a new array, then a1 is assigned to hold the reference to the new array, and the old a1 will be garbage collected). If you just want to append a2 to a1, the following code is a little bit more efficient:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;a1.concat(a2)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;concat method will directly update the content of a1 without creating a new array.&lt;br /&gt;&lt;br /&gt;And it is surprising to know that not all ruby's operators are method calls, so you can not overload &lt;i&gt;!, not, &amp;&amp;, and, ||, or&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;UPDATE 09/12/2006: Chris pointed out an error in my original article(I shouldn't use &lt;&lt; operator as the alternative of +=), see comments for details. Thanks,  Chris!&lt;br /&gt;&lt;br /&gt;Reference:&lt;br /&gt;[1]&lt;a href="http://www.rubycentral.com/faq/rubyfaq-7.html#ss7.2"&gt;Are +, -, * ... operators?&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-115514731519460891?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/115514731519460891/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=115514731519460891' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/115514731519460891'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/115514731519460891'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2006/08/operator-overloading-in-ruby.html' title='Operator overloading in ruby'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-114642798657017194</id><published>2006-04-30T12:15:00.000-07:00</published><updated>2006-04-30T13:24:53.226-07:00</updated><title type='text'>Rubyfront 0.2.0 released</title><content type='html'>This new version of Rubyfront fixed a bug found when parsing Ruby on Rails 1.1.2. You can &lt;a href="http://xruby.com/Documents/rubyfront.zip"&gt;download the source code from here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;In rubyfront 0.2.0, I changed the way it handles &lt;a href="http://www.ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html#exprsub"&gt;expression substitution&lt;/a&gt;. The older versions of rubyfront ignores the content in expression substitution. For example, if the input is:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;"hello, #{name}"&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The lexer will first start to scan the input as a double quote string. After it sees "#{", it will go find the first '}' and think that is the end of the expression substitution. Unfortunately, expression substitution may contain '}' itself. For example:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;"begin #{1.times {"block"}} end"&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The lexer can not match the above input as one string. Expression substitution can contain any legal ruby program (compoundStatement), and only the parser understands the structure.&lt;br /&gt;&lt;br /&gt;To correctly handle this situation, the new lexer will suspend its state when the start of expression substitution is seen (only 'begin ' is matched so far). After the parser finishes its processing of expression substitution, it will notify the lexer and the lexer will resume its state and matches the rest of the string (' end').&lt;br /&gt;&lt;br /&gt;Btw, when you run parser smoke test against Ruby on Rails 1.1.2, you will see the following failures:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;C:\Documents and Settings\xxx\workspace\rubyfront&gt;build parsersmoketest&lt;br /&gt;&lt;...&gt;&lt;br /&gt;parsersmoketest:&lt;br /&gt;     [java] parser exception for C:\ruby\lib\ruby\gems\1.8\gems\activerecord-1.14.2\test\connections\native_sqlite3\in_memory_connection.rb: line 18:76: expecting EOF, found ')'&lt;br /&gt;     [java] parser exception for C:\ruby\lib\ruby\gems\1.8\gems\rails-1.1.2\environments\environment.rb: line 8:1: unexpected token: &lt;&lt;br /&gt;     [java] parser exception for C:\ruby\lib\ruby\gems\1.8\gems\rails-1.1.2\lib\rails_generator\generators\components\controller\templates\controller.rb: line 1:7: unexpected token: &lt;&lt;br /&gt;     [java] parser exception for C:\ruby\lib\ruby\gems\1.8\gems\rails-1.1.2\lib\rails_generator\generators\components\controller\templates\functional_test.rb: line 1:41: unexpected token: ..&lt;br /&gt;     [java] parser exception for C:\ruby\lib\ruby\gems\1.8\gems\rails-1.1.2\lib\rails_generator\generators\components\controller\templates\helper.rb: line 1:8: unexpected token: &lt;&lt;br /&gt;     [java] parser exception for C:\ruby\lib\ruby\gems\1.8\gems\rails-1.1.2\lib\rails_generator\generators\components\integration_test\templates\integration_test.rb: line 3:7: unexpected token: &lt;&lt;br /&gt;     [java] parser exception for C:\ruby\lib\ruby\gems\1.8\gems\rails-1.1.2\lib\rails_generator\generators\components\mailer\templates\mailer.rb: line 1:7: unexpected token: &lt;&lt;br /&gt;     [java] parser exception for C:\ruby\lib\ruby\gems\1.8\gems\rails-1.1.2\lib\rails_generator\generators\components\mailer\templates\unit_test.rb: line 4:7: unexpected token: &lt;&lt;br /&gt;     [java] parser exception for C:\ruby\lib\ruby\gems\1.8\gems\rails-1.1.2\lib\rails_generator\generators\components\migration\templates\migration.rb: line 1:7: unexpected token: &lt;&lt;br /&gt;     [java] parser exception for C:\ruby\lib\ruby\gems\1.8\gems\rails-1.1.2\lib\rails_generator\generators\components\model\templates\migration.rb: line 1:7: unexpected token: &lt;&lt;br /&gt;     [java] parser exception for C:\ruby\lib\ruby\gems\1.8\gems\rails-1.1.2\lib\rails_generator\generators\components\model\templates\model.rb: line 1:7: unexpected token: &lt;&lt;br /&gt;     [java] parser exception for C:\ruby\lib\ruby\gems\1.8\gems\rails-1.1.2\lib\rails_generator\generators\components\model\templates\unit_test.rb: line 1:41: unexpected token: ..&lt;br /&gt;     [java] parser exception for C:\ruby\lib\ruby\gems\1.8\gems\rails-1.1.2\lib\rails_generator\generators\components\plugin\templates\generator.rb: line 1:7: unexpected token: &lt;&lt;br /&gt;     [java] parser exception for C:\ruby\lib\ruby\gems\1.8\gems\rails-1.1.2\lib\rails_generator\generators\components\plugin\templates\unit_test.rb: line 3:7: unexpected token: &lt;&lt;br /&gt;     [java] parser exception for C:\ruby\lib\ruby\gems\1.8\gems\rails-1.1.2\lib\rails_generator\generators\components\scaffold\templates\controller.rb: line 1:7: unexpected token: &lt;&lt;br /&gt;     [java] parser exception for C:\ruby\lib\ruby\gems\1.8\gems\rails-1.1.2\lib\rails_generator\generators\components\scaffold\templates\functional_test.rb: line 5:7: unexpected token: &lt;&lt;br /&gt;     [java] parser exception for C:\ruby\lib\ruby\gems\1.8\gems\rails-1.1.2\lib\rails_generator\generators\components\scaffold\templates\helper.rb: line 1:8: unexpected token: &lt;&lt;br /&gt;     [java] parser exception for C:\ruby\lib\ruby\gems\1.8\gems\rails-1.1.2\lib\rails_generator\generators\components\session_migration\templates\migration.rb: line 1:7: unexpected token: &lt;&lt;br /&gt;     [java] parser exception for C:\ruby\lib\ruby\gems\1.8\gems\rails-1.1.2\lib\rails_generator\generators\components\web_service\templates\api_definition.rb: line 1:7: unexpected token: &lt;&lt;br /&gt;     [java] parser exception for C:\ruby\lib\ruby\gems\1.8\gems\rails-1.1.2\lib\rails_generator\generators\components\web_service\templates\controller.rb: line 1:7: unexpected token: &lt;&lt;br /&gt;     [java] parser exception for C:\ruby\lib\ruby\gems\1.8\gems\rails-1.1.2\lib\rails_generator\generators\components\web_service\templates\functional_test.rb: line 1:41: unexpected token: ..&lt;br /&gt;     [java] 2428 ruby programs have been parsed, 21 failed.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Those errors are expected as those files are in .rhtml format (not valid ruby, ROR requires erb to preprocess them).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-114642798657017194?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/114642798657017194/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=114642798657017194' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/114642798657017194'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/114642798657017194'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2006/04/rubyfront-020-released.html' title='Rubyfront 0.2.0 released'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-114532508004961452</id><published>2006-04-17T18:49:00.000-07:00</published><updated>2006-04-30T12:15:11.443-07:00</updated><title type='text'>Compile-time type inference for ruby has its limit</title><content type='html'>I have been thinking about doing type inference at compiler time for ruby. Whiles lots of the cases can be handled in a straightforward way, type inference won't work in all situations.&lt;br /&gt;&lt;br /&gt;One of the problems is, ruby supports multiple return types:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;def f&lt;br /&gt;  if rand(2) == 1&lt;br /&gt;       return 1&lt;br /&gt;  else&lt;br /&gt;       return "hello"&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In the above code, method 'f' will randomly return 1 (Fixnum) or "hello" (String). At compiler time there is no way for a compiler to know what type to return. All it can do is to insert meta data so that typing checking can be done at runtime.&lt;br /&gt;&lt;br /&gt;And multiple return types is not uncommon in real code. For example, Ruby' s array or hash can hold objects of different types:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  a = [1, 1.5, "hello"]&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In the above code, Array 'a' contains three different types of objects: Fixnum, Float and String. And element reference("[]") is an example of method that has multiple return types.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-114532508004961452?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/114532508004961452/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=114532508004961452' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/114532508004961452'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/114532508004961452'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2006/04/compile-time-type-inference-for-ruby.html' title='Compile-time type inference for ruby has its limit'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-114015291498261682</id><published>2006-02-16T20:55:00.000-08:00</published><updated>2006-04-30T12:14:53.660-07:00</updated><title type='text'>First release of Rubyfront</title><content type='html'>&lt;b&gt;UPDATE 02/27/2006: a new version of rubyfront was released, and now it is capable to parse ruby's stable snapshot and Ruby on Rails. Thanks Mauricio Fernandez for reporting the bugs.&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;I am glad to announce the first release of rubyfront (a &lt;a href="http://www.ruby-lang.org"&gt;ruby&lt;/a&gt; parser powered by &lt;a href="http://www.antlr.org"&gt;antlr&lt;/a&gt;), you can &lt;a href="http://xruby.com/Documents/rubyfront.zip"&gt;download it here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Overview&lt;/b&gt;&lt;br /&gt;The goal of this project is to create an error checking tool for ruby. Currently we are using antlr as the parser generator and java as the implementation language.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Current Status&lt;/b&gt;&lt;br /&gt;Even though Rubyfront is in its very early stage, the current parser can accept the entire ruby standard library. So far the parser only do error checking at syntax level, no semantic checking is implemented. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;What's next&lt;/b&gt;&lt;br /&gt;We will focus on improving the parser to make it closer to C ruby's yacc counterpart.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Requirement&lt;/b&gt;&lt;br /&gt;J2SE 5.0 and up.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Demonstration&lt;/b&gt;&lt;br /&gt;1. Open build.xml and change "rubycode.dir" to the directory of your ruby source code.&lt;br /&gt;2. Run the smoke test. On windows, you can simply type "build parsersmoketest".&lt;br /&gt;&lt;br /&gt;For example, if you have Ruby 1.8.4's source code installed on "c:\ruby", you are going to see the following:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;parsersmoketest:&lt;br /&gt; [java] 1574 ruby programs have been parsed, 0 failed.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The above result shows that all 1574 ruby programs are accepted by the parser.&lt;br /&gt;&lt;br /&gt;By the way, if you run smoke test against Ruby's windows One-Click installer, you are going to see a few failures from fxruby 1.2.6 and others. The good news is: they are known to be broken (You can use "ruby -c" to verify). If you have Ruby on Rails installed, you are going to see more failures. But all of the them are expected, since those are actually .rhtml files.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-114015291498261682?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/114015291498261682/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=114015291498261682' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/114015291498261682'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/114015291498261682'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2006/02/first-release-of-rubyfront.html' title='First release of Rubyfront'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-113682550193628710</id><published>2006-01-09T08:51:00.000-08:00</published><updated>2006-01-09T08:51:42.166-08:00</updated><title type='text'>Ruby interpreter crashes with invalid input</title><content type='html'>Last week I found a bug in ruby's parser, NULL pointer reference will happen when the following program is parsed:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;C:\ruby-1.8.4-i386-mswin32\bin&gt;ruby -e 'def a=.a=;end'&lt;br /&gt;-e:1: identifier a= is not valid&lt;br /&gt;-e:1: [BUG] Segmentation fault ruby 1.8.4 (2005-12-24) [i386-mswin32]&lt;br /&gt;This application has requested the Runtime to terminate it in an unusual way.&lt;br /&gt;Please contact the application's support team for more information.&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now it was fixed in CVS.&lt;br /&gt;&lt;br /&gt;This is not a serious security problem. I tried to find if it will result in a remote DOS vulnerability in Ruby on Rails, but find nothing.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-113682550193628710?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/113682550193628710/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=113682550193628710' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113682550193628710'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113682550193628710'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2006/01/ruby-interpreter-crashes-with-invalid.html' title='Ruby interpreter crashes with invalid input'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-113657207973442389</id><published>2006-01-06T09:58:00.000-08:00</published><updated>2006-01-06T10:32:31.326-08:00</updated><title type='text'>Why "undef" is keyword in ruby</title><content type='html'>&lt;a href="http://www.ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html#undef"&gt;undef&lt;/a&gt; is a &lt;a href="http://www.ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html#resword"&gt;keyword&lt;/a&gt; in ruby. But its syntax:&lt;br /&gt;"undef method-name (, method-name)*", looks just like a normal command call (function call without parameter, e.g. print "hello"). Then why not just implement it as a built-in method? As we know, "private", "protected" and "public", which are keywords in lots of other language, are &lt;a href="http://seclib.blogspot.com/2005/10/access-control-for-ruby-class.html"&gt;just implemented as plain method in ruby&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;What makes "undef" special is in attribute methods. In ruby we can define method like this:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;class A&lt;br /&gt;&amp;nbsp;&amp;nbsp;def a=(value)  &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;@value = value  &lt;br /&gt;&amp;nbsp;&amp;nbsp;end&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And later, we can undefine "a=" with "undef":&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;undef a=&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;"a=" is not a valid identifier(because of the '=') unless the parser is expecting a method name, for example, after "alias", "def" or "undef".&lt;br /&gt;&lt;br /&gt;Note ":a=" is valid &lt;a href="http://www.rubycentral.com/faq/rubyfaq-6.html#ss6.1"&gt;symbol&lt;/a&gt;. "private", "protected" and "public" are normal methods since they only accept symbols:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;class MyClass&lt;br /&gt;&lt;br /&gt;&amp;nbsp;  def method1&lt;br /&gt;&amp;nbsp;  end&lt;br /&gt;&lt;br /&gt;&amp;nbsp;  public :method1&lt;br /&gt;&amp;nbsp; #This is invalid: public method1&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Since "undef" is followed by method name, it has to be implemented as a keyword, so the parser/lexer knows when to change its state to accept the extra '='.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-113657207973442389?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/113657207973442389/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=113657207973442389' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113657207973442389'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113657207973442389'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2006/01/why-undef-is-keyword-in-ruby.html' title='Why &quot;undef&quot; is keyword in ruby'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-113476711658709728</id><published>2005-12-16T10:48:00.000-08:00</published><updated>2005-12-18T10:08:18.506-08:00</updated><title type='text'>MiniRails</title><content type='html'>Lots of people are using web technologies in their desktop applications, and it is especially common to find a windows application which embeds &lt;a href="msdn.microsoft.com/workshop/ browser/WebBrowser/WebBrowser.asp"&gt;WebBrowser control&lt;/a&gt; to render great GUI elements. There are some bumps, for example, you can not do disk/socket IO with javascript(even java applet), which most applications have to reply on.&lt;br /&gt;&lt;br /&gt;To overcome this, we can either use ActiveX control(I am using it myself and am satisfied with it), or launch a web server on the background. The second has an additional advantage: the server and client are decoupled, so in the future you can easily migrate to a pure web environment without touching too much code. While this approach looks attractive, however, we have to face a reality: most web application servers can be too big for most desktop applications to distribute. Note I am taking web application servers here, not simple web servers. It is easy to find a small footprint web server or even write one by yourself, but your development style will have to go back to the 80s (CGI in C). Even though &lt;a href="http://www.onjava.com/pub/a/onjava/2002/04/03/tomcat.html"&gt;Tomcat Embedded&lt;/a&gt; 5.5.12 can be downloaded as a 3.1 MB zip file, your customers may not have JVM installed in the first place. &lt;a href="http://msdn.microsoft.com/msdnmag/issues/03/01/cuttingedge/"&gt;Cassini&lt;/a&gt; suffers the same problem, Microsoft has not pushed hard enough to make .NET universal.&lt;br /&gt;&lt;br /&gt;How about the &lt;a href="http://www.rubyonrails.org"&gt;Ruby on Rails&lt;/a&gt;? It turns out to be a great choice. While a complete distribution takes lots of disk space, it is easy to customize so that we only ship what we need.&lt;br /&gt;&lt;br /&gt;Here is how I build my minimum ruby distribution that rail can run on(use windows as example):&lt;br /&gt;&lt;br /&gt;1. Have &lt;a href="http://rubyforge.org/FRS/?group_id=167"&gt;ruby&lt;/a&gt; installed to C:\ruby. Later we need to copy files from it.&lt;br /&gt;&lt;br /&gt;2. Download rails &lt;a href="http://rubyforge.org/frs/?group_id=307"&gt;stand-alone packages&lt;/a&gt;, uncompress it to C:\rails, and empty doc/ folder to save space.&lt;br /&gt;&lt;br /&gt;3. Copy ruby.exe and msvcrt-ruby18.dll from C:\ruby\bin to C:\rails.&lt;br /&gt;&lt;br /&gt;4. Copy the following OS independent libraries (implemented in pure ruby) from C:\ruby\lib\ruby\1.8 to C:\rails\lib\ruby\1.8:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt; base64.rb&lt;br /&gt; benchmark.rb&lt;br /&gt; cgi.rb and cgi/&lt;br /&gt; date.rb&lt;br /&gt; date/format.rb&lt;br /&gt; delegate.rb&lt;br /&gt; drb.rb and drb/&lt;br /&gt; e2mmap.rb&lt;br /&gt; erb.rb&lt;br /&gt; English.rb&lt;br /&gt; fileutils.rb&lt;br /&gt; ipaddr.rb&lt;br /&gt; irb.rb and irb/&lt;br /&gt; kconv.rb&lt;br /&gt; logger.rb&lt;br /&gt; mutex_m.rb&lt;br /&gt; net/http.rb&lt;br /&gt; net/protocol.rb&lt;br /&gt; net/smtp.rb&lt;br /&gt; observer.rb&lt;br /&gt; optparse.rb and optparse/&lt;br /&gt; parsedate.rb&lt;br /&gt; pathname.rb&lt;br /&gt; pstore.rb&lt;br /&gt; rational.rb&lt;br /&gt; rexml.rb and rexml/&lt;br /&gt; set.rb&lt;br /&gt; singleton.rb&lt;br /&gt; soap.rb and soap/&lt;br /&gt; tempfile.rb&lt;br /&gt; thread.rb&lt;br /&gt; time.rb&lt;br /&gt; timeout.rb&lt;br /&gt; tmpdir.rb&lt;br /&gt; uri.rb and uri/&lt;br /&gt; webrick.rb and webrick/&lt;br /&gt; xmlrpc/&lt;br /&gt; xsd/&lt;br /&gt; yaml.rb and yaml/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;5. Copy the following OS dependent libraries from C:\ruby\lib\ruby\1.8\i386-mswin32 to C:\rails\lib\ruby\1.8\i386-mswin32:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt; digest.so&lt;br /&gt; digest/md5.so&lt;br /&gt; digest/sha1.so &lt;br /&gt; fcntl.so&lt;br /&gt; nkf.so&lt;br /&gt; rbconfig.rb&lt;br /&gt; socket.so&lt;br /&gt; strscan.so&lt;br /&gt; stringio.so&lt;br /&gt; syck.so&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;6. Now we may still need a database (optional). Here is how I get sqlite3 installed:&lt;br /&gt;a) Download &lt;a href="http://www.sqlite.org/download.html"&gt;precompiled binaries&lt;/a&gt;. Copy sqlite3.exe and sqlite3.dll into C:\rails folder.&lt;br /&gt;b) Download &lt;a href="http://rubyforge.org/frs/?group_id=254"&gt;SQLite-Ruby&lt;/a&gt;. Copy sqlite3_api.so to C:\rails\lib\ruby\site_ruby\1.8\i386-msvcrt\,  copy sqlite3.rb and sqlite3/ to C:\rails\lib\ruby\site_ruby\1.8&lt;br /&gt;That's it! You can start WEBrick now:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;C:\rails&gt;ruby script\server&lt;br /&gt;=&gt; Booting WEBrick...&lt;br /&gt;=&gt; Rails application started on http://0.0.0.0:3000&lt;br /&gt;=&gt; Ctrl-C to shutdown server; call with --help for options&lt;br /&gt;[2005-12-16 15:23:09] INFO  WEBrick 1.3.1&lt;br /&gt;[2005-12-16 15:23:09] INFO  ruby 1.8.2 (2004-12-25) [i386-mswin32]&lt;br /&gt;[2005-12-16 15:23:09] INFO  WEBrick::HTTPServer#start: pid=440 port=3000&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And do whatever rails developement as you want.&lt;br /&gt;&lt;br /&gt;This distribution takes 6.28M on disk. If you zip it, it shrinks to a 2.3M file.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-113476711658709728?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/113476711658709728/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=113476711658709728' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113476711658709728'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113476711658709728'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/12/minirails.html' title='MiniRails'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-113451991329352684</id><published>2005-12-13T15:55:00.000-08:00</published><updated>2006-01-30T14:52:56.416-08:00</updated><title type='text'>Good experience with boost memory pool</title><content type='html'>With increasing number of source code to compile, the compiler I maintain becomes unacceptable slow. After profiling the code with &lt;a href="http://www.automatedqa.com/products/aqtime/"&gt;AQTime&lt;/a&gt;, I found about 30% percent CPU is used by malloc(), and half of them are for tree node allocation(fixed size).&lt;br /&gt;&lt;br /&gt;After &lt;a href="http://seclib.blogspot.com/2005/12/compare-performance-of-malloc-and.html"&gt;testing the performance of boost memory pool&lt;/a&gt;, I simply replaced malloc() with boost::object_pool::malloc().  The result is great, it almost eliminated the cost of tree node allocation. The total amount of time used for malloc is down to 13%. Still plenty of room for improvement, but the performance is at least acceptable.&lt;br /&gt;&lt;br /&gt;There is one thing to remember: boost::object_pool is designed for "allocate many objects and then destroy all of them" type of scenario, so freeing memory from the pool can be very slow. For example, at the beginning I also replaced free() with boost::object_pool::free(), which make the performance even worse: boost::simple_segregated_storage&lt;unsigned int&gt;::find_prev() and boost::simple_segregated_storage&lt;unsigned int&gt;::nextof() start to take over all the CPU. So I do not do free anymore and simply let ~object_pool() to release the memory. This works perfect for my compiler, but may not be good for other applications.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-113451991329352684?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/113451991329352684/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=113451991329352684' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113451991329352684'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113451991329352684'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/12/good-experience-with-boost-memory-pool.html' title='Good experience with boost memory pool'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-113444484337922412</id><published>2005-12-12T18:55:00.000-08:00</published><updated>2005-12-12T19:34:05.363-08:00</updated><title type='text'>Scope of a local variable in ruby</title><content type='html'>In ruby, only class, module and method can introduce new scope (see &lt;a href="http://www.rubycentral.com/faq/rubyfaq-4.html#ss4.2"&gt;Ruby FAQ&lt;/a&gt;). Even if ruby has "if .. end", "while ... end" constructs, unlike c/c++/java/c#, they won't create new scope.&lt;br /&gt;&lt;br /&gt;For example:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;if true&lt;br /&gt;&amp;nbsp;&amp;nbsp;x = "hello"&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;# we can access x outside of "if". This will print "hello".&lt;br /&gt;puts x&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;While there might be other motivations for this design, I think it is most likely driven by a technical issue: as I wrote &lt;a href="http://seclib.blogspot.com/2005/11/more-on-leftshift-and-heredoc.html"&gt;before&lt;/a&gt;, ruby's lexer need to distinguish local variable and method call(command). It is easy for it to check "module", "class" and "def" keyword to recognize a new scope. However, as for "if", "while" etc (may followed by a complex expression), it is too hard for the lexer to handle (requires serious parsing capability).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-113444484337922412?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/113444484337922412/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=113444484337922412' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113444484337922412'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113444484337922412'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/12/scope-of-local-variable-in-ruby.html' title='Scope of a local variable in ruby'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-113399785539699474</id><published>2005-12-07T15:23:00.000-08:00</published><updated>2005-12-07T15:31:08.613-08:00</updated><title type='text'>Compare performance of malloc and boost::pool</title><content type='html'>Andrei Gorine and Konstantin Knizhnik wrote a great article on Dr. Dobb's Journal titled &lt;a href="http://devnet.developerpipeline.com/documents/s=9849/q=1/ddj0512m/0512m.html"&gt;Memory Management &amp;amp; Embedded Databases&lt;/a&gt;. In this article, they examine several memory-allocation strategies, explained the advantages/disadvantages based on their experience creating the eXtremeDB in-memory database.&lt;br /&gt;&lt;br /&gt;As we know it is normal for malloc/free(new/delete) to take 10-20 percent of the CPU time of an application. Sometime it is nice to have a memory pool to handle some fixed size allocation, especially when you have &lt;a href="http://www.boost.org/libs/pool/doc/index.html"&gt;Boost Pool Library&lt;/a&gt; for free.&lt;br /&gt;&lt;br /&gt;I wrote a small program, which creates a small and simple data structure on heap a million times to benchmark malloc and boost::object_pool, and the result shows boost::object_pool is a clear winner. I also tried to compare with new operator, even though there is no constructor for the dummy data structure. The difference between malloc and new in this case is insignificant.&lt;br /&gt;&lt;br /&gt;The result also shows something interesting which have been mentioned in &lt;a href="http://blogs.msdn.com/oldnewthing/"&gt;Raymond Chen's&lt;/a&gt; "5 Things Every Win32 Developer Should Know" PDC 2005 talk. If boost::object_pool is used as a pointer, the performance hurts a lot, even through still way faster than malloc.&lt;br /&gt;&lt;br /&gt;Here is the result on my laptop (Windows XP, VC 2003 release build, P4 2.4G, 512M):&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;alloc_with_new_array:   26 microseconds&lt;br /&gt;alloc_with_malloc_array:        11 microseconds&lt;br /&gt;alloc_with_new: 365120 microseconds&lt;br /&gt;alloc_with_malloc:      351586 microseconds&lt;br /&gt;alloc_with_boost_pool_construct:        7852 microseconds&lt;br /&gt;alloc_with_boost_pool_malloc:   3371 microseconds&lt;br /&gt;alloc_with_boost_pool_malloc_use_pointer:       11751 microseconds&lt;br /&gt;alloc_with_boost_pool_malloc_use_reference:     3383 microseconds&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Here is code:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;#include &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;boost&lt;FONT COLOR=BLUE SIZE=+1&gt;/&lt;/FONT&gt;pool&lt;FONT COLOR=BLUE SIZE=+1&gt;/&lt;/FONT&gt;object_pool&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;hpp&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;struct&lt;/B&gt;&lt;/FONT&gt; dummy_data&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;int&lt;/B&gt;&lt;/FONT&gt; a&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;int&lt;/B&gt;&lt;/FONT&gt; b&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;inline&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;void&lt;/B&gt;&lt;/FONT&gt; alloc_with_new&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;size_t size&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; dummy_data&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt; p&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;for&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;size_t i &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt; i &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt; size&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;+&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;+&lt;/FONT&gt;&lt;/FONT&gt;i&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  p &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;new&lt;/B&gt;&lt;/FONT&gt; dummy_data&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;delete&lt;/B&gt;&lt;/FONT&gt; p&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;inline&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;void&lt;/B&gt;&lt;/FONT&gt; alloc_with_malloc&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;size_t size&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; dummy_data&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt; p&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;for&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;size_t i &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt; i &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt; size&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;+&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;+&lt;/FONT&gt;&lt;/FONT&gt;i&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  p &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;dummy_data&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;malloc&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;sizeof&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;dummy_data&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  free&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;p&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;inline&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;void&lt;/B&gt;&lt;/FONT&gt; alloc_with_boost_pool_construct&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;size_t size&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; boost&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;object_pool&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;dummy_data&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt; pool&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; dummy_data&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt; p&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;for&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;size_t i &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt; i &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt; size&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;+&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;+&lt;/FONT&gt;&lt;/FONT&gt;i&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  p &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; pool&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;construct&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  pool&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;destroy&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;p&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;inline&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;void&lt;/B&gt;&lt;/FONT&gt; alloc_with_boost_pool_malloc&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;size_t size&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; boost&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;object_pool&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;dummy_data&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt; pool&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; dummy_data&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt; p&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;for&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;size_t i &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt; i &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt; size&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;+&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;+&lt;/FONT&gt;&lt;/FONT&gt;i&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  p &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; pool&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;malloc&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  pool&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;free&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;p&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;inline&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;void&lt;/B&gt;&lt;/FONT&gt; alloc_with_boost_pool_malloc_use_pointer&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;size_t size&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; boost&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;object_pool&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;dummy_data&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt; pool &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;new&lt;/B&gt;&lt;/FONT&gt; boost&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;object_pool&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;dummy_data&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; dummy_data&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt; p&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;for&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;size_t i &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt; i &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt; size&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;+&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;+&lt;/FONT&gt;&lt;/FONT&gt;i&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  p &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; pool&lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;malloc&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  pool&lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;free&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;p&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;delete&lt;/B&gt;&lt;/FONT&gt; pool&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;inline&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;void&lt;/B&gt;&lt;/FONT&gt; alloc_with_boost_pool_malloc_use_reference&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;size_t size&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; boost&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;object_pool&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;dummy_data&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt; _pool&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; boost&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;object_pool&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;dummy_data&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt; pool &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; _pool&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; dummy_data&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt; p&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;for&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;size_t i &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt; i &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt; size&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;+&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;+&lt;/FONT&gt;&lt;/FONT&gt;i&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  p &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; pool&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;malloc&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  pool&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;free&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;p&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;inline&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;void&lt;/B&gt;&lt;/FONT&gt; alloc_with_new_array&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;size_t size&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; dummy_data&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt; p &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;new&lt;/B&gt;&lt;/FONT&gt; dummy_data&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;[&lt;/B&gt;&lt;/FONT&gt;size&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;]&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;delete&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;[&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;]&lt;/B&gt;&lt;/FONT&gt; p&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;inline&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;void&lt;/B&gt;&lt;/FONT&gt; alloc_with_malloc_array&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;size_t size&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; dummy_data&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt; p &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;dummy_data&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;malloc&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;sizeof&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;dummy_data&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt; size&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; free&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;p&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;int&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;main&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;int&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;char&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; LARGE_INTEGER freq&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; t0&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; t1&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; QueryPerformanceFrequency&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;freq&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; size_t number &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;1000000&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; QueryPerformanceCounter&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;t0&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; alloc_with_new_array&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;number&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; QueryPerformanceCounter&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;t1&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; printf&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"alloc_with_new_array: %d microseconds\n"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;t1.QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;t0.QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt;&lt;FONT COLOR=BROWN&gt;1000000&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;/&lt;/FONT&gt;freq&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; QueryPerformanceCounter&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;t0&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; alloc_with_malloc_array&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;number&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; QueryPerformanceCounter&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;t1&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; printf&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"alloc_with_malloc_array: %d microseconds\n"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;t1.QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;t0.QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt;&lt;FONT COLOR=BROWN&gt;1000000&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;/&lt;/FONT&gt;freq&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; QueryPerformanceCounter&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;t0&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; alloc_with_new&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;number&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; QueryPerformanceCounter&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;t1&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; printf&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"alloc_with_new: %d microseconds\n"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;t1.QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;t0.QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt;&lt;FONT COLOR=BROWN&gt;1000000&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;/&lt;/FONT&gt;freq&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; QueryPerformanceCounter&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;t0&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; alloc_with_malloc&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;number&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; QueryPerformanceCounter&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;t1&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; printf&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"alloc_with_malloc: %d microseconds\n"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;t1.QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;t0.QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt;&lt;FONT COLOR=BROWN&gt;1000000&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;/&lt;/FONT&gt;freq&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; QueryPerformanceCounter&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;t0&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; alloc_with_boost_pool_construct&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;number&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; QueryPerformanceCounter&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;t1&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; printf&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"alloc_with_boost_pool_construct: %d microseconds\n"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;t1.QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;t0.QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt;&lt;FONT COLOR=BROWN&gt;1000000&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;/&lt;/FONT&gt;freq&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; QueryPerformanceCounter&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;t0&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; alloc_with_boost_pool_malloc&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;number&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; QueryPerformanceCounter&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;t1&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; printf&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"alloc_with_boost_pool_malloc: %d microseconds\n"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;t1.QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;t0.QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt;&lt;FONT COLOR=BROWN&gt;1000000&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;/&lt;/FONT&gt;freq&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; QueryPerformanceCounter&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;t0&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; alloc_with_boost_pool_malloc_use_pointer&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;number&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; QueryPerformanceCounter&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;t1&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; printf&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"alloc_with_boost_pool_malloc_use_pointer: %d microseconds\n"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;t1.QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;t0.QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt;&lt;FONT COLOR=BROWN&gt;1000000&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;/&lt;/FONT&gt;freq&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; QueryPerformanceCounter&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;t0&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; alloc_with_boost_pool_malloc_use_reference&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;number&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; QueryPerformanceCounter&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;t1&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; printf&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"alloc_with_boost_pool_malloc_use_reference: %d microseconds\n"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;t1.QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;t0.QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt;&lt;FONT COLOR=BROWN&gt;1000000&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;/&lt;/FONT&gt;freq&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;QuadPart&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;return&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-113399785539699474?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/113399785539699474/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=113399785539699474' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113399785539699474'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113399785539699474'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/12/compare-performance-of-malloc-and.html' title='Compare performance of malloc and boost::pool'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-113347049740872822</id><published>2005-12-01T12:24:00.000-08:00</published><updated>2005-12-02T08:19:15.746-08:00</updated><title type='text'>Programming and playing chess</title><content type='html'>There are lots of things in common between leaning how to program and leaning how to play chess:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;First, you need to leaning the rules&lt;/b&gt;&lt;br /&gt;For programming, the rules are the grammar of your language of choice. You can not hit the road without knowing them, but this is the easiest part.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Nothing can replace realworld experience&lt;/b&gt;&lt;br /&gt;That's why some gurus claim building software is a craftsmanship rather than engineering. While there are tons of tools, smart IDEs to assist you, software design masters reach their level by years of practicing.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Pattern is shortcut&lt;/b&gt;&lt;br /&gt;Then how do we improve ourselves quicker? Lots of people know how to play chess and keep playing for years, but have very little improvement on their skills. Well, if you do not know it yet, patterns can be the shortcut. If you study how chess masters deal with common scenarios, you will improve much faster than your friends how do not.&lt;br /&gt;&lt;br /&gt;So far, it is all about individuals. Multiplayer game is much more complicated, and so is professional software developement in corporate.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-113347049740872822?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/113347049740872822/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=113347049740872822' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113347049740872822'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113347049740872822'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/12/programming-and-playing-chess.html' title='Programming and playing chess'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-113332962905192724</id><published>2005-11-29T21:11:00.000-08:00</published><updated>2005-11-29T22:03:53.986-08:00</updated><title type='text'>More on leftshift and heredoc</title><content type='html'>A few weeks ago I wrote something on &lt;a href="http://seclib.blogspot.com/2005/11/distinguish-leftshift-and-heredoc.html"&gt;distinguishing between leftshift and heredoc in ruby lexer&lt;/a&gt;. Even though I knew how things work in theory, during the implementation I found out quite a lot complicated cases, and to handle all of them requires a complete symbol table, which is something I try to avoid right now.&lt;br /&gt;&lt;br /&gt;Today I spent a few hours on trying examples and reading ruby's source code, and finally decoded the rules (it turns out to be much simpler than I thought).&lt;br /&gt;&lt;br /&gt;Now let me show you how it works. Suppose the lexer is going to tokenize the following line:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;x&amp;lt;&amp;lt;blahblah&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Obviously, "x" is an IDENTIFIER, but what about "&lt;&lt;"? Is it a SHIFT operator or the start of HEREDOC? Well, sometime you can do it at syntax level. In the above case, since there is &lt;b&gt;no whitespace between "x" and "&lt;&lt;"&lt;/b&gt;, ruby always treated "&lt;&lt;" as shift operator.&lt;br /&gt;&lt;br /&gt;Then let's move on to another example:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;x&amp;nbsp;&amp;nbsp;&amp;lt;&amp;lt;blahblah&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As you can see the only difference is that we put space between "x" and "&lt;&lt;". Now comes rule 2: if "x" is a variable, "&lt;&lt;" becomes SHIFT operator, if "x" is a method, "&lt;&lt;" and the following will be treated as HEREDOC. As you can see, ruby will choose the way that makes most sense. But how do we know whether "x" is a method or not? Well, sometime it is easy: if "x" looks like "a.b.c" (notice the DOT), then it is always a method. Otherwise, we need a symbol table to lookup.&lt;br /&gt;&lt;br /&gt;And there is a trick when implementing the symbol table: you can not put only methods in it and later check if a simple IDENTIFIER is indeed a method. It does not work for two reasons: 1) The method you called may not be defined yet; 2) The method may be defined in an included module and you do not want to parse them here. So how do we do it? Simply store the local variables in the symbol table: if a simple IDENTIFIER is not a local variable, then it must be a method.&lt;br /&gt;&lt;br /&gt;The above rules make lexer implementation easy. Originally I thought I need to check the number of parameters of a method to get more accurate predict, but that is too much for a lexer.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-113332962905192724?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/113332962905192724/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=113332962905192724' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113332962905192724'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113332962905192724'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/11/more-on-leftshift-and-heredoc.html' title='More on leftshift and heredoc'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-113322346682005482</id><published>2005-11-28T16:01:00.000-08:00</published><updated>2005-11-28T17:46:17.836-08:00</updated><title type='text'>Entertainment Reward Scam</title><content type='html'>Purchasing a ticket on TicketMaster in last November made me a member of so called "Entertainment Reward" program, and they started to charge $9 from my credit card each month. They deliberately make the process unnoticable during the purchase. If my coworker did not break the news, I might no even know I was in the trap.&lt;br /&gt;&lt;br /&gt;A quick search on google shows there are lots of people who are scamed, and now there is a website for sharing the stoies: &lt;a href="http://www.entertainmentrewardscam.com/"&gt;www.entertainmentrewardscam.com&lt;/a&gt;. So be careful, better don't do business with those unethical companies.&lt;br /&gt;&lt;br /&gt;Shame on TicketMaster and Entertainment Reward!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-113322346682005482?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/113322346682005482/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=113322346682005482' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113322346682005482'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113322346682005482'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/11/entertainment-reward-scam.html' title='Entertainment Reward Scam'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-113157410176470122</id><published>2005-11-09T13:59:00.000-08:00</published><updated>2005-11-09T14:10:00.280-08:00</updated><title type='text'>Does pure OO matter?</title><content type='html'>Ruby is a pure OO language, in other words, it has no functions. Even if a "def" statement outside of a class definition looks and behaves like a function, it is actually a private methods of class Object.&lt;br /&gt;&lt;br /&gt;You may ask, is this just an implementation details? Well, most of the time it doesn't matter, people can ignore the difference and use those methods as functions -- no problem at all. It only matters when you use introspect(reflection). For example, the following code:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;def my_global_function&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;puts Object.private_methods&lt;br /&gt;&lt;/pre&gt; &lt;br /&gt;&lt;br /&gt;will print:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;...&lt;br /&gt;my_global_function&lt;br /&gt;exit&lt;br /&gt;putc&lt;br /&gt;system&lt;br /&gt;...&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Reference:&lt;br /&gt;[0] &lt;a href="http://www.rubygarden.org/faq/entry/show/14"&gt;Ruby FAQ: How Does Ruby Compare With Python?&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-113157410176470122?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/113157410176470122/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=113157410176470122' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113157410176470122'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113157410176470122'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/11/does-pure-oo-matter_09.html' title='Does pure OO matter?'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-113108105100258555</id><published>2005-11-03T21:10:00.000-08:00</published><updated>2005-11-03T21:15:24.610-08:00</updated><title type='text'>Linear approximate lookahead</title><content type='html'>Even though we talk &lt;a href="http://www.antlr.org"&gt;antlr&lt;/a&gt; as a LL(k) parser generator for simplicity, it actually does &lt;a href="http://www.antlr.org/doc/glossary.html#Linear_approximate_lookahead"&gt;linear approximate lookahead&lt;/a&gt; instead of full LL(k).&lt;br /&gt;Most of the time this is a good thing, because it reduces the complexity of storing and testing lookahead (from exponential to linear reduction). But occasionally the weaker lookahead is insufficient and results in nondeterministic parser/lexer.&lt;br /&gt;Here is an example to illustrate the problem:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;RULE1&lt;br /&gt;&amp;nbsp;&amp;nbsp; : "ab" | "ba"&lt;br /&gt;&amp;nbsp;&amp;nbsp; ;&lt;br /&gt;&lt;br /&gt;RULE2&lt;br /&gt;&amp;nbsp;&amp;nbsp; : "ac" | "ca"&lt;br /&gt;&amp;nbsp;&amp;nbsp; ;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The above is prefect LL(2) grammar, but &lt;a href="http://www.antlr.org"&gt;antlr&lt;/a&gt; will give you a warning:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;[antlr] test.g: warning:lexical nondeterminism between rules RULE1 and RULE2 upon&lt;br /&gt;[antlr] test.g:     k==1:'a'&lt;br /&gt;[antlr] test.g:     k==2:'a'&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;If you look at the generated code, soon you will realized this is because of linear approximate lookahead:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;else if ((LA(1)=='a'||LA(1)=='b') &amp;&amp; (LA(2)=='a'||LA(2)=='b')) {&lt;br /&gt;&amp;nbsp;&amp;nbsp; ...//match RULE1&lt;br /&gt;}&lt;br /&gt;else if ((LA(1)=='a'||LA(1)=='c') &amp;&amp; (LA(2)=='a'||LA(2)=='c')) {&lt;br /&gt;&amp;nbsp;&amp;nbsp; ...//match RULE2&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;If the input is "aa", even though it does not match any of the two rules, both tests will be true, and that is what the nondeterminism warning trying to tell you.&lt;br /&gt;&lt;br /&gt;A full LL(k) parser generator should generate the following code instead:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;else if ((LA(1)=='a'&amp;&amp;LA(2)=='b') || (LA(1)=='b'&amp;&amp;LA(2)=='a')) {&lt;br /&gt;&amp;nbsp;&amp;nbsp; ...//match RULE1&lt;br /&gt;}&lt;br /&gt;else if ((LA(1)=='a'&amp;&amp;LA(2)=='c') || (LA(1)=='c'&amp;&amp;LA(2)=='a')) {&lt;br /&gt;&amp;nbsp;&amp;nbsp; ...//match RULE2&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-113108105100258555?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/113108105100258555/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=113108105100258555' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113108105100258555'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113108105100258555'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/11/linear-approximate-lookahead.html' title='Linear approximate lookahead'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-113088616982958479</id><published>2005-11-01T15:02:00.000-08:00</published><updated>2005-11-03T08:47:11.633-08:00</updated><title type='text'>Distinguish leftshift and heredoc</title><content type='html'>I am working on a ruby parser with antlr. Last weekend I tested my ruby lexer on lots of realworld ruby scripts, and found an interesting problem. That is, how to distinguish left shift operator and "here document(heredoc)"?&lt;br /&gt;&lt;br /&gt;As we know, "&amp;lt;&amp;lt;" is left shift operator in lots of computer languages. In perl and ruby, it is also the start of heredoc. For those of you who do not have unix shell script/perl/ruby background, heredoc acts like a string, but with flexibility. Here is an example in ruby:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;str = &amp;lt;&amp;lt;EOF&lt;br /&gt;hello, world!&lt;br /&gt;EOF&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Since perl/ruby choose not to introduce a new symbol for the start of heredoc, their parser developers have to deal with the ambiguity. I tried to find out a simple solution, but later found out the ambiguity can not be solved at syntax level.&lt;br /&gt;&lt;br /&gt;For example, in the following code, "&amp;lt;&amp;lt;" should be parsed as the start of heredoc:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;def x(var)&lt;br /&gt;&amp;nbsp;&amp;nbsp;puts var&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;x &amp;lt;&amp;lt;1&lt;br /&gt;test&lt;br /&gt;1&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;But in another case, "&amp;lt;&amp;lt;" should be parsed as left shift operator:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;x = 1&lt;br /&gt;&lt;br /&gt;x &amp;lt;&amp;lt;1&lt;br /&gt;test&lt;br /&gt;1&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The only difference is: in the first case, x is a method, while in the second case x is a variable. So there is no other choice, we have to look up symbol table to decide lexer state.&lt;br /&gt;&lt;br /&gt;Today I checked the source code of ruby 1.8.3. No surprise, it uses the same approach.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-113088616982958479?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/113088616982958479/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=113088616982958479' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113088616982958479'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113088616982958479'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/11/distinguish-leftshift-and-heredoc.html' title='Distinguish leftshift and heredoc'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-113047363670538908</id><published>2005-10-27T21:13:00.000-07:00</published><updated>2005-10-27T21:32:12.520-07:00</updated><title type='text'>ngen</title><content type='html'>As mentioned in &lt;a href="http://msdn.microsoft.com/msdnmag/issues/05/04/NGen/default.aspx"&gt;Reid Wilkes's article on MSDN Magazine (April 2005)&lt;/a&gt;, Microsoft has always used NGen on its own core Framework assemblies at .NET Framework installation time.&lt;br /&gt;Here is screen capture during my installtion of .NET 2.0 (the installer spent quite a lot time doing ngen):&lt;br /&gt;&lt;br /&gt;&lt;a href="http://photos1.blogger.com/blogger/7129/802/1600/ngen.1.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;" src="http://photos1.blogger.com/blogger/7129/802/400/ngen.jpg" border="0" alt="" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-113047363670538908?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/113047363670538908/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=113047363670538908' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113047363670538908'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113047363670538908'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/10/ngen.html' title='ngen'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-113046436711228418</id><published>2005-10-27T18:52:00.000-07:00</published><updated>2006-06-01T08:53:33.933-07:00</updated><title type='text'>Do not disable "DCOM Server Process Launcher" service</title><content type='html'>DCOM Server Process Launcher is a new service introduced in windows XP SP2. It plays a very important role on the system, and will start other "manual" services when necessary. Since it is relatively new and the documentation about it is poor, some people believe this service is useless and disabled it.&lt;br /&gt;&lt;br /&gt;I have experienced several weird problems when the service is not started:&lt;br /&gt;&lt;br /&gt;1. Watir scripts won't run, Ruby reports "Failed to create WIN32OLE object from `InternetExplorer.Application' (WIN32OLERuntimeError)&lt;br /&gt;    HRESULT error code:0x800706ba The RPC server is unavailable.".&lt;br /&gt;&lt;br /&gt;2. Symantec Antivirus LiveUpdate fails with LU1803 error.  All the workarounds on the web do not help.&lt;br /&gt;&lt;br /&gt;3. Most installers won't run with "RPC server is unavailable" error message. Although you can fix that by starting "Windows Installer" service manually.&lt;br /&gt;&lt;br /&gt;If you have the same problems, first check if its startup type is "Automatic".&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-113046436711228418?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/113046436711228418/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=113046436711228418' title='18 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113046436711228418'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/113046436711228418'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/10/do-not-disable-dcom-server-process.html' title='Do not disable &quot;DCOM Server Process Launcher&quot; service'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>18</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-112952128578430305</id><published>2005-10-16T20:54:00.000-07:00</published><updated>2005-10-16T20:59:17.766-07:00</updated><title type='text'>Let watir do the job</title><content type='html'>AutoLinking is a very convenience feature for almost every blog writer. For example, when you are writing about antlr, you may want to give a link to www.antlr.org, and a smart blog authoring tool should be able to do that for you. But as &lt;a href="http://wesnerm.blogs.com/net_undocumented/2005/10/autolinking.html"&gt; Wesner Moise mentioned on his blog&lt;/a&gt; , currently no blog-posting tool provides that service.  &lt;br /&gt;&lt;br /&gt;So I wrote a &lt;a href="http://wtr.rubyforge.org"&gt;watir&lt;/a&gt; script(Watir is a great web application testing framework in Ruby) to help me. First it uses regular expression to do autolinking, then go to the website and publish the post (so I do not have to click all the links and wait for a reply). &lt;br /&gt;&lt;br /&gt;Here is the code:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;require 'watir'&lt;br /&gt;include Watir &lt;br /&gt;&lt;br /&gt;#Start your writing here&lt;br /&gt;title = "Let watir do the job"&lt;br /&gt;content = &amp;lt;&amp;lt;EOF&lt;br /&gt;I love watir !&lt;br /&gt;EOF&lt;br /&gt;&lt;br /&gt;#Polish and Autolinking etc&lt;br /&gt;content = content.gsub(/\n/, ' ') #replace linebreak with whitespace &lt;br /&gt;content = content.gsub(/\bwatir\b/, '&amp;lt;a href="http://wtr.rubyforge.org"&gt;watir&amp;lt;/a&amp;gt;')&lt;br /&gt;&lt;br /&gt;#Go to the website&lt;br /&gt;ie = IE.new&lt;br /&gt;ie.goto("http://www.blogger.com/start") &lt;br /&gt;&lt;br /&gt;#Login&lt;br /&gt;ie.text_field(:name, "username").set("yourusrename")&lt;br /&gt;ie.text_field(:name, "password").set("yourpassword")&lt;br /&gt;ie.link(:text, "Sign in").click&lt;br /&gt;&lt;br /&gt;#Open blog&lt;br /&gt;ie.link(:text, "your blog title").click&lt;br /&gt;&lt;br /&gt;#Create new post&lt;br /&gt;ie.link(:text, "Create new post").click&lt;br /&gt;&lt;br /&gt;#Publish it ("value=" is faster then "set")&lt;br /&gt;ie.text_field(:name, "title").value=(title)&lt;br /&gt;ie.text_field(:name, "postBody").value=(content) &lt;br /&gt;ie.button(:value, "Publish Post").click&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-112952128578430305?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/112952128578430305/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=112952128578430305' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112952128578430305'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112952128578430305'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/10/let-watir-do-job_16.html' title='Let watir do the job'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-112931620471872759</id><published>2005-10-14T09:03:00.000-07:00</published><updated>2007-01-22T11:46:03.635-08:00</updated><title type='text'>A simple port scanner using ACE proactor</title><content type='html'>Today I wrote a simple port scanner using ACE proactor. Even though the code itself is useless, the process helped me to know ACE proctor's implementation details much better.&lt;br /&gt;&lt;br /&gt;Proactor is a very good model for high performance IO, but you can not implement an efficient port scanner with it.&lt;br /&gt;&lt;br /&gt;First, since most platforms do not have native capability for asynchronously connecting sockets, ACE may choos to emulate asynchronous connections with an instance of ACE_Select_reactor managed privately by the framework (for example, on windows). Btw, the description on &lt;a href="http://www.amazon.com/exec/obidos/redirect?link_code=ur2&amp;amp;camp=1789&amp;tag=xyz0e-20&amp;amp;creative=9325&amp;path=tg/detail/-/0201795256"&gt;C++NP v2&lt;/a&gt;&lt;img style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; MARGIN: 0px; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=xyz0e-20&amp;amp;l=ur2&amp;o=1" width="1" border="0" /&gt; page 283, sidebar 57 is inaccurate: even though Windows XP/2003 has that capability(via ConnectEX() API), ACE is not using it now (to support older platform like windows 2000). You can check out the source code of ACE_WIN32_Asynch_Connect::connect() to see yourself. So in this case you are using a Reactor in deed, and since the framework need to spawn thread to do the emulation, it is less efficient than using Reactor directly.&lt;br /&gt;&lt;br /&gt;Second, since each ACE_Handler can only be bundled with one handle/socket, you need to create one ACE_Handler for each connection, which definitely has a few more extra overhead than just creating a plain old socket handle.&lt;br /&gt;&lt;br /&gt;Here is the source:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;#include &lt;span style="font-size:+1;color:blue;"&gt;&amp;lt;&lt;/span&gt;ace&lt;span style="font-size:+1;color:blue;"&gt;/&lt;/span&gt;Log_Msg&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;.&lt;/b&gt;&lt;/span&gt;h&lt;span style="font-size:+1;color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;#include &lt;span style="font-size:+1;color:blue;"&gt;&amp;lt;&lt;/span&gt;ace&lt;span style="font-size:+1;color:blue;"&gt;/&lt;/span&gt;INET_Addr&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;.&lt;/b&gt;&lt;/span&gt;h&lt;span style="font-size:+1;color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;#include &lt;span style="font-size:+1;color:blue;"&gt;&amp;lt;&lt;/span&gt;ace&lt;span style="font-size:+1;color:blue;"&gt;/&lt;/span&gt;OS&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;.&lt;/b&gt;&lt;/span&gt;h&lt;span style="font-size:+1;color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;#include &lt;span style="font-size:+1;color:blue;"&gt;&amp;lt;&lt;/span&gt;ace&lt;span style="font-size:+1;color:blue;"&gt;/&lt;/span&gt;Proactor&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;.&lt;/b&gt;&lt;/span&gt;h&lt;span style="font-size:+1;color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;#include &lt;span style="font-size:+1;color:blue;"&gt;&amp;lt;&lt;/span&gt;ace&lt;span style="font-size:+1;color:blue;"&gt;/&lt;/span&gt;WIN32_Proactor&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;.&lt;/b&gt;&lt;/span&gt;h&lt;span style="font-size:+1;color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:red;"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt; PortScanner &lt;span style="font-size:+1;color:blue;"&gt;:&lt;/span&gt; &lt;span style="color:red;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt; ACE_Handler&lt;br /&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:red;"&gt;&lt;b&gt;public&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; PortScanner&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt; &lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt; &lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span style="color:red;"&gt;&lt;b&gt;int&lt;/b&gt;&lt;/span&gt; open&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;ACE_Proactor&lt;span style="font-size:+1;color:blue;"&gt;&amp;&lt;/span&gt; proactor&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;,&lt;/b&gt;&lt;/span&gt; &lt;span style="color:red;"&gt;&lt;b&gt;const&lt;/b&gt;&lt;/span&gt; ACE_INET_Addr&lt;span style="font-size:+1;color:blue;"&gt;&amp;amp;&lt;/span&gt; remote_addr&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt; &lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:red;"&gt;&lt;b&gt;this&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;-&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&amp;gt;&lt;/span&gt;proactor&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&amp;&lt;/span&gt;proactor&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:red;"&gt;&lt;b&gt;this&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;-&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&amp;gt;&lt;/span&gt;remote_addr_&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;.&lt;/b&gt;&lt;/span&gt;set&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;remote_addr&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span style="color:red;"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; &lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;connect_&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;.&lt;/b&gt;&lt;/span&gt;open&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;*&lt;/span&gt;&lt;span style="color:red;"&gt;&lt;b&gt;this&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;,&lt;/b&gt;&lt;/span&gt; ACE_INVALID_HANDLE&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;,&lt;/b&gt;&lt;/span&gt; &lt;span style="color:brown;"&gt;0&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;,&lt;/b&gt;&lt;/span&gt; &lt;span style="color:red;"&gt;&lt;b&gt;this&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;-&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&amp;gt;&lt;/span&gt;proactor&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt; &lt;span style="font-size:+1;color:blue;"&gt;&amp;lt;&lt;/span&gt; &lt;span style="color:brown;"&gt;0&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:red;"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; &lt;span style="font-size:+1;color:blue;"&gt;-&lt;/span&gt;&lt;span style="color:brown;"&gt;1&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span style="color:red;"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; connect_&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;.&lt;/b&gt;&lt;/span&gt;connect&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;ACE_INVALID_HANDLE&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;,&lt;/b&gt;&lt;/span&gt; remote_addr_&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;,&lt;/b&gt;&lt;/span&gt; ACE_Addr&lt;span style="font-size:+1;color:blue;"&gt;:&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;:&lt;/span&gt;sap_any&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;,&lt;/b&gt;&lt;/span&gt; &lt;span style="color:brown;"&gt;1&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt; &lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span style="color:red;"&gt;&lt;b&gt;void&lt;/b&gt;&lt;/span&gt; handle_connect&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;&lt;span style="color:red;"&gt;&lt;b&gt;const&lt;/b&gt;&lt;/span&gt; ACE_Asynch_Connect&lt;span style="font-size:+1;color:blue;"&gt;:&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;:&lt;/span&gt;Result &lt;span style="font-size:+1;color:blue;"&gt;&amp;&lt;/span&gt;result&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt; &lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:green;"&gt;&lt;i&gt;//This handler will be called if connection is established or RST is received,&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;  &lt;span style="color:green;"&gt;&lt;i&gt;//You may no get any response in a timely manner even if there is no firewall.&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;  ACE_ASSERT&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;result&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;.&lt;/b&gt;&lt;/span&gt;connect_handle &lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt; &lt;span style="font-size:+1;color:blue;"&gt;!&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;=&lt;/span&gt; ACE_INVALID_HANDLE&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;  &lt;span style="color:red;"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; &lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;result&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;.&lt;/b&gt;&lt;/span&gt;success&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;&lt;i&gt;//Connection is established&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;   ACE_DEBUG&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;LM_NOTICE&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;,&lt;/b&gt;&lt;/span&gt; &lt;span style="color:purple;"&gt;"%s:%d is open\n"&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;,&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;        remote_addr_&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;.&lt;/b&gt;&lt;/span&gt;get_host_addr&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;,&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;        remote_addr_&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;.&lt;/b&gt;&lt;/span&gt;get_port_number&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:red;"&gt;&lt;b&gt;else&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;   &lt;span style="color:green;"&gt;&lt;i&gt;//Got a RST&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;  &lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt; &lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:red;"&gt;&lt;b&gt;private&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;:&lt;/span&gt;&lt;br /&gt; ACE_INET_Addr remote_addr_&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt; ACE_Asynch_Connect connect_&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:red;"&gt;&lt;b&gt;int&lt;/b&gt;&lt;/span&gt; ACE_TMAIN&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;&lt;span style="color:red;"&gt;&lt;b&gt;int&lt;/b&gt;&lt;/span&gt; &lt;span style="color:green;"&gt;&lt;i&gt;/*argc*/&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;,&lt;/b&gt;&lt;/span&gt; ACE_TCHAR&lt;span style="font-size:+1;color:blue;"&gt;*&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;*&lt;/span&gt; &lt;span style="color:green;"&gt;&lt;i&gt;/*argv*/&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt; ACE_Proactor proactor&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt; ACE_INET_Addr scan_target&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;&lt;span style="color:purple;"&gt;"127.0.0.1:0"&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span style="color:green;"&gt;&lt;i&gt;//Asynchronous connection are simulated on Both Windows and Unix&lt;br /&gt;&lt;/i&gt;&lt;/span&gt; &lt;span style="color:green;"&gt;&lt;i&gt;//(C++NP v2 page 283, sidebar 57 is inaccurate).&lt;br /&gt;&lt;/i&gt;&lt;/span&gt; &lt;span style="color:green;"&gt;&lt;i&gt;//Since ACE_Select_reactor is used internally, the handles limit&lt;br /&gt;&lt;/i&gt;&lt;/span&gt; &lt;span style="color:green;"&gt;&lt;i&gt;//applies. You can either increase the limit(1024 by default), or&lt;br /&gt;&lt;/i&gt;&lt;/span&gt; &lt;span style="color:green;"&gt;&lt;i&gt;//simply do not register too much handles simultaneously.&lt;br /&gt;&lt;/i&gt;&lt;/span&gt; &lt;span style="color:red;"&gt;&lt;b&gt;unsigned&lt;/b&gt;&lt;/span&gt; &lt;span style="color:red;"&gt;&lt;b&gt;short&lt;/b&gt;&lt;/span&gt; start_port  &lt;span style="font-size:+1;color:blue;"&gt;=&lt;/span&gt; &lt;span style="color:brown;"&gt;1&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt; &lt;span style="color:red;"&gt;&lt;b&gt;unsigned&lt;/b&gt;&lt;/span&gt; &lt;span style="color:red;"&gt;&lt;b&gt;short&lt;/b&gt;&lt;/span&gt; end_port &lt;span style="font-size:+1;color:blue;"&gt;=&lt;/span&gt; &lt;span style="color:brown;"&gt;1024&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; ACE_ASSERT&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;end_port &lt;span style="font-size:+1;color:blue;"&gt;&amp;gt;&lt;/span&gt; start_port&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt; &lt;span style="color:red;"&gt;&lt;b&gt;const&lt;/b&gt;&lt;/span&gt; size_t size &lt;span style="font-size:+1;color:blue;"&gt;=&lt;/span&gt; end_port &lt;span style="font-size:+1;color:blue;"&gt;-&lt;/span&gt; start_port &lt;span style="font-size:+1;color:blue;"&gt;+&lt;/span&gt; &lt;span style="color:brown;"&gt;1&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt; &lt;span style="color:green;"&gt;&lt;i&gt;//'size' is not const expression so we can not create the array on stack&lt;br /&gt;&lt;/i&gt;&lt;/span&gt; PortScanner&lt;span style="font-size:+1;color:blue;"&gt;*&lt;/span&gt; portscanners &lt;span style="font-size:+1;color:blue;"&gt;=&lt;/span&gt; &lt;span style="color:red;"&gt;&lt;b&gt;new&lt;/b&gt;&lt;/span&gt; PortScanner&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;[&lt;/b&gt;&lt;/span&gt;size&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;]&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span style="color:red;"&gt;&lt;b&gt;for&lt;/b&gt;&lt;/span&gt; &lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;&lt;span style="color:red;"&gt;&lt;b&gt;unsigned&lt;/b&gt;&lt;/span&gt; &lt;span style="color:red;"&gt;&lt;b&gt;short&lt;/b&gt;&lt;/span&gt; i &lt;span style="font-size:+1;color:blue;"&gt;=&lt;/span&gt; start_port&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt; i &lt;span style="font-size:+1;color:blue;"&gt;&amp;lt;&lt;/span&gt; end_port&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt; &lt;span style="font-size:+1;color:blue;"&gt;&lt;span style="font-size:+1;color:blue;"&gt;+&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;+&lt;/span&gt;&lt;/span&gt;i&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;br /&gt; &lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;{&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;  scan_target&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;.&lt;/b&gt;&lt;/span&gt;set_port_number&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;i&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;  portscanners&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;[&lt;/b&gt;&lt;/span&gt;i&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;]&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;.&lt;/b&gt;&lt;/span&gt;open&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;proactor&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;,&lt;/b&gt;&lt;/span&gt; scan_target&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt; &lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span style="color:green;"&gt;&lt;i&gt;//Run event loop for 10 seconds&lt;br /&gt;&lt;/i&gt;&lt;/span&gt; ACE_DEBUG&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;LM_NOTICE&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;,&lt;/b&gt;&lt;/span&gt; ACE_TEXT&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;&lt;span style="color:purple;"&gt;"Portscan started\n"&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt; ACE_Time_Value timeout&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;&lt;span style="color:brown;"&gt;30&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt; proactor&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;.&lt;/b&gt;&lt;/span&gt;proactor_run_event_loop&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;(&lt;/b&gt;&lt;/span&gt;timeout&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;)&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span style="color:red;"&gt;&lt;b&gt;delete&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;[&lt;/b&gt;&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;]&lt;/b&gt;&lt;/span&gt; portscanners&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span style="color:red;"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; &lt;span style="color:brown;"&gt;0&lt;/span&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:+1;color:blue;"&gt;&lt;b&gt;}&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-112931620471872759?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/112931620471872759/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=112931620471872759' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112931620471872759'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112931620471872759'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/10/simple-port-scanner-using-ace-proactor.html' title='A simple port scanner using ACE proactor'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-112917620676332498</id><published>2005-10-12T20:51:00.000-07:00</published><updated>2005-10-12T21:03:26.770-07:00</updated><title type='text'>Access Control for Ruby Class</title><content type='html'>The following words are from &lt;a href="http://www.amazon.com/exec/obidos/redirect?link_code=ur2&amp;amp;camp=1789&amp;amp;tag=xyz0e-20&amp;amp;creative=9325&amp;amp;path=http://www.amazon.com/gp/product/0974514055"&gt;Programming Ruby: The Pragmatic Programmers' Guide&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=xyz0e-20&amp;amp;l=ur2&amp;amp;o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /&gt;:&lt;br /&gt;&lt;br /&gt;"Ruby differs from other OO languages in another important way. Access control is determined dynamically, as the program runs, not statically. You will get an access violation only when the code attempts to execute the restricted method."&lt;br /&gt;&lt;br /&gt;That's because those "public"/"protected"/"private" you saw are actually implemented as functions! The parser does not even know them. As the program runs, those functions are called and then you know if there is any errors.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-112917620676332498?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/112917620676332498/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=112917620676332498' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112917620676332498'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112917620676332498'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/10/access-control-for-ruby-class.html' title='Access Control for Ruby Class'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-112896227712158319</id><published>2005-10-10T09:24:00.000-07:00</published><updated>2005-10-10T09:37:57.126-07:00</updated><title type='text'>Lexer state</title><content type='html'>Lexer state cannot be avoided when implementing a lexer for Perl and Ruby.&lt;br /&gt;&lt;br /&gt;In Perl/Ruby, regular expression starts and ends with '/', for example:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;/perl|ruby/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;As we all know, '/' is the divide operator.&lt;br /&gt;&lt;br /&gt;So when the lexer meets a '/' character, it can not tell whether it is the start of a regular expression or a divide operator without the help of the context.&lt;br /&gt;&lt;br /&gt;Same thing for "&amp;lt;&amp;lt;", it can be the left shift operator, or the start of "here doc":&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;&amp;lt;EOF&lt;br /&gt;whatever&lt;br /&gt;EOF&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-112896227712158319?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/112896227712158319/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=112896227712158319' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112896227712158319'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112896227712158319'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/10/lexer-state.html' title='Lexer state'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-112846082208054133</id><published>2005-10-04T13:32:00.000-07:00</published><updated>2005-10-04T14:27:13.046-07:00</updated><title type='text'>The Ruby phenomenon</title><content type='html'>The recent Ruby phenomenon is very interesting. Lost of people (including me) are first attracted by a killer application (e.g., &lt;a href="www.rubyonrails.org/"&gt;rails&lt;/a&gt; and &lt;a href="wtr.rubyforge.org"&gt;watir&lt;/a&gt;), then start to learn this foreign language (considering the majority programmers are only familiar with "curly braces" languages, like C++/C#/Java).&lt;br /&gt;&lt;br /&gt;Both rails and watir are in a very competitive market. To develop web applications, there are big players like J2EE and ASP.net, even PHP has a larger user base than ruby. To do web application testing, javascript and vbscript have been used for years. Believe me, no matter how good ruby is, most people would like to stay with the language they know. Lots of credits should go to rails and watir.&lt;br /&gt;&lt;br /&gt;So what makes rails and watir successful? One philosophy: make simple things simple and complex things possible. Everyone knows it, but it is quiet hard to achieve.&lt;br /&gt;&lt;br /&gt;We can build very complex web applications with J2EE and .NET, while they have simplified the job greatly, comparing with developing in portable assembly(I am talking C :)), there are still lots of tedious works. On the other hand, there are some RAD tools which can help us to &lt;a href="http://www.dbqwiksite.com/"&gt;build an eCommerce site without a single line of coding&lt;/a&gt;, adding additional features soon becomes painful.&lt;br /&gt;&lt;br /&gt;Rails and waitr do lots of things behind the scene, making good choice themselves without bothering us. Meanwhile the simple and powerful ruby language enable us to do complex things without too much works. Now that's a real beauty!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-112846082208054133?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/112846082208054133/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=112846082208054133' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112846082208054133'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112846082208054133'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/10/ruby-phenomenon.html' title='The Ruby phenomenon'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-112845691928670189</id><published>2005-10-04T12:25:00.000-07:00</published><updated>2005-10-11T10:16:56.790-07:00</updated><title type='text'>Sniffer and Reactor/Proactor</title><content type='html'>While I have used &lt;a href="http://www.tcpdump.org/"&gt;pcap&lt;/a&gt; and &lt;a href="http://www.winpcap.org/"&gt;winpcap&lt;/a&gt; for years, I am not big fan of the current programming model. I would wish to have an event driven model(reactor) or asynchronous IO model(procator). In other words, treat PCAP handler just like socket, have someone (select() for example) notify me when something interesting happens.&lt;br /&gt;&lt;br /&gt;But maybe it is not pcap to blame, most of time it is just implemented as an user level library, and the underlying operating system may not provide a way to do IO multiplexing for such low level functions.&lt;br /&gt;&lt;br /&gt;To implement a sniffer on windows, most of people will go for winpcap (btw, after a long waiting(two years!), winpcap 3.1 is finally out to replace the very buggy 3.0 version). Actually winsock has native sniffing support via raw socket(with SIO_RCVALL option), and it works well with reactor and proactor!&lt;br /&gt;&lt;br /&gt;Here is the code to demonstrate the functionality (I used &lt;a href="http://www.cs.wustl.edu/~schmidt/ACE.html"&gt;ACE&lt;/a&gt;. I know most of people would prefer plain old socket programming, but it is too hard for me to go back the dark days):&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;//Sniffer and Reactor Example&lt;br /&gt;#include &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;ace&lt;FONT COLOR=BLUE SIZE=+1&gt;/&lt;/FONT&gt;Log_Msg&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;h&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;&lt;br /&gt;#include &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;ace&lt;FONT COLOR=BLUE SIZE=+1&gt;/&lt;/FONT&gt;Reactor&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;h&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;&lt;br /&gt;#include &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;ace&lt;FONT COLOR=BLUE SIZE=+1&gt;/&lt;/FONT&gt;INET_Addr&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;h&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;&lt;br /&gt;#include &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;ace&lt;FONT COLOR=BLUE SIZE=+1&gt;/&lt;/FONT&gt;OS&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;h&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;&lt;br /&gt;#include &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;ace&lt;FONT COLOR=BLUE SIZE=+1&gt;/&lt;/FONT&gt;WFMO_Reactor&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;h&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;#include &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;mstcpip&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;h&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;&lt;FONT COLOR=GREEN&gt;&lt;I&gt;//SIO_RCVALL&lt;br /&gt;&lt;/I&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=GREEN&gt;&lt;I&gt;//ACE_NDEBUG will be defined if you define _DEBUG on windows.&lt;br /&gt;&lt;/I&gt;&lt;/FONT&gt;#ifdef ACE_NDEBUG&lt;br /&gt;#define ACE_VERIFY&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;X&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;void&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;X&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;#&lt;FONT COLOR=RED&gt;&lt;B&gt;else&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;#define ACE_VERIFY&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;X&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; ACE_ASSERT&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;X&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;#endif &lt;FONT COLOR=GREEN&gt;&lt;I&gt;//ACE_NDEBUG&lt;br /&gt;&lt;/I&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;class&lt;/B&gt;&lt;/FONT&gt; Sniffer &lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;public&lt;/B&gt;&lt;/FONT&gt; ACE_Event_Handler&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;public&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;br /&gt; Sniffer&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;ACE_Reactor&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt; reactor&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;socket_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;ACE_INVALID_HANDLE&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;this&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;reactor&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;reactor&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; ACE_HANDLE get_handle&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;const&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;return&lt;/B&gt;&lt;/FONT&gt; socket_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;~&lt;/FONT&gt;Sniffer&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;if&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;ACE_INVALID_HANDLE &lt;FONT COLOR=BLUE SIZE=+1&gt;!&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; socket_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;   ACE_VERIFY&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;ACE_OS&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;closesocket&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;socket_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; &lt;FONT COLOR=GREEN&gt;&lt;I&gt;/*&lt;br /&gt; MSDN On SIO_RCVALL:&lt;br /&gt; Enables a socket to receive all IP packets on the network. The socket handle passed to the&lt;br /&gt; WSAIoctl function must be of AF_INET address family, SOCK_RAW socket type, and IPPROTO_IP&lt;br /&gt; protocol. The socket also must be bound to an explicit local interface, which means that you cannot&lt;br /&gt; bind to INADDR_ANY. &lt;br /&gt; Once the socket is bound and the ioctl set, calls to the WSARecv or recv functions return IP&lt;br /&gt; datagrams passing through the given interface. Note that you must supply a sufficiently large&lt;br /&gt; buffer. Setting this ioctl requires Administrator privilege on the local computer. SIO_RCVALL is&lt;br /&gt; available in Windows 2000 and later versions of Windows.&lt;br /&gt; */&lt;/I&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;int&lt;/B&gt;&lt;/FONT&gt; open &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;const&lt;/B&gt;&lt;/FONT&gt; ACE_INET_Addr&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt; listen_addr&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  socket_ &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; ACE_OS&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;socket&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;AF_INET&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; SOCK_RAW&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; IPPROTO_IP&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;if&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;ACE_INVALID_HANDLE &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; socket_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;   ACE_ERROR&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;LM_ERROR&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; ACE_TEXT&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"%p\n"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; ACE_TEXT&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"socket() failed in Sniffer::open()"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;   &lt;FONT COLOR=RED&gt;&lt;B&gt;return&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;&lt;FONT COLOR=BROWN&gt;1&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;  sockaddr&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt; laddr &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; reinterpret_cast&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;sockaddr&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;listen_addr&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;get_addr&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  size_t size &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; listen_addr&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;get_size&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  ACE_VERIFY&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;ACE_OS&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;bind&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;socket_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; laddr&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; size&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;  DWORD YES &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;1&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  ACE_VERIFY&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;ACE_OS&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;setsockopt&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;socket_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; IPPROTO_IP&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; IP_HDRINCL&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; reinterpret_cast&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;const&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;char&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;YES&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;sizeof&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;YES&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;  DWORD dwBytesRet &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;if&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;WSAIoctl&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;SOCKET&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;socket_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; SIO_RCVALL&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;YES&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;sizeof&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;YES&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; NULL&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;dwBytesRet&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; NULL&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; NULL&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;!&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;   ACE_ERROR&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;LM_ERROR&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; ACE_TEXT&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"%p\n"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; ACE_TEXT&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"WSAIoctl() failed in Sniffer::open()"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;   &lt;FONT COLOR=RED&gt;&lt;B&gt;return&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;&lt;FONT COLOR=BROWN&gt;1&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;  DWORD rcvtimeo &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;1000&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=GREEN&gt;&lt;I&gt;// 1 sec instead of 45(default)&lt;br /&gt;&lt;/I&gt;&lt;/FONT&gt;  ACE_VERIFY&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;ACE_OS&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;setsockopt&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;socket_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; SOL_SOCKET&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; SO_RCVTIMEO&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; reinterpret_cast&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;const&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;char&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;rcvtimeo&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;sizeof&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;rcvtimeo&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;  &lt;FONT COLOR=GREEN&gt;&lt;I&gt;// register the event handle&lt;br /&gt;&lt;/I&gt;&lt;/FONT&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;if&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;this&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;reactor&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;register_handler&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;this&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; ACE_Event_Handler&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;READ_MASK&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;   ACE_ERROR&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;LM_ERROR&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; ACE_TEXT &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"%p\n"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;     ACE_TEXT&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"register_handler"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;   &lt;FONT COLOR=RED&gt;&lt;B&gt;return&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;&lt;FONT COLOR=BROWN&gt;1&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;  ACE_DEBUG&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;LM_DEBUG&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; ACE_TEXT&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"Sniffer::open\n"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;return&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;int&lt;/B&gt;&lt;/FONT&gt; handle_input&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;ACE_HANDLE fd &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; ACE_INVALID_HANDLE&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  ACE_ASSERT&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;fd &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; socket_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;char&lt;/B&gt;&lt;/FONT&gt; recvbuf&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;[&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BROWN&gt;65536&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;]&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  ssize_t nrecv &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; ACE_OS&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;recv&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;socket_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; recvbuf&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;sizeof&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;recvbuf&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;1&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;if&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;nrecv &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;   ACE_HEX_DUMP&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;LM_NOTICE&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; recvbuf&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; nrecv&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;else&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;   ACE_ERROR&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;LM_ERROR&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; ACE_TEXT&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"handle_input returns %d: %m\n"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; nrecv&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;return&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;private&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;br /&gt; ACE_HANDLE socket_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;int&lt;/B&gt;&lt;/FONT&gt; ACE_TMAIN&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;int&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=GREEN&gt;&lt;I&gt;/*argc*/&lt;/I&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; ACE_TCHAR&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt; &lt;FONT COLOR=GREEN&gt;&lt;I&gt;/*argv*/&lt;/I&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; ACE_WFMO_Reactor wfmo_reactor&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; ACE_Reactor reactor &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;wfmo_reactor&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; &lt;FONT COLOR=GREEN&gt;&lt;I&gt;//TODO bind to your local address!!!&lt;br /&gt;&lt;/I&gt;&lt;/FONT&gt; &lt;FONT COLOR=GREEN&gt;&lt;I&gt;//Do not work with loopback address (127.0.0.1)&lt;br /&gt;&lt;/I&gt;&lt;/FONT&gt; ACE_INET_Addr addr&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"192.168.0.100:0"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; Sniffer sniffer&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;reactor&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;if&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;sniffer&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;open&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;addr&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;&lt;FONT COLOR=BROWN&gt;1&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  ACE_ERROR&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;LM_ERROR&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; ACE_TEXT&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"Can not open to listen: %m\n"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;return&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;&lt;FONT COLOR=BROWN&gt;1&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; &lt;FONT COLOR=GREEN&gt;&lt;I&gt;//Run event loop&lt;br /&gt;&lt;/I&gt;&lt;/FONT&gt; ACE_DEBUG&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;LM_NOTICE&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; ACE_TEXT&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"Sniffer started\n"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; reactor&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;run_reactor_event_loop&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;return&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;--------------------------------&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;//Sniffer and Proactor example&lt;br /&gt;#include &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;ace&lt;FONT COLOR=BLUE SIZE=+1&gt;/&lt;/FONT&gt;Log_Msg&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;h&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;&lt;br /&gt;#include &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;ace&lt;FONT COLOR=BLUE SIZE=+1&gt;/&lt;/FONT&gt;INET_Addr&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;h&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;&lt;br /&gt;#include &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;ace&lt;FONT COLOR=BLUE SIZE=+1&gt;/&lt;/FONT&gt;OS&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;h&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;&lt;br /&gt;#include &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;ace&lt;FONT COLOR=BLUE SIZE=+1&gt;/&lt;/FONT&gt;Proactor&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;h&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;&lt;br /&gt;#include &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;ace&lt;FONT COLOR=BLUE SIZE=+1&gt;/&lt;/FONT&gt;WIN32_Proactor&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;h&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;#include &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;mstcpip&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;h&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;&lt;FONT COLOR=GREEN&gt;&lt;I&gt;//SIO_RCVALL&lt;br /&gt;&lt;/I&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=GREEN&gt;&lt;I&gt;//ACE_NDEBUG will be defined if you define _DEBUG on windows.&lt;br /&gt;&lt;/I&gt;&lt;/FONT&gt;#ifdef ACE_NDEBUG&lt;br /&gt;#define ACE_VERIFY&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;X&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;void&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;X&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;#&lt;FONT COLOR=RED&gt;&lt;B&gt;else&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;#define ACE_VERIFY&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;X&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; ACE_ASSERT&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;X&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;#endif &lt;FONT COLOR=GREEN&gt;&lt;I&gt;//ACE_NDEBUG&lt;br /&gt;&lt;/I&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;class&lt;/B&gt;&lt;/FONT&gt; Sniffer &lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;public&lt;/B&gt;&lt;/FONT&gt; ACE_Handler&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;static&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;const&lt;/B&gt;&lt;/FONT&gt; size_t PACKET_SIZE &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;65526&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;public&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;br /&gt; Sniffer&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;ACE_Proactor&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt; proactor&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;socket_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;ACE_INVALID_HANDLE&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt;ACE_Handler&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;proactor&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt;mblk_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;PACKET_SIZE&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; ACE_HANDLE handle&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;const&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;return&lt;/B&gt;&lt;/FONT&gt; socket_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;~&lt;/FONT&gt;Sniffer&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;if&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;ACE_INVALID_HANDLE &lt;FONT COLOR=BLUE SIZE=+1&gt;!&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; socket_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;   ACE_VERIFY&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;ACE_OS&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;closesocket&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;socket_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; &lt;FONT COLOR=GREEN&gt;&lt;I&gt;/*&lt;br /&gt; MSDN On SIO_RCVALL:&lt;br /&gt; Enables a socket to receive all IP packets on the network. The socket handle passed to the&lt;br /&gt; WSAIoctl function must be of AF_INET address family, SOCK_RAW socket type, and IPPROTO_IP&lt;br /&gt; protocol. The socket also must be bound to an explicit local interface, which means that you cannot&lt;br /&gt; bind to INADDR_ANY. &lt;br /&gt; Once the socket is bound and the ioctl set, calls to the WSARecv or recv functions return IP&lt;br /&gt; datagrams passing through the given interface. Note that you must supply a sufficiently large&lt;br /&gt; buffer. Setting this ioctl requires Administrator privilege on the local computer. SIO_RCVALL is&lt;br /&gt; available in Windows 2000 and later versions of Windows.&lt;br /&gt; */&lt;/I&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;int&lt;/B&gt;&lt;/FONT&gt; open &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;const&lt;/B&gt;&lt;/FONT&gt; ACE_INET_Addr&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt; listen_addr&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;if&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;create_sniffer_socket&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;listen_addr&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;   &lt;FONT COLOR=RED&gt;&lt;B&gt;return&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;&lt;FONT COLOR=BROWN&gt;1&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;  &lt;FONT COLOR=GREEN&gt;&lt;I&gt;// register the event handle&lt;br /&gt;&lt;/I&gt;&lt;/FONT&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;if&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;reader_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;open&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;this&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;   ACE_ERROR&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;LM_ERROR&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; ACE_TEXT&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"open: %m\n"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;   &lt;FONT COLOR=RED&gt;&lt;B&gt;return&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;&lt;FONT COLOR=BROWN&gt;1&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;  ACE_DEBUG&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;LM_DEBUG&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; ACE_TEXT&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"Sniffer::open\n"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;  &lt;FONT COLOR=GREEN&gt;&lt;I&gt;//initiate our first asynchronous read&lt;br /&gt;&lt;/I&gt;&lt;/FONT&gt;  reader_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;read&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;mblk_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; PACKET_SIZE&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;return&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;void&lt;/B&gt;&lt;/FONT&gt; handle_read_stream&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;const&lt;/B&gt;&lt;/FONT&gt; ACE_Asynch_Read_Stream&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;Result &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;result&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;if&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;!&lt;/FONT&gt;result&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;success&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;|&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;|&lt;/FONT&gt;&lt;/FONT&gt; result&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;bytes_transferred&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;   ACE_ERROR&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;LM_ERROR&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; ACE_TEXT&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"read_streamhandle_read_stream error\n"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;   &lt;FONT COLOR=RED&gt;&lt;B&gt;return&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;  ACE_ASSERT&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;mblk_ &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;result&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;message_block&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;  ACE_HEX_DUMP&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;LM_NOTICE&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; mblk_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;rd_ptr&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; result&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;bytes_transferred&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;  &lt;FONT COLOR=GREEN&gt;&lt;I&gt;//Reset the write pointer and read again&lt;br /&gt;&lt;/I&gt;&lt;/FONT&gt;  mblk_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;wr_ptr&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;mblk_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;rd_ptr&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  reader_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;read&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;mblk_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; PACKET_SIZE&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;private&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;br /&gt; ACE_Asynch_Read_Stream reader_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; ACE_HANDLE socket_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; ACE_Message_Block mblk_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;int&lt;/B&gt;&lt;/FONT&gt; create_sniffer_socket&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;const&lt;/B&gt;&lt;/FONT&gt; ACE_INET_Addr&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt; listen_addr&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  socket_ &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; ACE_OS&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;socket&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;AF_INET&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; SOCK_RAW&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; IPPROTO_IP&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;if&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;ACE_INVALID_HANDLE &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; socket_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;   ACE_ERROR&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;LM_ERROR&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; ACE_TEXT&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"%p\n"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; ACE_TEXT&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"socket() failed in Sniffer::open()"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;   &lt;FONT COLOR=RED&gt;&lt;B&gt;return&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;&lt;FONT COLOR=BROWN&gt;1&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;  sockaddr&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt; laddr &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; reinterpret_cast&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;sockaddr&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;listen_addr&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;get_addr&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  size_t size &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; listen_addr&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;get_size&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  ACE_VERIFY&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;ACE_OS&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;bind&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;socket_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; laddr&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; size&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;  DWORD YES &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;1&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  ACE_VERIFY&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;ACE_OS&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;setsockopt&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;socket_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; IPPROTO_IP&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; IP_HDRINCL&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; reinterpret_cast&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;const&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;char&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;YES&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;sizeof&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;YES&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;  DWORD dwBytesRet &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;if&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;WSAIoctl&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;SOCKET&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;socket_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; SIO_RCVALL&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;YES&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;sizeof&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;YES&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; NULL&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;dwBytesRet&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; NULL&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; NULL&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;!&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;   ACE_ERROR&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;LM_ERROR&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; ACE_TEXT&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"%p\n"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; ACE_TEXT&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"WSAIoctl() failed in Sniffer::open()"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;   &lt;FONT COLOR=RED&gt;&lt;B&gt;return&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;&lt;FONT COLOR=BROWN&gt;1&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;  DWORD rcvtimeo &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;1000&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=GREEN&gt;&lt;I&gt;// 1 sec instead of 45(default)&lt;br /&gt;&lt;/I&gt;&lt;/FONT&gt;  ACE_VERIFY&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;ACE_OS&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;:&lt;/FONT&gt;setsockopt&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;socket_&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; SOL_SOCKET&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; SO_RCVTIMEO&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; reinterpret_cast&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;lt;&lt;/FONT&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;const&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;char&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;rcvtimeo&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;sizeof&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;rcvtimeo&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;return&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;int&lt;/B&gt;&lt;/FONT&gt; ACE_TMAIN&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=RED&gt;&lt;B&gt;int&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=GREEN&gt;&lt;I&gt;/*argc*/&lt;/I&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; ACE_TCHAR&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;*&lt;/FONT&gt; &lt;FONT COLOR=GREEN&gt;&lt;I&gt;/*argv*/&lt;/I&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; ACE_WIN32_Proactor win32_proactor&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; ACE_Proactor proactor&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&amp;amp;&lt;/FONT&gt;win32_proactor&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; &lt;FONT COLOR=GREEN&gt;&lt;I&gt;//TODO bind to your local address!!!&lt;br /&gt;&lt;/I&gt;&lt;/FONT&gt; &lt;FONT COLOR=GREEN&gt;&lt;I&gt;//Do not work with loopback address (127.0.0.1)&lt;br /&gt;&lt;/I&gt;&lt;/FONT&gt; ACE_INET_Addr addr&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"192.168.0.100:0"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; Sniffer sniffer&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;proactor&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;if&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;sniffer&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;open&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;addr&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;=&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;&lt;FONT COLOR=BROWN&gt;1&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;{&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  ACE_ERROR&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;LM_ERROR&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; ACE_TEXT&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"Can not open to listen: %m\n"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;  &lt;FONT COLOR=RED&gt;&lt;B&gt;return&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;-&lt;/FONT&gt;&lt;FONT COLOR=BROWN&gt;1&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt; &lt;FONT COLOR=GREEN&gt;&lt;I&gt;//Run event loop&lt;br /&gt;&lt;/I&gt;&lt;/FONT&gt; ACE_DEBUG&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;LM_NOTICE&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;,&lt;/B&gt;&lt;/FONT&gt; ACE_TEXT&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=PURPLE&gt;"Sniffer started\n"&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; proactor&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;.&lt;/B&gt;&lt;/FONT&gt;proactor_run_event_loop&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;(&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;)&lt;/B&gt;&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt; &lt;FONT COLOR=RED&gt;&lt;B&gt;return&lt;/B&gt;&lt;/FONT&gt; &lt;FONT COLOR=BROWN&gt;0&lt;/FONT&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;;&lt;/B&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR=BLUE SIZE=+1&gt;&lt;B&gt;}&lt;/B&gt;&lt;/FONT&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Reference:&lt;br /&gt;[0] &lt;a href="http://pinegap.net/infosurge/infosurge-20.txt"&gt;Raw Sockets in Windows 2000/XP" by ziss&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-112845691928670189?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/112845691928670189/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=112845691928670189' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112845691928670189'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112845691928670189'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/10/sniffer-and-reactorproactor.html' title='Sniffer and Reactor/Proactor'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-112793942688524915</id><published>2005-09-28T13:03:00.000-07:00</published><updated>2005-09-28T13:32:18.060-07:00</updated><title type='text'>Ruby and Ada do look alike</title><content type='html'>I once thought ruby is mostly inspired by perl, since Yukihiro Matsumoto mentioned &lt;a href="http://www.artima.com/intv/ruby3.html"&gt;ruby inherited the Perl philosophy&lt;/a&gt;. But it is hard to explain where a few "wired" syntax come from (considering my C/C++/C#/Java background), for example:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Ruby          C/C++/C#/Java&lt;br /&gt;---------------------------&lt;br /&gt;begin/end         {}&lt;br /&gt;rescue            try/catch&lt;br /&gt;raise             throw&lt;br /&gt;elsif             else if&lt;br /&gt;case/when         switch/case&lt;br /&gt;nil               NULL/null&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Actually it is all from Ada. Definitely &lt;a href="http://www.ruby-lang.org/en/20020101.html"&gt;this is not a news&lt;/a&gt;, I failed to pay enough attention since I know nothing about Ada.&lt;br /&gt;&lt;br /&gt;You can check out &lt;a href="http://merd.sourceforge.net/pixel/language-study/syntax-across-languages/CntrFlow.html"&gt;syntax across languages per category&lt;/a&gt; to compare the two.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-112793942688524915?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/112793942688524915/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=112793942688524915' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112793942688524915'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112793942688524915'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/09/ruby-and-ada-do-look-alike.html' title='Ruby and Ada do look alike'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-112793486416236733</id><published>2005-09-28T11:41:00.000-07:00</published><updated>2005-10-11T11:25:03.136-07:00</updated><title type='text'>Dynamic typing and error checking</title><content type='html'>For people who get used to Eclipse or other great IDE, coding in ruby has some dark sides. For example, there is no compilation, so error checking only happens at runtime. Normally after you write a program, you run it, find a bug, fix it and repeat the process again and again. Since the program always stops at the first error, it is very inefficient. Most of the people would prefer the IDE to detect errors (like typo) while they are typing.&lt;br /&gt;&lt;br /&gt;Some people believe it is the fault of "dynamic typing". Actually it is not, the poor IDE is the one to blame. As long as the language is strong typed, a compiler(or part of an IDE) is able to do lots of type inference, then validation. You do not have to wait it until runtime. Static typing make type checking easier, in some case even better. But dynamic typing language itself does not prevent you to do it. Unfortunally there is no ruby IDE doing that.&lt;br /&gt;&lt;br /&gt;UPDATE(10/11/2005): Eric Lippert has a &lt;a href="http://blogs.msdn.com/ericlippert/archive/2005/10/11/479696.aspx"&gt;new post on this topic today[2]&lt;/a&gt;. MS's script engine(JScript and VBScript) can check syntax errors without actually running the code, but unfortunately it always stops at the first syntax error.&lt;br /&gt;&lt;br /&gt;References:&lt;br /&gt;[0] &lt;a href="http://jroller.com/page/obie?entry=compiling_in_vain"&gt;Compiling in Vain&lt;/a&gt;&lt;br /&gt;[1] &lt;a href="http://www.artima.com/weblogs/viewpost.jsp?thread=7590"&gt;Typing: Strong vs. Weak, Static vs. Dynamic by Aahz&lt;/a&gt;&lt;br /&gt;[2] &lt;a href="http://blogs.msdn.com/ericlippert/archive/2005/10/11/479696.aspx"&gt;Checking For Script Syntax Errors by Eric Lippert&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-112793486416236733?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/112793486416236733/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=112793486416236733' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112793486416236733'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112793486416236733'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/09/dynamic-typing-and-error-checking.html' title='Dynamic typing and error checking'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-112641996833389761</id><published>2005-09-10T22:09:00.000-07:00</published><updated>2005-09-11T20:51:43.910-07:00</updated><title type='text'>How text editor stores text</title><content type='html'>Text editors need to store text in an efficient way, so that common operations like insert/delete/replace have minimized overhead. How do they do it?&lt;br /&gt;&lt;br /&gt;Well, the simplest way is to put anything into an array(string), but clearly this is not very efficient. If an user is inserting/deleting text at beginning of a file, each keystroke will result in copying the entire buffer.&lt;br /&gt;&lt;br /&gt;There is an obvious trick to improve the performance : since most editing activities tend to occur frequently in a local area , we can allocate more space (often called "Gap Buffer") in advance so that further insertions/replacements do not involve copying. Now the text is represented by two contiguous blocks of data, and a gap buffer between them. Whenever an editing action takes place, we first move the gap to the location. Now the design becomes a little more complex (have to make the gap invisible to the user), but it is much more efficient (less copying and still enjoy caching benefits of locality). Gap Buffer is used in SharpDevelop(see SharpDevelop\src\Libraries\ICSharpCode.TextEditor\src\Document\TextBufferStrategy\GapTextBufferStrategy.cs) and Eclipse(see eclipse\plugins\org.eclipse.rcp.source.win32.win32.x86_3.1.0\src\org.eclipse.swt.win32.win32.x86_3.1.0\src.zip\org\eclipse\swt\custom\DefaultContent.java).&lt;br /&gt;&lt;br /&gt;While gap buffer might be good enough for small size documents, the copying overhead will soon become unacceptable for larger files. Professional text editors (like MS Word, AbiWord etc) use a method called "piece table". If you know Composite Design Pattern, it is very easy to figure it out all by yourself. In this approach, you start with a buffer containing the original text read from the file (this buffer won't be touched anymore). Instead, the new text is kept in a new append-only block, and during editing, the simple buffer changes into a composite structure. You can think the structure as a linked list, and each item is the "piece". A delete is handled by splitting a piece into two pieces, and an insert is handled by splitting the piece into three pieces (the middle one is the inserted content).&lt;br /&gt;&lt;br /&gt;References:&lt;br /&gt;&lt;br /&gt;[1] &lt;a href="http://www.cs.unm.edu/~crowley/papers/sds/sds.html"&gt;Data Structures for Text Sequences by Charles Crowley&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;[2] &lt;a href="http://www.finseth.com/craft/index.html"&gt;The Craft of Text Editing by Craig A. Finseth&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;[3] &lt;a href="http://www.icsharpcode.net/OpenSource/SD/InsideSharpDevelop.aspx"&gt;Dissecting a C# Application: Inside SharpDevelop by SharpDevelop Team&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;[4] &lt;a href="http://www.qoheleth.uklinux.net/blog/?p=16"&gt;MS Word Piece Table by Tomas Frydrych&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;[5] &lt;a href="http://www.advogato.org/person/msevior/diary.html?start=35"&gt;Performance Improvements by Msevior&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;[6] &lt;a href="http://wesnerm.blogs.com/net_undocumented/2005/09/programmer_myop.html"&gt;Programmer Myopia by Wesner Moise&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-112641996833389761?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/112641996833389761/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=112641996833389761' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112641996833389761'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112641996833389761'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/09/how-text-editor-stores-text.html' title='How text editor stores text'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-112638371584932119</id><published>2005-09-10T12:50:00.000-07:00</published><updated>2005-09-10T22:20:43.076-07:00</updated><title type='text'>On Hungarian Notation</title><content type='html'>Recently Micah Martin &lt;a href="http://butunclebob.com/ArticleS.MicahMartin.AyeCarumba"&gt;complained about Hungarian Notation on his blog&lt;/a&gt;. He is definitely not the first person to bring this issue on, the criticism might start as soon as the Notation was born. The complain is valid: if you need to change a type, in Micah Martin's case, from an interface(ICommand) to abstract class(Command), Hungarian Notation is in your way. You have to delete the capital "I" prefix in lots of places, which is not very "agile" for some people.&lt;br /&gt;&lt;br /&gt;But I do not want to ignore the advantage of Hungarian Notation: with its help, you can quickly tell the nature of a type without consulting the documents. If you are using a third party library/framework with stable APIs, you are very likely to appreciate if the vendor uses the Hungarian Notation. And for vendors still doing Big Upfront Design (like MS), changing a type does not happen very frequently.&lt;br /&gt;&lt;br /&gt;In fact Micah Martin's example is not very good as well, he'd better to create an abstract class which simply implements the interface, and let the subclasses extend from it (to enjoy benefit of template method). The clients of the interface do not require any change, they still consume the interface.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-112638371584932119?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/112638371584932119/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=112638371584932119' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112638371584932119'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112638371584932119'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/09/on-hungarian-notation.html' title='On Hungarian Notation'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-112603156066976730</id><published>2005-09-06T10:04:00.000-07:00</published><updated>2005-09-06T11:39:31.486-07:00</updated><title type='text'>Thoughts on parser generators</title><content type='html'>Recently I have been evaluating several parser generators and eventually picked &lt;a href="http://www.antlr.org"&gt;antlr&lt;/a&gt; in my project. Among all the parser generators in the world, &lt;a href="www.gnu.org/software/bison/bison.html"&gt;yacc&lt;/a&gt;, &lt;a href="spirit.sourceforge.net"&gt;boost.spirit&lt;/a&gt;, &lt;a href="http://www.antlr.org"&gt;antlr&lt;/a&gt; and &lt;a href="dev.perl.org/perl6/"&gt;Perl 6&lt;/a&gt; represent the current state of art and each has unique characters worth talking about.&lt;br /&gt;&lt;br /&gt;Since most languages do not have parsing features built-in (Perl 6 will be the pioneer), almost all of the current parser generators use code generation. A common problem is: the generated code may become very foreign to you, and look totally cryptic in your favorite debugger.&lt;br /&gt;&lt;br /&gt;Yacc suffers most in this perspective, since it uses LALR parsing. Lots of people like LL(k) based antlr since it produces human readable code, which I find extremely useful when working on a new/unfamiliar grammar. For more detailed comparison you can read &lt;a href="http://www.bearcave.com/software/antlr/antlr_expr.html"&gt;Ian Kaplan's article&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Boost.Spirit is quite unique (and amazing!). With the help of powerful C++ template and operator overloading, it mimics EBNF in C++. Although it looks like perl 6's approach, it actually generates code through template (compile time), and the generated code is not as readable as antlr's output. Even worse, since C++ compiler won't take special care for boost.spirit, a simple grammar error may appears to be multiple pages of impenetrable garbage. &lt;a href="http://www.codeproject.com/vcpp/stl/introduction_spirit.asp"&gt;Dave Handley has a nice introduction about Boost.Spirit on CodeProject&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://research.microsoft.com/Comega/"&gt;Comega(Cω)&lt;/a&gt; made an interesting move by integrating popular "foreign language"(XML, SQL) to the core of the host language(C#). Perl 6's built-in parsing support did the similar thing (brings EBNF to perl). This can help to provide ealier and more friendly error reporting, which is a mjor problem for Boost.Spirit.&lt;br /&gt;&lt;br /&gt;So far, antlr is sufficient for me. It can generate parser in several languages (Java, C#, C++, Python), reports errors nicely, and the code is readable and debugger friendly.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-112603156066976730?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/112603156066976730/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=112603156066976730' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112603156066976730'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112603156066976730'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/09/thoughts-on-parser-generators.html' title='Thoughts on parser generators'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-112542080510466259</id><published>2005-08-30T09:01:00.000-07:00</published><updated>2005-09-06T10:04:35.523-07:00</updated><title type='text'>Happy 10-year Birthday, Opera!</title><content type='html'>There are lots of people in the world do not know &lt;a href="www.opera.com"&gt;opera web browser&lt;/a&gt;, and may never consider using an IE alternative. But for me, opera has been my browser of choice for 7 years.&lt;br /&gt;&lt;br /&gt;The first version of opera I used is 3.x. At that time, IE 4 started to take over the browser market and lots of people were very disappointed about the sluggish Netscape 4. I found opera from Gao Chunhui's personal webstite, and became an fan since then.&lt;br /&gt;&lt;br /&gt;The best way to describe opera is: fastest and most innovative web browser. On the office website, they also claim opera has better security track record than others, but I wish they did not say that. Maybe opera's security history looks great on paper, but I believe opera's underdog image helps a lot. I still experience a few crashes with the latest 8.0.2 version, maybe the bugs are hard to be exploited, but they mean something. Firefox once bragged about its security, but you know...&lt;br /&gt;&lt;br /&gt;Now lots of people switched to firefox for better user experience (like tabed browsing, easy font size controlling etc), and I know why: it has opera features! And actually it makes me a little bit uncomfortable for firefox not acknowledging its competitor for those features.&lt;br /&gt;&lt;br /&gt;Well, there are still lots of things for opera to improve (a few of them are even showstoppers for some people), I am happy with the way opera is. Happy birthday, Opera!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-112542080510466259?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/112542080510466259/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=112542080510466259' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112542080510466259'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112542080510466259'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/08/happy-10-year-birthday-opera.html' title='Happy 10-year Birthday, Opera!'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-112499266824603116</id><published>2005-08-25T10:35:00.000-07:00</published><updated>2005-10-07T08:52:20.506-07:00</updated><title type='text'>Why IIS is more secure since 6.0?</title><content type='html'>If you read &lt;a href="http://blogs.msdn.com/michael_howard/default.aspx"&gt;Michael Howard's blog&lt;/a&gt;, you may remember his article titled&lt;a href="http://blogs.msdn.com/michael_howard/archive/2004/10/15/242966.aspx"&gt;"IIS6 vs Apache2 Security Defects"&lt;/a&gt;. Base on third party's data, IIS 6 shows a better security track record than Apache 2.&lt;br /&gt;&lt;br /&gt;So, why IIS 6 becomes much safer? Especially given the notorious security history of IIS 5?&lt;br /&gt;&lt;br /&gt;In his new book &lt;a href="http://www.amazon.com/exec/obidos/redirect?link_code=ur2&amp;amp;camp=1789&amp;amp;tag=xyz0e-20&amp;amp;creative=9325&amp;amp;path=tg/detail/-/0072260858"&gt;19 Deadly Sins of Software Security&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=xyz0e-20&amp;amp;l=ur2&amp;amp;o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /&gt;, Michael Howard tells an interesting story:&lt;br /&gt;&lt;br /&gt;(Page 3)"Internet information Server(IIS) 6.0 web server switched entirly to a C++ string class for handling input, and one brave developer claimed he'd amputate his little finger if any buffer overruns were found in his code. As of this writing, the developer still has his finger and no security bulletins have been issued against the web server in the nearly two years since its release."&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-112499266824603116?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/112499266824603116/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=112499266824603116' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112499266824603116'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112499266824603116'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/08/why-iis-is-more-secure-since-60.html' title='Why IIS is more secure since 6.0?'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-112474689444257152</id><published>2005-08-22T14:25:00.000-07:00</published><updated>2005-10-12T09:31:45.356-07:00</updated><title type='text'>Using ACE_SPIPE_Acceptor with ACE_Reactor</title><content type='html'>Using ACE_SPIPE_Acceptor with ACE_Reactor is not very straightforward. There are three things to be noticed:&lt;br /&gt;1. Use ACE_WFMO_Reactor. ACE_Select_Reactor does not work with windows named pipe. Named pipe handle is not socket, so you can not use select() on it. ACE_WFMO_Reactor works because it uses WaitForMultipleObjects().&lt;br /&gt;2. ACE_SPIPE_Acceptor should be registered with the ACE_Reactor::register_handler (ACE_Event_Handler *, ACE_HANDLE) method, since the handle to demultiplex on is an event handle.&lt;br /&gt;3. handle_signal() will be called instead of handle_input() and handle_output(). WaitForMultipleObjects() can not tell whether read or write condition is happening, so ACE_WFMO_Reactor has to can WSAEventSelect() again to check, which means handle_input()/handle_output() only happens for sockets.&lt;br /&gt;&lt;br /&gt;As you can see even if they work together, it is not exactly the same "Reactor" model we used to program sockets (no handle_input and handle_output). Proactor model works better with windows named pipe.&lt;br /&gt;&lt;br /&gt;Here is an example:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;font color="#000000"&gt;&lt;br /&gt;class ClientAcceptor : public ACE_Event_Handler&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ClientAcceptor(ACE_Reactor&amp;amp; reactor)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;this-&amp;gt;reactor(&amp;amp;reactor);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int open (const ACE_SPIPE_Addr &amp;amp;listen_addr);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;int handle_signal(int signum, siginfo_t* = 0, ucontext_t* = 0);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;protected:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ACE_SPIPE_Acceptor acceptor_;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;int ClientAcceptor::open (const ACE_SPIPE_Addr &amp;amp;listen_addr)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (this-&amp;gt;acceptor_.open (listen_addr, 1) == -1)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ACE_TEXT ("acceptor.open")),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-1);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//register the event handle&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if( this-&amp;gt;reactor()-&amp;gt;register_handler(this, this-&amp;gt;acceptor_.get_handle()) &amp;lt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ACE_TEXT ("register_handler")),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-1);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ACE_DEBUG((LM_DEBUG, ACE_TEXT("ClientAcceptor::open\n")));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int ClientAcceptor::handle_signal(int signum, siginfo_t*, ucontext_t*)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ACE_DEBUG((LM_DEBUG, ACE_TEXT("ClientAcceptor::handle_signal\n")));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ACE_SPIPE_Stream stm;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (this-&amp;gt;acceptor_.accept (stm) == -1)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ACE_ERROR_RETURN ((LM_ERROR,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ACE_TEXT ("(%P|%t) %p\n"),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ACE_TEXT ("Failed to accept ")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ACE_TEXT ("client connection")),&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-1);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//If you have only one client to deal with, now you can simply play with&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;stm.&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//To handle multiple clients at the same time, you can either:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//a. create a new thread for every connection&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//b. use asynchronous IO (shift to Proactor model)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int ACE_TMAIN(int argc, ACE_TCHAR*argv[])&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ACE_WFMO_Reactor wfmo_reactor;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ACE_Reactor reactor (&amp;amp;wfmo_reactor);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ACE_SPIPE_Addr addr("mynamedpipe");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ClientAcceptor acceptor(reactor);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (acceptor.open(addr) == -1)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("Can not open to listen:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;%m\n")), -1);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//Run event loop&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ACE_DEBUG((LM_NOTICE, ACE_TEXT("Server started\n")));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;reactor.run_reactor_event_loop();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-112474689444257152?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/112474689444257152/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=112474689444257152' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112474689444257152'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112474689444257152'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/08/using-acespipeacceptor-with-acereactor.html' title='Using ACE_SPIPE_Acceptor with ACE_Reactor'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-112266035775248778</id><published>2005-07-29T10:44:00.000-07:00</published><updated>2005-08-25T11:16:02.603-07:00</updated><title type='text'>CruiseControl.NET, CVS and SSH password</title><content type='html'>I tried to setup up a build server using CruiseControl.NET (CCNET for short) and am not happy about CCNET's documentation. My CVS server is only accessible via SSH and it's password protected. I need to give CCNET a password so that it can login itself (btw, using public/private key provides few security improvement here, you better have a limited account for read only CVS access so that a tool like CCNET can use). I started to read the documentation, but soon lost on &lt;a href="http://confluence.public.thoughtworks.org/display/CCNET/Using+CruiseControl.NET+with+CVS"&gt;this page&lt;/a&gt;(Using CruiseControl.NET with CVS). It simply mentiones:&lt;br /&gt;"An example file is 'plinkwithpw.bat' in the tools sub-directory."&lt;br /&gt;&lt;br /&gt;But guess where is the tools sub-directory? I searched my installation dir and found nothing. And it's turned out to be in &lt;a href="http://cvs.sourceforge.net/viewcvs.py/ccnet/ccnet/tools/"&gt;their CVS&lt;/a&gt;! Since The script is so short, why not just put it in the documentation?&lt;br /&gt;&lt;br /&gt;The documentation page does no allow me to edit (not even to add a comment), so I just post the script here:&lt;br /&gt;&lt;br /&gt;0. I use Tortoise CVS in this example, so cvs.exe and plink.exe (renamed as TortoisePlink.exe) are already on my computer(C:\Program Files\TortoiseCVS). If you do not have one you need to download them.&lt;br /&gt;&lt;br /&gt;1. Create plinkwithpw.bat like this:&lt;br /&gt;@"C:\Program Files\TortoiseCVS\TortoisePlink.exe" -pw yourpassword %*&lt;br /&gt;&lt;br /&gt;2. Create cvswithplinkrsh.bat like this:&lt;br /&gt;@echo off&lt;br /&gt;set CVS_RSH="C:\Program Files\TortoiseCVS\plinkwithpw.bat"&lt;br /&gt;"c:\Program Files\TortoiseCVS\cvs.exe" %*&lt;br /&gt;&lt;br /&gt;3. Edit ccnet.config to have something like this:&lt;br /&gt;&lt;br /&gt;    &amp;lt;sourcecontrol type="cvs"&amp;gt;&lt;br /&gt;      &amp;lt;executable&amp;gt;C:\Program Files\TortoiseCVS\cvswithplinkrsh.bat&amp;lt;/executable&amp;gt;&lt;br /&gt;      &amp;lt;workingDirectory&amp;gt;C:\projects\YourProject&amp;lt;/workingDirectory&amp;gt;&lt;br /&gt;    &amp;lt;/sourcecontrol&amp;gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-112266035775248778?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/112266035775248778/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=112266035775248778' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112266035775248778'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112266035775248778'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/07/cruisecontrolnet-cvs-and-ssh-password.html' title='CruiseControl.NET, CVS and SSH password'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-112187731270241718</id><published>2005-07-20T08:44:00.000-07:00</published><updated>2006-09-25T07:26:54.666-07:00</updated><title type='text'>Force windbg to load symbols</title><content type='html'>I needed to analyze a crash dump yesterday but could not find the associated .pdb symbol file. Usually I check in all the binaries and symbols for public releases, but unfortunately there is a typo in my build script so that the symbol I am looking for is missing.&lt;br /&gt;&lt;br /&gt;I do have the source code on my version control system, so it is quite easy for me to rebuild the symbol file. It should match the binary, but winbdg refused to load it since the timestamp differs:&lt;br /&gt;&lt;br /&gt;*** WARNING: Unable to verify checksum for Your.dll&lt;br /&gt;*** ERROR: Symbol file could not be found.  Defaulted to export symbols for Your.dll &lt;br /&gt;&lt;br /&gt;Modifying the timestamp does not look easy, so I decided to force windbg to load the symbol. while impossible in VS.net, it is quiet easy with windbg, all you need is type in:&lt;br /&gt;&lt;br /&gt;.symopt+0x40&lt;br /&gt;&lt;br /&gt;This command indead enables SYMOPT_LOAD_ANYTHING option.&lt;br /&gt;&lt;br /&gt;Now a complete stack trace showed up, nice...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-112187731270241718?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/112187731270241718/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=112187731270241718' title='11 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112187731270241718'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/112187731270241718'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/07/force-windbg-to-load-symbols.html' title='Force windbg to load symbols'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>11</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-111946578285646890</id><published>2005-06-22T11:07:00.000-07:00</published><updated>2005-07-06T16:51:21.676-07:00</updated><title type='text'>Scripting ActiveX control in WSH</title><content type='html'>Last week is quite frustrating for me. I have a ActiveX control created by MFC ActiveX wizard. The control has been used in web browser (scripted by javascript) and runs very well. Recently I need to script it in WSH, but every method invoked failed with 'catastrophic failure' error message.&lt;br /&gt;&lt;br /&gt;The worse part is that it took me significant amount of time to find the answer from google group. I picked wrong words at the beginning which unfortunately generated lots of noise.&lt;br /&gt;&lt;br /&gt;The lesson: think harder about the search string instead wasting time on irrelevant results ("catastrophic failure activex wsh" is the best for this issue). And it's better if I go directly to the related news groups/maillists (microsoft.public.scripting.wsh in this case).&lt;br /&gt;&lt;br /&gt;Here I just quote the answer from Kyle Alons:&lt;br /&gt;&lt;br /&gt;&lt;div style="font-weight: lighter"&gt;&lt;br /&gt;"First, a little background: ActiveX controls are normally persisted to/from some type of permanent storage, and they do this by implementing one or more IPersist* interfaces.  Containers are supposed to call one of the IPersist methods to initialize or load the control upon creation. &lt;br /&gt;&lt;br /&gt;COleControl, which all MFC controls derive from, enforces that this initialization has taken place before allowing any calls to be made to the control (COleDispatchImpl::Invoke, line 1209 of OLEDISP1.CPP calls IsInvokeAllowed, which checks a protected m_bInitialized member variable for TRUE; this variable is set in the IPersist* implementations in CTLPSTM.CPP). &lt;br /&gt;&lt;br /&gt;Since WSH never calls the IPersist* methods, the above test fails, and the result is the 'catastrophic failure' error message.  The test control container (and VB6, which I also tested), are smart enough to detect when a control class has been instantiated and call an IPersist*-&gt;InitNew method to initialize the control. &lt;br /&gt;&lt;br /&gt;One workaround is to add the statement  m_bInitialized = TRUE; in your control's constructor.  This may be an acceptable workaround in this case, because the control isn't truly being hosted and its state isn't being loaded from anywhere.  This seems like an oversight by the WSH team, since most other environments don't require the workaround; on the outside chance that the MS developers are actually reading this, maybe they can address it. &lt;br /&gt;&lt;br /&gt;Kyle"&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-111946578285646890?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/111946578285646890/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=111946578285646890' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111946578285646890'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111946578285646890'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/06/scripting-activex-control-in-wsh.html' title='Scripting ActiveX control in WSH'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-111928374740081730</id><published>2005-06-20T08:20:00.000-07:00</published><updated>2005-08-26T13:51:04.940-07:00</updated><title type='text'>Unit Testing for Network Programming</title><content type='html'>Network program is error-prone to write and hard to test, how can we make our life easier with the help of unit testing? Let's start with short examples:&lt;br /&gt;&lt;br /&gt;Which function is easier to test?&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;int funcion1(const char* filename)&lt;br /&gt;{&lt;br /&gt;...open and process file...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int function2(std::istream&amp; stm)&lt;br /&gt;{&lt;br /&gt;...process file...&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The answer is function2: it avoids the dependency on external resource, so you can create a string and pass it in (see more on C++ coding standard item 63).&lt;br /&gt;&lt;br /&gt;This is a basic technique that every unit testing book will teach. To apply it to network programming, we need to choose a stubable high level abstraction (instead of the low level socket as integer).&lt;br /&gt;&lt;br /&gt;I use ACE as network library. While it provides very nice high level abstractions like ACE_SOCK_Stream, those classes are not designed to be base class (members are not virtual). This is understandable since lots of network programmers prefer to get the best performance they can. &lt;br /&gt;&lt;br /&gt;So we have two choices here:&lt;br /&gt;&lt;br /&gt;1. Use C++ template, and make the substitution happen at compile time.&lt;br /&gt;&lt;br /&gt;Or&lt;br /&gt;&lt;br /&gt;2. Create a wrapper to provide dynamic polymorphism (C++ coding style item 64).&lt;br /&gt;&lt;br /&gt;I choose the later since it provides more flexibility.&lt;br /&gt;&lt;br /&gt;Here is what the code looks like:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;class ISockStream&lt;br /&gt;{&lt;br /&gt;public:&lt;br /&gt; virtual ~ISockStream(){}&lt;br /&gt;&lt;br /&gt; virtual ssize_t send (const void *buf,&lt;br /&gt;     size_t n,&lt;br /&gt;     int flags = 0,&lt;br /&gt;     const ACE_Time_Value *timeout = NULL) = 0;&lt;br /&gt;&lt;br /&gt; virtual ssize_t recv (void *buf,&lt;br /&gt;     size_t n,&lt;br /&gt;     int flags = 0,&lt;br /&gt;     const ACE_Time_Value *timeout = NULL) = 0;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;template &amp;lt;class _ACE_PEER_STREAM&amp;gt;&lt;br /&gt;class StreamAdapter : public ISockStream&lt;br /&gt;{&lt;br /&gt;protected:&lt;br /&gt; _ACE_PEER_STREAM stream_;&lt;br /&gt;public:&lt;br /&gt; ssize_t send (const void *buf,&lt;br /&gt;     size_t n,&lt;br /&gt;     int flags = 0,&lt;br /&gt;     const ACE_Time_Value *timeout = NULL)&lt;br /&gt; {&lt;br /&gt;  return stream_.send(buf, n, flags, timeout);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; ssize_t recv (void *buf,&lt;br /&gt;     size_t n,&lt;br /&gt;     int flags = 0,&lt;br /&gt;     const ACE_Time_Value *timeout = NULL)&lt;br /&gt; {&lt;br /&gt;  return stream_.recv(buf, n, flags, timeout);&lt;br /&gt; }&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;class MockStream : public ISockStream &lt;br /&gt;{&lt;br /&gt; ssize_t send (const void *buf,&lt;br /&gt;     size_t len,&lt;br /&gt;     int flags = 0,&lt;br /&gt;     const ACE_Time_Value *timeout = NULL)&lt;br /&gt; {&lt;br /&gt;  //save the data somewhere (std::string for example)&lt;br /&gt;  //so that we can test the result later.&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; ssize_t recv (void *buf,&lt;br /&gt;   size_t len,&lt;br /&gt;   int flags = 0,&lt;br /&gt;   const ACE_Time_Value *timeout = NULL)&lt;br /&gt; {&lt;br /&gt;  //generate fake data,&lt;br /&gt;  //we can even trigger failure (return -1).&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In real product, we are going to use things like StreamAdapter&amp;lt;ACE_SOCK_Stream&amp;gt;. While in unit testing, MockStream will be sufficient.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-111928374740081730?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/111928374740081730/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=111928374740081730' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111928374740081730'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111928374740081730'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/06/unit-testing-for-network-programming.html' title='Unit Testing for Network Programming'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-111885544292789977</id><published>2005-06-15T10:03:00.000-07:00</published><updated>2006-03-07T18:08:41.870-08:00</updated><title type='text'>Parser generator used for popular languages</title><content type='html'>Recently I need a parser generator in my new project, so I spent a while to check  what other people are using. Here is the result:&lt;br /&gt;&lt;br /&gt;Jython: JavaCC (with asdl)&lt;br /&gt;Python: YACC&lt;br /&gt;IronPython: Hand made recursive descent parser&lt;br /&gt;&lt;br /&gt;Rhino/SpiderMonkey: Hand made recursive descent parser&lt;br /&gt;&lt;br /&gt;Beanshell: JavaCC (with JJTree)&lt;br /&gt;Groovy: Antlr&lt;br /&gt;&lt;br /&gt;Boo: Antlr&lt;br /&gt;&lt;br /&gt;Ruby: YACC&lt;br /&gt;JRuby: Jay &lt;br /&gt;&lt;br /&gt;Mono C#: Jay&lt;br /&gt;&lt;br /&gt;Perl: YACC&lt;br /&gt;&lt;br /&gt;Eclipse JDT: &lt;a href="http://sourceforge.net/project/showfiles.php?group_id=128803&amp;package_id=144579"&gt;Jikes Parser generator&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;CFront: YACC, but Stroustrup actaully likes to have a hand made recursive descent parser, see [5]&lt;br /&gt;&lt;br /&gt;References:&lt;br /&gt;[1] &lt;a href = "https://coyote.dev.java.net/milestone2/plan2_1_syntaxcoloring.html"&gt; coyote: Syntax coloring&lt;/a&gt;&lt;br /&gt;[2] &lt;a href = "http://pydev.blogspot.com/2005/05/pydev-parser-future.html"&gt;Pydev parser... the future??!?!?!&lt;/a&gt;&lt;br /&gt;[3] &lt;a href = "http://sourceforge.net/mailarchive/message.php?msg_id=15077"&gt; Jan Arne Petersen on jruby-devel&lt;/a&gt;&lt;br /&gt;[4] &lt;a href="http://www.program-transformation.org/Transform/JavaAbstractSyntax"&gt;Java Abstract Syntax&lt;/a&gt;&lt;br /&gt;[5] &lt;a href="http://www.research.att.com/~bs/dne.html"&gt;Stroustrup, The Design and Evolution of C++&lt;/a&gt;&lt;br /&gt;[6] &lt;a href="http://www.eclipse.org/jdt/core/howto/generate%20parser/generateParser.html"&gt;JDT Core HowTo: Generate the Parser &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;To be continued...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-111885544292789977?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/111885544292789977/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=111885544292789977' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111885544292789977'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111885544292789977'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/06/parser-generator-used-for-popular.html' title='Parser generator used for popular languages'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-111834575912106408</id><published>2005-06-09T12:26:00.000-07:00</published><updated>2006-04-18T11:39:23.320-07:00</updated><title type='text'>"-ko" in tortoise cvs</title><content type='html'>When managing third party libraries, I like to create a repository in house (for C++, it includes headers and compiled libs). &lt;a href="http://www.amazon.com/exec/obidos/redirect?link_code=ur2&amp;tag=xyz0e-20&amp;camp=1789&amp;creative=9325&amp;path=http%3A%2F%2Fwww.amazon.com%2Fgp%2Fproduct%2F0974514004"&gt;Pragmatic Version Control Using CVS&lt;/a&gt;&lt;img src="http://www.assoc-amazon.com/e/ir?t=xyz0e-20&amp;amp;l=ur2&amp;amp;o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /&gt; also recommends this approach.&lt;br /&gt;&lt;br /&gt;One of the annoying thing you may encounter is the keyword expansion feature of CVS (I do not like it, so do the authors of the above cvs book). It means when importing/adding files, you have to specify "-ko"(keyword off) in command line. For tortoise CVS, you need to:&lt;br /&gt;&lt;br /&gt;1. Select all the files you want to add;&lt;br /&gt;2. Right Click, find "keywords" option, set it to "disabled(0)".&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-111834575912106408?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/111834575912106408/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=111834575912106408' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111834575912106408'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111834575912106408'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/06/ko-in-tortoise-cvs.html' title='&quot;-ko&quot; in tortoise cvs'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-111834514145393636</id><published>2005-06-09T12:06:00.000-07:00</published><updated>2005-06-09T14:07:29.393-07:00</updated><title type='text'>code or data?</title><content type='html'>I am thinking the two most common security problems - buffer overflow for binary program and cross site scripting for website - share the same nature: instead of treating user's input as pure data, the system/runtime may execute them as code, which in turn grant the user the ability to 'customize' some of the behavior of the program.&lt;br /&gt;&lt;br /&gt;Even though the modern compilers(like java and C#) fight hard to make buffer overrun disappear, those "executable data" will not go away (sql injection for example), and the restriction of sandbox can not help too much.&lt;br /&gt;&lt;br /&gt;In &lt;a href="research.microsoft.com/Comega/"&gt;Cω&lt;/a&gt;, researches start to add build-in support for data access and concurrency. Security may be on the list somedays, although now I have no idea how it fit in.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-111834514145393636?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/111834514145393636/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=111834514145393636' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111834514145393636'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111834514145393636'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/06/code-or-data.html' title='code or data?'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-111782834372496725</id><published>2005-06-03T12:39:00.000-07:00</published><updated>2005-06-15T08:26:09.740-07:00</updated><title type='text'>Suppressing splash screen of source insight</title><content type='html'>Source insight is my editor of choice for 6 years. The reason? It is super fast, especially when your are searching symbols in monster projects, like linux kernel, ACE and TAO.&lt;br /&gt;&lt;br /&gt;One small issue I feel annoying is the splash screen. The manual did a poor job here, it only tells me how to suppress the splash screen if I launch the program from command line (that is what I do most of the time), but occasionly I just want to launch it from windows explorer (by clicking an associated file), the splash screen just on my way.&lt;br /&gt;&lt;br /&gt;I sent their support an email, and their support(Ray Gram) emailed me back the solution in ten minutes! Well, I really fell shame for not asking the question ealier:)&lt;br /&gt;&lt;br /&gt;Since I can not find it via google (it is not in the current manual either) , let's share it:&lt;br /&gt;&lt;br /&gt;&lt;pre  style="font-size:12;"&gt;&lt;br /&gt;You can suppress the splash screen with the -s command line option.&lt;br /&gt;For example:&lt;br /&gt;&lt;br /&gt;Insight3 -s&lt;br /&gt;&lt;br /&gt;You can also do it by adding a registry value. Under the key:&lt;br /&gt;&lt;br /&gt;HKEY_CURRENT_USER\Software\Source Dynamics\Source Insight\3.0\Options&lt;br /&gt;&lt;br /&gt;Create a text value named "NoSplash" with a value of "1".&lt;br /&gt;&lt;br /&gt;Ray Gram&lt;br /&gt;Source Dynamics, Inc.&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Thank you, Ray!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-111782834372496725?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/111782834372496725/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=111782834372496725' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111782834372496725'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111782834372496725'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/06/suppressing-splash-screen-of-source.html' title='Suppressing splash screen of source insight'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-111774939416622470</id><published>2005-06-02T14:39:00.000-07:00</published><updated>2005-06-02T14:56:36.123-07:00</updated><title type='text'>Memory footprint</title><content type='html'>That was two months ago, I need to reduce the memory footprint of one of my application. I checked the "Mem Usage" column in windows task manager, the result is  surprsing: the process uses more than 10M just after it hits main().&lt;br /&gt;&lt;br /&gt;The good news is it did not take me long to figure out that "Mem Usage" means the size of the current working set, which includes the shared data, dynamic libaries (DLL) for example.&lt;br /&gt;&lt;br /&gt;Even the minimal hello world program requires lots of system dlls to run, so it takes about 1,000K after startup. If you add winsock, it soon becomes 1,500K.&lt;br /&gt;&lt;br /&gt;The &lt;a href="http://www.flounder.com/howbig.htm"&gt;article of Joseph M. Newcomer&lt;/a&gt; explained the topic very well. And &lt;a href="http://www.itwriting.com/dotnetmem.php"&gt;this one&lt;/a&gt; touched .NET.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-111774939416622470?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/111774939416622470/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=111774939416622470' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111774939416622470'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111774939416622470'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/06/memory-footprint.html' title='Memory footprint'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-111721142740472059</id><published>2005-05-27T09:04:00.000-07:00</published><updated>2005-05-27T09:31:26.696-07:00</updated><title type='text'>Trusted and un-trusted vulnerability assessment</title><content type='html'>I read a article titled &lt;a href="http://www.securitypark.co.uk/article.asp?articleid=23673"&gt;From SATAN to OVAL: The Evolution of Vulnerability Assessment&lt;/a&gt; today, and I really like the term "Trusted" and "un-trusted" vulnerability assessment.&lt;br /&gt;&lt;br /&gt;As Dr. Gerhard Eschelbeck put in his article:&lt;br /&gt;"Un-trusted vulnerability assessments simulate the scenario of an attacker without prior knowledge about the target system, while trusted assessments leverage credentials to log into the target systems for auditing configuration and patch information."&lt;br /&gt;&lt;br /&gt;Trusted vulnerability assessment is kind of the trend that scanner vendors are doing. One example is MS baseline scanner, another is nessus (its plugins number growed from less then 2000 to more than 8000 in 2 years, most of the new ones are "local checks"). The reason behind it is obvious: this is way easier to implement and it works well in enterprise environment (also make it less likly to be used a hacking tool).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-111721142740472059?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/111721142740472059/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=111721142740472059' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111721142740472059'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111721142740472059'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/05/trusted-and-un-trusted-vulnerability.html' title='Trusted and un-trusted vulnerability assessment'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-111720973350156066</id><published>2005-05-27T08:58:00.000-07:00</published><updated>2005-05-27T09:03:51.186-07:00</updated><title type='text'>Security and Testing Conferences</title><content type='html'>Secure Programming Group at University of Oulu (Finland) maintained a very nice list of Security and Testing Conferences. I had tried to do same something on my little personal website when I was in school, but lost interest to update it after graduation:(&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.ee.oulu.fi/research/ouspg/sage/conferences/index.html"&gt;http://www.ee.oulu.fi/research/ouspg/sage/conferences/index.html&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-111720973350156066?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/111720973350156066/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=111720973350156066' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111720973350156066'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111720973350156066'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/05/security-and-testing-conferences.html' title='Security and Testing Conferences'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-111662636243929213</id><published>2005-05-20T14:29:00.000-07:00</published><updated>2005-08-25T11:32:14.716-07:00</updated><title type='text'>Building native C++ projects with NAnt</title><content type='html'>I have not tried nant for a long time because I thought(wrongly) it is just for .NET, and my daily job involves only native C++.&lt;br /&gt;&lt;br /&gt;My current build process use &lt;a href="http://www.ociweb.com/product/mpc/"&gt;MPC&lt;/a&gt;, devenv command line and batch script. I like MPC a lot(especially the idea of inheritance used the build process). MPC's template approach can help me to create .sln and .vcproj with very little effort.&lt;br /&gt;&lt;br /&gt;Devenv.com is helpful as well, although it is a little bit slow. vcbuild.exe is faster, but there are some small issues I do not like (the devil is always in the details).&lt;br /&gt;&lt;br /&gt;I uses batch script(.bat) to glue the build process together, but I really hate to program in this old awkward langage. I resisted to put more error handling because it can easily mess up the script.&lt;br /&gt;&lt;br /&gt;So I decided to switch to nant after I found it can handle c++ project as well. Even though it takes me a while to figure it out, using nant is quiet easy. The solution task is great idea (know how to live peacefully with others is important:)): no need to write verbose build script and no need to wot worry about keeping it in sync with visual studio.&lt;br /&gt;&lt;br /&gt;If all the environment variables are setup correctly (I will take about the tricks later), the build file can be as simple as this(and it is faster than devenv):&lt;br /&gt;&lt;br /&gt;&amp;lt;?xml version="1.0" ?&amp;gt;&lt;br /&gt;&amp;lt;project name="myproject" default="all" xmlns="http://nant.sf.net/schemas/nant.xsd"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;lt;target name="all" depends="debug, release" /&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;lt;target name="debug"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;solution solutionfile="myproject.sln" configuration="Debug" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;lt;/target&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;lt;target name="release"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;solution solutionfile="myproject.sln" configuration="Release" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;lt;/target&amp;gt;&lt;br /&gt;&amp;lt;/project&amp;gt;&lt;br /&gt;&lt;br /&gt;Unless you run nant from Visual Stuio 2003 Command Prompt, you may see lots of erros about missing headers and libs. This is because you need a few more environment varibles(PATH, INCLUDE and LIB). Visual studio will set them up for itself (see vcvars32.bat) and nant are not aware of them (it knows only system level environment varibles).&lt;br /&gt;&lt;br /&gt;Nant supports setenv task so it looks like good place to go. But it will bloat the build file. Why not just use vcvars32.bat? If you are following the installation procedure of nant, you can just add a line into your nant.bat:&lt;br /&gt;&lt;br /&gt;@echo off&lt;br /&gt;@call "C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Tools\vsvars32.bat"&lt;br /&gt;"C:\tools\nant-0.85-rc3\bin\NAnt.exe" %*&lt;br /&gt;&lt;br /&gt;You can also use "HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun" so that vcvars32.bat is launched everytime cmd.exe is created. For cygwin users you know what to do:)&lt;br /&gt;&lt;br /&gt;There is a &lt;a href="http://sourceforge.net/tracker/?func=detail&amp;aid=1215811&amp;group_id=31650&amp;atid=402868"&gt;small issue&lt;/a&gt; in the current release (0.85 Release Candidate 3):  rc files can include c++ header files. Resource.h is one of them. And &lt;a href="http://support.microsoft.com/kb/q237870/"&gt;this practice&lt;/a&gt; uses it as well. But in the source code(nant-0.85-rc3\src\NAnt.VisualCpp\Tasks\RcTask.cs::NeedsCompiling), the date of the header files are not checked. So if you modified the include file, the resource will be rebuilt.&lt;br /&gt;&lt;br /&gt;Btw, nant uses its own algorithm to calculate the dependencies between files, so you may see different compilation sequence between nant and devenv, it's even true for C# projetcs.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-111662636243929213?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/111662636243929213/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=111662636243929213' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111662636243929213'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111662636243929213'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/05/building-native-c-projects-with-nant.html' title='Building native C++ projects with NAnt'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-111661823206162502</id><published>2005-05-20T12:17:00.000-07:00</published><updated>2005-05-20T13:25:24.850-07:00</updated><title type='text'>windbg beated VS.NET debugger</title><content type='html'>Our QA guy sent me a minidump file of crashed service and asked my help. The developer who wrote the program forgot to check in the full debug symbol file, but we do have the stripped .pdb file since we always ship it along with our product (following the advise of John Robbins).&lt;br /&gt;&lt;br /&gt;I opened the minidump file with Visual Studio .NET debugger, but this time it did a terrible job reconstructing stack trace (later I find out the information it gave me is misleading, which is worse than useless). Well, I soon switched to windbg, and it showed me the correct result. The bug was found(printf again!) and fixed in less than 10 minutes, thanks to windbg.&lt;br /&gt;&lt;br /&gt;Last time windbg beated VS.NET debugger on my system is a program deadlocked in the system space and VS.NET debugger can not break into it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-111661823206162502?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/111661823206162502/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=111661823206162502' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111661823206162502'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111661823206162502'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/05/windbg-beated-vsnet-debugger.html' title='windbg beated VS.NET debugger'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-111660828648599503</id><published>2005-05-20T09:25:00.000-07:00</published><updated>2005-05-20T09:59:29.240-07:00</updated><title type='text'>Use devenv in cygwin</title><content type='html'>I use cygwin as a better shell, not a development environment. Cygwin can do an excellent job as a replacement of cmd.exe(of course it can do much much more), and I like it very much.&lt;br /&gt;&lt;br /&gt;There is a few corner cases where command behaves differently in cygwin and cmd.exe, for example:&lt;br /&gt;&lt;br /&gt;When you type 'devenv' in cmd.exe, it will bring up devenv.com, which is expected since Windows prefers .com to .exe if both exist in the user's PATH (see the &lt;a href="http://msdn.microsoft.com/msdnmag/issues/04/02/CQA/"&gt;article&lt;/a&gt; in C++ QA column of the February 2004 issue of MSDN Magazine). But when you type 'devenv' in  cygwin, it will launch devenv.exe instead, the project will get compiled anyway but you can no longer see the output of the compilation process.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-111660828648599503?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/111660828648599503/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=111660828648599503' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111660828648599503'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111660828648599503'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/05/use-devenv-in-cygwin.html' title='Use devenv in cygwin'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-111645351147115100</id><published>2005-05-18T14:26:00.000-07:00</published><updated>2005-05-18T15:07:30.853-07:00</updated><title type='text'>"Files and Folders" View of InstallShield</title><content type='html'>InstallShield gives you a nice "Files and Folders" view(Application Data) and lets you add new components as drag and drop files. It is very easy for a developer to jumpstart an installation project without reading any documents. But it does not mean you can totally forget the existence of component table.&lt;br /&gt;&lt;br /&gt;Recently I find out there are lots of duplicated components in my project, they have the same name but different suffix, for example: mylib.dll1, mylib.dll2, mylib.dll3. It confused me for a while because I am not sure if I should delete some of them(as a developer, removing duplication becomes my habit:)).&lt;br /&gt;&lt;br /&gt;Until recently I find out that if you delete files from "Files and Folders" view, they won't be removed from the component table. And after you add the same file again, InstallShield will create a new component named yourfile.dll1(.dll2 if .dll1 exists already). By the way, they will be considered to be different components since the component code changed.&lt;br /&gt;&lt;br /&gt;Maybe InstallShield thinks it's nice to keep them for people don't use version control:)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-111645351147115100?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/111645351147115100/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=111645351147115100' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111645351147115100'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111645351147115100'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/05/files-and-folders-view-of.html' title='&quot;Files and Folders&quot; View of InstallShield'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-111600945505404505</id><published>2005-05-13T11:21:00.000-07:00</published><updated>2005-05-18T20:21:00.830-07:00</updated><title type='text'>Give Up Microsoft Visual C++ Toolkit 2003</title><content type='html'>I tried to get some free lunch from Microsoft Visual C++ Toolkit 2003, but finally gives up. There are lots of missing pieces, most of them can be fixed by downloading other packages, but it is tedious and may not be allowed.&lt;br /&gt;&lt;br /&gt;There are a few problems I encountered:&lt;br /&gt;&lt;br /&gt;1. Only static-link C/C++ libraries are available, so you can not use /MD, /MDD by default. &lt;a href="http://www.codecomments.com/archive307-2004-8-266145.html"&gt;this link&lt;/a&gt; introduced a hack but as mentioned in the same article it has its limits.&lt;br /&gt;&lt;br /&gt;2. Do not have a build system. It's easy to generate solution(.sln) and project (.vcproj) with &lt;a href="http://www.ociweb.com/product/mpc/"&gt;MPC&lt;/a&gt;, and we can use &lt;a href="http://www.gotdotnet.com/team/cplusplus/"&gt;vcbuild.exe&lt;/a&gt; to compile them. But soon you will find out vcbuild requires several dlls from VS C++ 2003, even through you can copy some dlls from there to make it work(see &lt;a href="http://www.codecomments.com/archive292-2004-8-265438.html"&gt;this article&lt;/a&gt;). So you have to purchase a copy of VS C++ anyway.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-111600945505404505?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/111600945505404505/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=111600945505404505' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111600945505404505'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111600945505404505'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/05/give-up-microsoft-visual-c-toolkit.html' title='Give Up Microsoft Visual C++ Toolkit 2003'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-111463369466374205</id><published>2005-04-27T13:07:00.000-07:00</published><updated>2005-05-24T14:04:37.423-07:00</updated><title type='text'>When URL moniker meets security problems</title><content type='html'>URL moniker is a very useful. For example, URLDownloadToFile allows you to download files using IE. While it's easy to write code to do that job yourself, the users may be appreciated if they do not have to config it for their proxy.&lt;br /&gt;&lt;br /&gt;Three months ago I met some problems with URLDownloadToFile when dealing with https url. If IE is used, it will pop up an error saying the certificate is not trusted, obviously the owner of the site does not want to spend money to get their certificate signed. URLDownloadToFile will simply fail in this case, it won't show you the dialog as IE does.&lt;br /&gt;&lt;br /&gt;To see the dialog, we need to implement a callback object and pass it to URLDownloadToFile. MSDN simply said the callback should implement BindStatusCallback, but here, we need IHttpSecurity as well. And most important method is GetWindow() method. URLDownloadToFile need this to report error.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;class Callback : public IBindStatusCallback, IHttpSecurity&lt;br /&gt;{&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt; STDMETHOD(GetWindow)(REFGUID rguidReason, HWND *phwnd)&lt;br /&gt; {&lt;br /&gt;  if (NULL != phwnd_)&lt;br /&gt;  {&lt;br /&gt;   (*phwnd) = (*phwnd_);&lt;br /&gt;  }&lt;br /&gt;  else&lt;br /&gt;  {&lt;br /&gt;   (*phwnd) = GetDesktopWindow();&lt;br /&gt;  }&lt;br /&gt;  return S_OK;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-111463369466374205?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/111463369466374205/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=111463369466374205' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111463369466374205'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111463369466374205'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/04/when-url-moniker-meets-security.html' title='When URL moniker meets security problems'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-111463191792601504</id><published>2005-04-27T12:38:00.000-07:00</published><updated>2005-04-27T13:03:10.823-07:00</updated><title type='text'>CPPUNIT: constructor/destructor VS setUp/tearDown</title><content type='html'>In C++, we used to use constructor and destructor to manage resources.&lt;br /&gt;In XUNIT, setUp() and tearDown() are favored instead. One of the reasons&lt;br /&gt;is that some langurages like Java have only undetermined garbage collector,&lt;br /&gt;while we need a "determined" way to clean up the state after each test.&lt;br /&gt;&lt;br /&gt;But in C++, we can use stack. As mentioned in&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/visualc/using/multimedia/oopsla/default.aspx"&gt;Herb Sutter's OOPSLA keynote&lt;/a&gt;, this approach has its own&lt;br /&gt;advantage. So when writing tests with CPPUNIT, I still prefer constructor/destructor over setUp/tearDown, and it works.&lt;br /&gt;&lt;br /&gt;There is a disadvantage, althrough it should be a implementation issue&lt;br /&gt;of CPPUNIT: TestFixtures' Constructor will be called before main() to register&lt;br /&gt;themself. So if your constructor fails, the whole program won't run at all.&lt;br /&gt;In this case, you have to call setUp().&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-111463191792601504?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/111463191792601504/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=111463191792601504' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111463191792601504'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111463191792601504'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/04/cppunit-constructordestructor-vs.html' title='CPPUNIT: constructor/destructor VS setUp/tearDown'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-111342427097952804</id><published>2005-04-13T13:12:00.000-07:00</published><updated>2005-05-24T13:51:02.426-07:00</updated><title type='text'>resize web browser control</title><content type='html'>I have a dialog based MFC application using Microsoft web browser control(IWebBrowser2). From the first version, I disabled the maximize box and used non-resizable border to avoid the painful layout of GUI elements. Now I want to make it resizable, so I edited the properties in resources: now the dialog itself is resizable, but the Active X control doesn't.&lt;br /&gt;&lt;br /&gt;I truned to google and hope it can be sovled in 5 minutes, but the search is&lt;br /&gt;not very successful. After about an hour I solved the problem myself, even though it is very simple, I decided to write it down so that another poor man can get helped.&lt;br /&gt;&lt;br /&gt;The solution is to use the OnSize() Event to size our control:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;BEGIN_MESSAGE_MAP(CWebBrwoserDlg, CDialog)&lt;br /&gt;    ON_WM_SYSCOMMAND()&lt;br /&gt;    ON_WM_PAINT()&lt;br /&gt;    ON_WM_SIZE()&lt;br /&gt;    ON_WM_QUERYDRAGICON()&lt;br /&gt;    //}}AFX_MSG_MAP&lt;br /&gt;END_MESSAGE_MAP()&lt;br /&gt;&lt;br /&gt;void CWebBrwoserDlg::OnSize(UINT nType, int cx, int cy)&lt;br /&gt;{&lt;br /&gt;    CDialog::OnSize(nType, cx, cy);//Call parent's OnSize first&lt;br /&gt;&lt;br /&gt;    if (m_browser.GetSafeHwnd() != NULL))//Make sure the windows is created.&lt;br /&gt;    {&lt;br /&gt;        m_browser.MoveWindow(0, 0, cx, cy);//resize browser control&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-111342427097952804?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/111342427097952804/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=111342427097952804' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111342427097952804'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111342427097952804'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/04/resize-web-browser-control.html' title='resize web browser control'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-111281709221903980</id><published>2005-04-06T12:37:00.000-07:00</published><updated>2005-10-10T08:21:33.036-07:00</updated><title type='text'>Faked port 25 from symantec antivirus software</title><content type='html'>Symantec antivirus software gives me lots of trouble recently. To check if an email contains virus, it somehow creates a fake port 25 to intercept the traffic. So if you have Symentec antivirus software installed on your desktop, whenever you telnet or call connect() to a port 25, it will always succeed regardless the state of the remote host, even if the host is down.&lt;br /&gt;&lt;br /&gt;So port scan using tcp connect will give lots of false positives unless you stop symentec antivirus service. To avoid that you have to bypass compromised tcp/ip stack. For example, synscan with pcap can give you better result, since there is no actual SYN/ACK back from the faked port.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-111281709221903980?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/111281709221903980/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=111281709221903980' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111281709221903980'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111281709221903980'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/04/faked-port-25-from-symantec-antivirus.html' title='Faked port 25 from symantec antivirus software'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-10398581.post-111281585979847559</id><published>2005-04-06T11:47:00.000-07:00</published><updated>2005-08-25T14:22:04.260-07:00</updated><title type='text'>Bug in Netscape Internet Service software</title><content type='html'>I spent almost a day on a "bug" appeared in my program, which is a very simple portscanner using non-blocking tcp connect. I closed all the sockets after they are used, but boundchecker still complains about "Outstanding Allocations", and the call path is "My Program-&gt;ws2_32.dll-&gt;sliplsp.dll". Actually I should pay more attention to sliplsp.dll, but at that moment, ws2_32.dll convinced me that the bug is in my program.&lt;br /&gt;&lt;br /&gt;I opened windows task manager and noticed that the handle count keeps increasing. To see the details about the handle I launched &lt;a href ="http://www.sysinternals.com/ntw2k/freeware/procexp.shtml"&gt;Process Explorer&lt;/a&gt;, and found out there are lots of file handles named "\Device\WS2IFSL\NifsSct". What the hell is that?&lt;br /&gt;&lt;br /&gt;Even google can not help, there is no useful discussion of NifsSct at all.&lt;br /&gt;&lt;br /&gt;My program is quiet simple, but to be 100% sure, I started to use simple code to test, and found something interesting:&lt;br /&gt;1. After socket() succeed, a new handle called "\Device\Afd\Endpoint" will be created.&lt;br /&gt;2. After connect() succeed, a new handle called "\Device\Tcp" will be created.&lt;br /&gt;3. After closesocket(), all of them will be closed.&lt;br /&gt;&lt;br /&gt;But the problem is, "\Device\WS2IFSL\NifsSct" will be created along with the other two, and I have no idea what they are. Finally I had to give up after several hours of pointless efforts.&lt;br /&gt;&lt;br /&gt;Then another day came. I want to solve another myth I saw: after reading tons of good words about Ruby on Rails, I want to give it a try myself, but the installation of rails("gem install rails") always deadlock ruby.exe. I was very disappointed about ruby at that moment, since there are source code at hand, I decided  to find the "bug" and fix it.&lt;br /&gt;&lt;br /&gt;Then my eyes opened: the debugger shows ruby.exe loads "C:\Programs Files\Netscape Internet Service\sliplsp.dll". Hah? I turned back to boundcheck, and enabled the full path in the view, it is the same dll!&lt;br /&gt;&lt;br /&gt;I have had some bad experience before with programs hooked up with standard network stack. So I uninstalled Netscape Internet Service, deleted its folder after reboot, then everything goes fine. There is no more leaking \Device\WS2IFSL\NifsSct and I finally get rails installed.&lt;br /&gt;&lt;br /&gt;There are not too much users in the world use Netscape Internet Service. It explains why there are no discussion about it at all.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/10398581-111281585979847559?l=seclib.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://seclib.blogspot.com/feeds/111281585979847559/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=10398581&amp;postID=111281585979847559' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111281585979847559'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/10398581/posts/default/111281585979847559'/><link rel='alternate' type='text/html' href='http://seclib.blogspot.com/2005/04/bug-in-netscape-internet-service.html' title='Bug in Netscape Internet Service software'/><author><name>xue.yong.zhi</name><uri>http://www.blogger.com/profile/13007279094431940132</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
