An I/O Completion Port Template

Here’s another useful class: wiocp::IoCompPort. This template
wraps the I/O Completion port apis in a way that makes it very easy to create your own
IOCP-based server applications.

The class is defined like this:

  template <
    class T,          // derived class
    class TOV,        // overlapped class (you can use DefOverlapped)
    class TCK         // completion key class
  > class IoCompPort

Using IoCompPort is very easy: Just derive your own class from IoCompPort
and implement a few functions.

What are the benefits: IoCompPort wraps the ugly IOCP apis with type-safe template fuctions.
It also saves you from having to call the apis directly, since it handles the IOCP thread-pool for you,
taking care of thread creation/destruction, and just calling your implementation function to
process I/O requests. Another benefit is that it allows you to easily pass all the state information
you need on your io requests either through the OVERLAPPED struct or through the CompletionKey
(wiocp.h has all the information you need to use either or both!).

UPDATE 08/01/2001: Thanks to Andrew MacLean for pointing out to me that with a simple
fix, the ban on virtual functions in the OVERLAPPED-derived class could be lifted (and beating the
thing on my head several times until I fixed it . Thanks Andrew!

Here’s the file:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>