<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Rambling Comments</title>
    <link rel="alternate" type="text/html" href="http://www.lenholgate.com/blog/" />
    <link rel="self" type="application/atom+xml" href="http://www.lenholgate.com/blog/atom.xml" />
    <id>tag:www.lenholgate.com,2010-12-10:/blog//12</id>
    <updated>2012-03-27T06:04:32Z</updated>
    
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Pro 5.12</generator>

<entry>
    <title>Netmap, RIO and the challenges in using a 10 Gigabit pipe</title>
    <link rel="alternate" type="text/html" href="http://www.lenholgate.com/blog/2012/03/netmap-rio-and-the-challenges-in-using-a-10-gigabit-pipe.html" />
    <id>tag:www.lenholgate.com,2012:/blog//12.1179</id>

    <published>2012-03-26T20:46:06Z</published>
    <updated>2012-03-27T06:04:32Z</updated>

    <summary> This link, Revisiting Network I/O APIs: The Netmap Framework, via highscalability.com makes for interesting reading. Especially given my current interest in the performance of the Winsock Registered I/O networking extensions, RIO, and the fact that my new network cards...</summary>
    <author>
        <name>Len</name>
        
    </author>
    
        <category term="Winsock Registered I/O" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.lenholgate.com/blog/">
        <![CDATA[<div>
This link, <a href="http://highscalability.com/blog/2012/3/22/paper-revisiting-network-io-apis-the-netmap-framework.html" target="_blank">Revisiting Network I/O APIs: The Netmap Framework</a>, via <a href="http://highscalability.com/" target="_blank">highscalability.com</a> makes for interesting reading. Especially given my current interest in the performance of <a href="http://www.serverframework.com/asynchronousevents/2012/03/windows-8-registered-io-performance.html" target="_blank">the Winsock Registered I/O networking extensions, RIO</a><a>, and the fact that </a><a href="http://www.serverframework.com/asynchronousevents/2012/03/windows-8-registered-io-performance---10-gigabit-networking.html" target="_blank">my new network cards</a> are so difficult to fully utilise.
</div> ]]>
        
    </content>
</entry>

<entry>
    <title>Visual Studio 11, the UI changes don&apos;t matter...</title>
    <link rel="alternate" type="text/html" href="http://www.lenholgate.com/blog/2012/03/visual-studio-11-the-ui-changes-dont-matter.html" />
    <id>tag:www.lenholgate.com,2012:/blog//12.1173</id>

    <published>2012-03-09T21:50:40Z</published>
    <updated>2012-03-10T18:16:02Z</updated>

    <summary> The best thing about Visual Studio 11 is that it doesn&apos;t matter if you like the new style IDE or not. The project files are, at last, backwards compatible, so you can load them in Visual Studio 2010 and...</summary>
    <author>
        <name>Len</name>
        
    </author>
    
        <category term="Geek Speak" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.lenholgate.com/blog/">
        <![CDATA[<div>
The best thing about Visual Studio 11 is that it doesn't matter if you like the new style IDE or not. The project files are, at last, backwards compatible, so you can load them in Visual Studio 2010 and build with the new tool chain even though you ignore the new IDE - if that's what you want to do.  
</div> 
<div><br /></div>
<div>
I don't <i>like</i> the new icons, but I find I can work fine in the IDE as long as I don't think about it too much... Probably pretty much like how I felt about all previous versions when they were at the beta stage...
</div> ]]>
        
    </content>
</entry>

<entry>
    <title>RFC 6455: The WebSocket protocol</title>
    <link rel="alternate" type="text/html" href="http://www.lenholgate.com/blog/2011/12/rfc-6455-the-websocket-protocol.html" />
    <id>tag:www.lenholgate.com,2011:/blog//12.1161</id>

    <published>2011-12-14T08:46:47Z</published>
    <updated>2011-12-14T09:03:46Z</updated>

    <summary> I know I&apos;ve said this before, but now it&apos;s really done... The WebSocket protocol is now an official RFC. There are a small number of changes between RFC 6455 and the draft WebSocket protocol version 17; the only important...</summary>
    <author>
        <name>Len</name>
        
    </author>
    
        <category term="Geek Speak" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Socket Servers" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.lenholgate.com/blog/">
        <![CDATA[<div>
I know <a href="http://www.lenholgate.com/blog/2011/09/the-websocket-protocol-is-done.html">I've said this before</a>, but now it's really done...
</div>
<div><br/></div>
<div>
The WebSocket protocol is now an official RFC. There are a small number of changes between RFC 6455 and the draft WebSocket protocol version 17; the only important ones being he addition of two new close status codes. The rest is just a case of tidying up the draft.
</div>
<div><br/></div>
<div>
There will be a 6.5.3 release of <a href="http://www.serverframework.com/products---the-websockets-option.html" target="_blank">The Server Framework</a> to include these changes.
</div>]]>
        
    </content>
</entry>

<entry>
    <title>Inside the Windows 8 Registered I/O Extensions, RIO</title>
    <link rel="alternate" type="text/html" href="http://www.lenholgate.com/blog/2011/10/inside-the-windows-8-registered-io-extensions-rio.html" />
    <id>tag:www.lenholgate.com,2011:/blog//12.1144</id>

    <published>2011-10-24T20:30:38Z</published>
    <updated>2012-03-16T21:47:03Z</updated>

    <summary> Before I started to look at RIO for inclusion in The Server Framework I did a quick check on the Microsoft BUILD site to see if there were any sessions that dealt with it specifically, I didn&apos;t find any....</summary>
    <author>
        <name>Len</name>
        
    </author>
    
        <category term="Socket Servers" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Winsock Registered I/O" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.lenholgate.com/blog/">
        <![CDATA[<div>
Before I started to look at <a href="http://www.serverframework.com/asynchronousevents/2011/10/windows-8-registered-io-networking-extensions.html">RIO for inclusion in The Server Framework</a> I did a quick check on the <a href="http://www.microsoft.com/presspass/events/build/" target="_blank">Microsoft BUILD</a> site to see if there were any sessions that dealt with it specifically, I didn't find any. Once I posted my blog posting I did another check and <a href="http://channel9.msdn.com/Events/BUILD/BUILD2011/SAC-593T" target="_blank">found this video that deals specifically with RIO</a>. This gives some in depth details of how RIO works and the kinds of performance improvements that Microsoft has witnessed in their labs. It's interesting and impressive.
</div> 
<div><br /></div>
<div>
One thing that I hadn't realised is that with RIO, <code>SO_SNDBUF</code> and <code>SO_RCVBUF</code> are no longer applicable with RIO, it's as if you're operating with them set to zero. You need to always have recvs pending if you don't want to drop datagrams...
</div>
<div><br /></div>
<div>
More once I've watched it all...
</div>]]>
        
    </content>
</entry>

<entry>
    <title>The WebSocket protocol is done...</title>
    <link rel="alternate" type="text/html" href="http://www.lenholgate.com/blog/2011/09/the-websocket-protocol-is-done.html" />
    <id>tag:www.lenholgate.com,2011:/blog//12.1138</id>

    <published>2011-09-27T11:05:33Z</published>
    <updated>2011-09-27T11:36:48Z</updated>

    <summary> Version 16 of the draft WebSocket protocol specification was just released and the HyBi mailing list announcement for this version contained the following: Chairs and editors believe that this version is final (before the publication of the RFC). Thank...</summary>
    <author>
        <name>Len</name>
        
    </author>
    
        <category term="Socket Servers" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.lenholgate.com/blog/">
        <![CDATA[<div>
Version 16 of <a href="http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-16" target="_blank">the draft WebSocket protocol specification</a> was just released and the HyBi mailing list announcement for this version contained the following:
</div>
<div><br /></div>
<div>
<i>Chairs and editors believe that this version is final (before the publication of the RFC). Thank you to everybody who helped to get this completed and for the stimulating discussions on the way.</i>
<br />
<i>Now feel free to discuss extensions, WebSocket 1.1, etc. :-).</i>
</div>
<div><br /></div>
<div>
There are no major differences between this and version 13 and the version number of the protocol itself stays at 13 so <a href="http://www.serverframework.com/products---the-websockets-option.html" target="SF">The WebSockets Option Pack</a> supports everything that will be in the final RFC.
</div>
]]>
        
    </content>
</entry>

<entry>
    <title>Designing an asynchronous server-side API for WebSockets </title>
    <link rel="alternate" type="text/html" href="http://www.lenholgate.com/blog/2011/09/designing-an-asynchronous-server-side-api-for-websockets.html" />
    <id>tag:www.lenholgate.com,2011:/blog//12.1137</id>

    <published>2011-09-27T09:24:04Z</published>
    <updated>2011-09-27T10:53:18Z</updated>

    <summary><![CDATA[ I've just released The WebSockets Option Pack for The&nbsp;Server&nbsp;Framework and I think it's worth running through why the API that I designed ended up as it did. This will probably end up as part of The Server Framework's WebSockets...]]></summary>
    <author>
        <name>Len</name>
        
    </author>
    
        <category term="Socket Servers" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.lenholgate.com/blog/">
        <![CDATA[<div>
I've just released <a href="http://www.serverframework.com/products---the-websockets-option.html" target="SF">The WebSockets Option Pack</a> for <a href="http://www.serverframework.com" target="SF">The&nbsp;Server&nbsp;Framework</a> and I think it's worth running through why the API that I designed ended up as it did. This will probably end up as part of <a href="http://www.serverframework.com/ServerFramework/latest/Docs/websockettoolsoverview.html" target="SF">The Server Framework's WebSockets documentation</a>, which is currently a little sparse.
</div>
]]>
        <![CDATA[<div>
The WebSockets protocol is <a href="http://www.lenholgate.com/blog/2011/07/websockets-is-a-stream-not-a-message-based-protocol.html">a message based protocol with unbounded message sizes</a>. This makes a general purpose API more difficult to design as some clients of the API may wish to work in terms of discrete messages and some may wish to work in terms of streams of data. Due to the possibility of frame fragmentation occurring between the client and the server (due to unknown intermediaries being present in the data path) the server-side cannot assume that it will be able to determine the size of an individual message in advance of receiving the final frame for that message.
</div>
<div><br /></div>
<div><a href="http://www.lenholgate.com/blog/assets_c/2011/09/WebSocketsAPI-100ByteMessage-295.html" onclick="window.open('http://www.lenholgate.com/blog/assets_c/2011/09/WebSocketsAPI-100ByteMessage-295.html','popup','width=743,height=203,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false"><img src="http://www.lenholgate.com/blog/assets_c/2011/09/WebSocketsAPI-100ByteMessage-thumb-500x136-295.png" width="500" height="136" alt="WebSocketsAPI-100ByteMessage.png" class="mt-image-none" /></a>
</div>
<div><br /></div>
<div>
Whilst the client code may only ever generate messages that are 100 bytes or less the server could receive those messages as (in the worst case) a sequence of 100 frames each of 1 byte. Since each fragmented frame contains only the size of the current fragment there is no way for the server to determine that the message is 100 bytes long until the final fragment arrives.
</div>
<div><br /></div>
<div><a href="http://www.lenholgate.com/blog/assets_c/2011/09/WebSocketsAPI-FragmentedMessage-298.html" onclick="window.open('http://www.lenholgate.com/blog/assets_c/2011/09/WebSocketsAPI-FragmentedMessage-298.html','popup','width=743,height=411,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false"><img src="http://www.lenholgate.com/blog/assets_c/2011/09/WebSocketsAPI-FragmentedMessage-thumb-500x276-298.png" width="500" height="276" alt="WebSocketsAPI-FragmentedMessage.png" class="mt-image-none" /></a>
</div>
<div><br /></div>
<div>
Often the code that's using the server-side API will also be the code that deploys the client side code which is communicating with it, this allows that code to know things about the messaging it's expecting, after all, it's quite likely that the same organisation created both the client and server code. The challenge for The Server Framework's WebSockets API is to expose the underlying Websockets connection in such a way that the user of the API can decide how best to deal with the inbound data. It's tempting to simply structure the API to work in terms of a series of streams and to pass the problems of message accumulation on to the user of the API, however I felt that was taking the easy way out and doing the users of the API a disservice. Instead the API can be configured to work in terms of complete, distinct, messages as long as they will fit into a single 'buffer' and then degrade to working in terms of a stream if the message is too large. Since the user of the API gets to determine how big the buffers that they use are, they can select a size that is appropriate for their message size, if that is important to them. Users who would prefer to work with streams, or who are working in terms of a single unending stream of data rather than discrete messages, can opt to receive data as it arrives rather than having it accumulated inside The Server Framework's WebSockets API.
</div>
<div><br /></div>
<div>
The API interface looks something like this.
</div>
<div><br /></div>
<div>
<pre class="brush: cpp gutter: false">      virtual void OnData(
         JetByteTools::WebSocket::HyBi::IWebSocket &amp;socket,
         const JetByteTools::Win32::_tstring &amp;text,
         const JetByteTools::WebSocket::MessageStatus status,
         const __int64 messageBytesOutstanding);

      virtual void OnData(
         JetByteTools::WebSocket::HyBi::IWebSocket &amp;socket,
         JetByteTools::IO::IBuffer &amp;buffer,
         const JetByteTools::WebSocket::MessageType type,
         const JetByteTools::WebSocket::MessageStatus status,
         const __int64 messageBytesOutstanding);
</pre>
</div>
<div><br /></div>
<div>
Where <code>type</code> tells us if we have a binary message or a text message, <code>status</code> tells us if this data forms a complete message or if it's just part of the message and <code>messageBytesOutstanding</code> tells us how many bytes are still to come, if it can be determined. There are two versions of the <code>OnData()</code> callback because some clients of the API may wish to work in terms of text messages presented to them pre-converted from UTF-8 into a <code>string</code> and some may prefer the flexibility of having the <code>IBuffer</code> interface passed to them so that they can, in turn, pass it off to another thread for processing, perhaps, using the reference counting functionality that's built into the buffer system.
</div>
<div><br /></div>
<div>
When configuring your server you decide on the size of buffers used and whether the WebSockets protocol handler accumulates messages or simply passes you the data as it arrives. See <a href="http://www.serverframework.com/ServerFramework/latest/Docs/examples-websocketservers.html" target="SF">the WebSockets example servers</a> for more details.
</div>
<div><br /></div>
<div>
When configured correctly a message based implementation could process discrete messages from a WebSockets connection like this:
</div>
<div><br /></div>
<div>
<pre class="brush: cpp gutter: false">void CSocketServer::OnData(
   IWebSocket &amp;socket,
   IBuffer &amp;buffer,
   const MessageType type,
   const MessageStatus status,
   const __int64 messageBytesOutstanding)
{
   if (status != MessageStatusComplete)
   {
      throw CException(
         _T("CSocketServer::OnData()"),
         _T("Unexpected: message larger than buffer size"));
   }

   if (messageBytesOutstanding != 0)
   {
      throw CException(
         _T("CSocketServer::OnData()"),
         _T("Unexpected: message larger than buffer size: ") + ToString(messageBytesOutstanding) + _T(" outstanding"));
   }

   if (type == MessageTypeText)
   {
      // Process a text message
   }
   else
   {
      // Process a binary message
   }

   socket.TryRead();  // Read a new message into a new buffer
}
</pre>
</div>
<div><br /></div>
<div>
You may wish to do your message accumulation yourself, perhaps because the inbound data is actually a stream of application messages presented as a sequence of WebSockets fragments (and remember, you can't rely on the fragments that are sent being the same size as the fragments that are received!). In this case it would be normal to sometimes pass the buffer that you received back to the next call to read so that more data can be added to the end of the buffer...
</div>
<div><br /></div>
<div>
<pre class="brush: cpp gutter: false">   socket.TryRead(&amp;buffer);  // Read more data into this buffer
}
</pre>
</div>
<div><br /></div>
<div>
Accumulating messages larger than your buffer size is easy if you simply chain the buffers together once they're full.
</div>
<div>
<pre class="brush: cpp gutter: false">void CPerConnectionData::OnData(
   IWebSocket &amp;socket,
   IBuffer &amp;buffer,
   const MessageType type,
   const MessageStatus status,
   const __int64 messageBytesOutstanding)
{
   if (m_messageSize == 0)
   {
      m_messageType = type;
   }
   else if (m_messageType != type)
   {
      throw CException(_T("CPerConnectionData::OnDataFrame()"), _T("Unexpected frame type"));
   }

   if (status == MessageStatusComplete &amp;&amp; messageBytesOutstanding == 0)
   {
      AddBuffer(buffer);

      EchoMessage(socket);

      socket.TryRead();
   }
   else if (buffer.GetSize() == buffer.GetUsed())
   {
      AddBuffer(buffer);

      socket.TryRead();
   }
   else
   {
      socket.TryRead(&amp;buffer);
   }
}

void CPerConnectionData::AddBuffer(
   IBuffer &amp;buffer)
{
   const IBuffer::BufferSize used = buffer.GetUsed();

   if (used || m_messageBuffers.IsEmpty())
   {
      m_messageSize += used;

      m_messageBuffers.Add(buffer);
   }
}
</pre>
</div>
<div><br /></div>
<div>
Sending data would be simple if we restricted the user to buffer sized chunks or to single send calls, however an API user may wish to send very large messages, or to send a sequence of fragments where the actual message size is unknown at the time when the message is started. The API supports both of these options as well as the simple 'send a buffer as a text/binary message' option.
</div>
<div><br /></div>
<div>
Here we send a single buffer as a discrete WebSockets message.
</div>
<div><br /></div>
<div>
<pre class="brush: cpp gutter: false">   if (type == MessageTypeText)
   {
      socket.TryWriteText(buffer);
   }
   else
   {
      socket.TryWriteBinary(buffer);
   }
</pre>
</div>
<div><br /></div>
<div>
Whilst here, we send a message as a sequence of buffers. We know the size of the complete message before we start and pass that value in our call to <code>StartMessage()</code>.
</div>
<div><br /></div>
<div>
<pre class="brush: cpp gutter: false">void CPerConnectionData::EchoMessage(
   IWebSocket &amp;socket)
{
   CSmartBuffer buffer(m_messageBuffers.GetNext());

   socket.StartMessage(m_messageType, m_messageSize, buffer.GetRef());

   buffer = m_messageBuffers.GetNext();

   while (buffer.Get())
   {
      socket.SendMessageData(buffer.GetRef());

      buffer = m_messageBuffers.GetNext();
   }

   m_messageSize = 0;
}
</pre>
</div>
<div><br /></div>
<div>
Finally, here we show sending a message as a sequence of fragments, not knowing how long the resulting message will be when we start sending.
</div>
<div><br /></div>
<div>
<pre class="brush: cpp gutter: false">void CFragmentEchoingSocketServer::OnData(
   IWebSocket &amp;socket,
   IBuffer &amp;buffer,
   const MessageType type,
   const MessageStatus status,
   const __int64 messageBytesOutstanding)
{
   const bool echoing = ToBool(socket.GetUserData(m_userDataIndex));

   if (echoing)
   {
      if (status == MessageStatusComplete &amp;&amp; messageBytesOutstanding == 0)
      {
         socket.StartNewFragment(buffer.GetUsed(), buffer, true);

         socket.SetUserData(m_userDataIndex, false);
      }
      else
      {
         socket.StartNewFragment(buffer.GetUsed(), buffer);
      }
   }
   else 
   {
      socket.StartFragmentedMessage(type, buffer.GetUsed(), buffer);

      socket.SetUserData(m_userDataIndex, true);
   }

   socket.TryRead();
}
</pre>
</div>
<div><br /></div>
<div>
See <a href="http://www.serverframework.com/ServerFramework/latest/Docs/examples-websocketservers.html" target="SF">the WebSockets example servers</a> for more details.
</div>
<div><br /></div>
<div>
The WebSockets protocol presents itself as providing a message based interface but given that a single message can have an unbounded size it's complicated to provide a general purpose API which will suit all potential users. By allowing the user of the API to select the buffering and accumulation strategies we provide the flexibility to make it as easy to work with simple, small, discrete messages as it is to work with a potentially endless stream of data. 
</div>
<div><br /></div>
<div>
<a href="http://www.serverframework.com/products---the-websockets-option.html" target="SF">The WebSockets Option Pack</a> for <a href="http://www.serverframework.com" target="SF">The&nbsp;Server&nbsp;Framework</a> is available from version 6.5 of <a href="http://www.serverframework.com" target="SF">The&nbsp;Server&nbsp;Framework</a> which was released recently.
</div> ]]>
    </content>
</entry>

<entry>
    <title>The curious case of the missing copy constructor</title>
    <link rel="alternate" type="text/html" href="http://www.lenholgate.com/blog/2011/09/the-curious-case-of-the-not-missing-copy-constructor.html" />
    <id>tag:www.lenholgate.com,2011:/blog//12.1135</id>

    <published>2011-09-14T08:15:46Z</published>
    <updated>2011-09-14T08:56:53Z</updated>

    <summary> I have a tendency to write unit tests that are a little more invasive than they need to be; these tests make sure that not only are the results as expected but also that as many of the side-effects...</summary>
    <author>
        <name>Len</name>
        
    </author>
    
        <category term="C++ Tips" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Testing" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.lenholgate.com/blog/">
        <![CDATA[<div>
I have a <a href="http://www.lenholgate.com/blog/2008/04/what-would-i-do.html">tendency to write unit tests that are a little more invasive</a> than they need to be; these tests make sure that not only are the results as expected but also that as many of the side-effects and interactions with other objects are as expected as well. So, for example, in my current <a href="http://www.lenholgate.com/blog/2011/09/the-websocket-protocol---draft-hybi-13.html">WebSockets development</a> for <a href="http://www.serverframework.com/" target="_blank">The Server Framework</a> I have some tests which test that the correct data is delivered to the client of the API that I'm developing and also test that the API interacts with its buffer allocator correctly and doesn't leak memory. The detailed interaction testing sometimes gets in the way of refactoring as the inputs don't change, the outputs don't change but the interaction changes so a test that should pass before and after a refactoring may fail just because I've optimised the use of a sub object that happens to be being checked in the test; in these cases where both levels of testing are useful I sometimes duplicate the test with and without the detailed interaction examination... Anyway...
</div>
<div><br /></div>
<div>
I have a test which tracks the way a buffer's reference count is modified as the object under test performs an action; it's useful to be have tests which prove that under given circumstances you don't have a reference counting leak. The buffer is passed around via a mix of raw pointers and smart pointers and during the test a mock buffer is used which logs all of the operations performed. At one point in the interaction log there's a point where the buffer is returned by value via a smart pointer and we get an <code>AddRef()</code>, <code>Release()</code> sequence of calls as the temporary is copied into and out of. The compiler is allowed by the C++ standard to elide copy constructors in some situations, see <a href="http://en.wikipedia.org/wiki/Copy_elision" target="_blank">here</a>, so you should be careful that your copy constructor doesn't do anything other than copy the object as you can't guarantee that it will actually be called. If you then allow for the fact that the compiler may opt to use the <a href="http://en.wikipedia.org/wiki/Return_value_optimization">Return Value Optimisation</a> in some circumstances to avoid creating temporaries you should probably start to realise that my invasive test is somewhat fragile depending on which compiler optimisations are enabled and which compiler is being used...
</div>
<div><br /></div>
<div>
So, my tests expect to see the copy constructor called and the resulting sequence of <code>AddRef()</code> and <code>Release()</code> calls on the buffer and in debug builds on all supported compilers this is what they see. Unfortunately on release builds the compilers differ... VS2005 and VS2010 RTM both elide the copy constructor (presumably applying  RVO) whereas VS2008 and VS2010 SP1 both call the copy constructor. For now I have a rather clunky macro that detects the compiler version and build version and removes the test requirement where necessary. For a while I had some problems differentiating between VS2010 RTM and VS2010 SP1 but luckily <code>_MSC_FULL_VER</code> can be used for that. 
</div>
<div><br /></div>
<div>
Now, off to learn a little more about RVO and <a href="http://www.synesis.com.au/resources/articles/cpp/movectors.pdf" target="_blank">move constructors</a>.
</div>
<div><br /></div>
<div>
<b>Edit:</b>It seems that it's less compiler related than I thought. One of the projects (the one where the smart pointer template lives) had optimisations turned off in some of the release builds for some of the compilers... More investigation needed, with any luck all compilers will elide the copy once optimisations are turned on...
</div>]]>
        
    </content>
</entry>

<entry>
    <title>The WebSocket protocol - Draft, HyBi 13</title>
    <link rel="alternate" type="text/html" href="http://www.lenholgate.com/blog/2011/09/the-websocket-protocol---draft-hybi-13.html" />
    <id>tag:www.lenholgate.com,2011:/blog//12.1133</id>

    <published>2011-09-01T07:29:05Z</published>
    <updated>2011-09-01T08:57:27Z</updated>

    <summary> Another day, another WebSocket protocol draft... That&apos;s probably a little unfair actually. Although there have been several drafts in quick succession over the past few weeks the protocol itself has only changed very slightly. The majority of the changes...</summary>
    <author>
        <name>Len</name>
        
    </author>
    
        <category term="Socket Servers" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.lenholgate.com/blog/">
        <![CDATA[<div>
Another day, another WebSocket protocol <a href="http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-13" target="_blank">draft</a>...
</div>
<div><br /></div>
<div>
That's probably a little unfair actually. Although there have been several drafts in quick succession over the past few weeks the protocol itself has only changed very slightly. The majority of the changes have simply been to the wording and arrangement of the document.
</div>
<div><br /></div>
<div>
<a href="http://www.lenholgate.com/blog/2011/07/the-websocket-protocol-design-by-committee-and-requirements-tracing.html">I was fairly cynical</a> about the likely quality of the final RFC when I started looking at the 09 draft and then, in search of clarification, started following the <a href="http://www.ietf.org/mail-archive/web/hybi/current/maillist.html" target="_blank">HyBi Working Group's mailing list</a>. As I said at the time, there are a lot of interested parties and they all want their own special requirements reflected in the document. What I wasn't really aware of then was that once the document moved towards standardisation the issues would be managed in a much more controlled manner. Since then, Peter Saint-Andre has guided the Working Group and the document in a subtle but controlled manner. The discussions have still been heated (and in many cases circular) but each outstanding issue has finally been resolved and the document has moved forward.
</div>
<div><br /></div>
<div>
When I started following the Working Group I felt that I couldn't make a difference. There were lots of loud personalities that had been involved from the start and came across as having a lot more weight in the process than others on the list. I'm pleased that I decided to ignore my initial fears and raise some of the issues that I was concerned about as in some cases I feel that it made a difference.
</div>
<div><br /></div>
<div>
So, where are we on my list of rants from back in July?
</div>
<div><br /></div>
<div>
<ol>
<li><a href="http://www.lenholgate.com/blog/2011/07/websockets-is-a-stream-not-a-message-based-protocol.html">WebSockets is a stream, not a message based protocol...</a> - The wording of the RFC has been changed so that it doesn't imply that a message based API is the only one that should be considered and private use extension tokens are no longer allowed (so no x-tcp-stream)</li>
<li><a href="http://www.lenholgate.com/blog/2011/07/websockets---why-differentiate-between-text-and-binary-frames.html">Why differentiate between text and binary frames?</a> - No change. The WebSocket protocol needs to deal with UTF8 transformations just so that the users don't.</li>
<li><a href="http://www.lenholgate.com/blog/2011/07/websockets---why-do-we-need-to-mask-data-from-client-to-server.html">Why do we need to mask data from client to server?</a> - The document has been updated to explain the rationale behind this requirement.</li>
<li><a href="http://www.lenholgate.com/blog/2011/07/websockets---the-deflate-stream-extension-is-broken-and-badly-designed.html">How the deflate-stream extension is broken and badly designed</a> - The extension has been removed.</li>
<li><a href="http://www.lenholgate.com/blog/2011/07/websockets---i-miss-the-tcp-half-close.html">I miss the TCP half-close</a> - No change.</li>
</ol>
</div>
<div><br /></div>
<div>
So the main issues that I was concerned about have been dealt with and the remaining two are pretty minor. It's somewhat annoying that <code>deflate-stream</code> was removed after I implemented it, but since I implemented it as a <a href="http://www.serverframework.com/ServerFramework/latest/Docs/class_jet_byte_tools_1_1_socket_1_1_i_filter_stream_socket_connections.html" target="_blank">general purpose connection filter</a> the code can be reused by anyone using <a href="http://www.serverframework.com/" target="_blank">The Server Framework</a> who wants to deflate their TCP data.
</div>
<div><br /></div>
<div>
WebSocket support is available in <a href="http://www.serverframework.com/products---the-websockets-option.html" target="_blank">The Server Framework</a> from release 6.5 which is currently in final testing.
</div>]]>
        
    </content>
</entry>

<entry>
    <title>Autobahn WebSockets protocol compliance test suite</title>
    <link rel="alternate" type="text/html" href="http://www.lenholgate.com/blog/2011/08/autobahn-websockets-protocol-compliance-test-suite.html" />
    <id>tag:www.lenholgate.com,2011:/blog//12.1132</id>

    <published>2011-08-31T07:27:29Z</published>
    <updated>2011-08-31T07:37:25Z</updated>

    <summary> I&apos;m nearing the end of my WebSockets implementation for The Server Framework and have been dealing with various protocol compliance issues. Whilst I have decent unit test coverage I haven&apos;t, yet, sat down and produced compliance specific unit tests...</summary>
    <author>
        <name>Len</name>
        
    </author>
    
        <category term="Socket Servers" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Testing" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.lenholgate.com/blog/">
        <![CDATA[<div>
I'm nearing the end of my <a href="http://www.lenholgate.com/blog/2011/07/the-websocket-protocol-design-by-committee-and-requirements-tracing.html">WebSockets implementation</a> for <a href="http://www.serverframework.com/">The Server Framework</a> and have been dealing with various protocol compliance issues. Whilst I have decent unit test coverage I haven't, yet, sat down and produced compliance specific unit tests which walk through the various parts of the (ever changing) draft RFC and test each aspect. Looking back, I probably should have taken this approach even though the RFC was fluid. Anyway. One of the people involved in the WebSockets Working Group has a nice set of compliance tests for their implementation and they have made these tests are freely available; so I've been using them! They've really helped nail a few subtle issues in my implementation (and one or two not so subtle issues!).
</div>
<div><br/></div>
<div>
The <a href="http://www.tavendo.de/autobahn/testsuite.html" target="_blank">Autobahn tests can be found here</a>, and the report generated by the current pre-release version of my implementation can be found <a href="http://www.serverframework.com/ServerFramework/6.5/WebSockets/">here</a>.
</div>   ]]>
        
    </content>
</entry>

<entry>
    <title>I guess this is a geek thing...</title>
    <link rel="alternate" type="text/html" href="http://www.lenholgate.com/blog/2011/08/i-guess-this-is-a-geek-thing.html" />
    <id>tag:www.lenholgate.com,2011:/blog//12.1129</id>

    <published>2011-08-21T18:59:49Z</published>
    <updated>2011-08-21T19:05:25Z</updated>

    <summary>I&apos;m just back from a wonderfully relaxing holiday in Italy. This time we had internet connectivity all the time, so I&apos;m up to date on email, etc. The first thing that I do after all the &apos;we&apos;re back, how&apos;s the...</summary>
    <author>
        <name>Len</name>
        
    </author>
    
        <category term="Geek Speak" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.lenholgate.com/blog/">
        <![CDATA[I'm just back from a wonderfully relaxing holiday in Italy. This time we had internet connectivity all the time, so I'm up to date on email, etc. The first thing that I do after all the 'we're back, how's the house, and you need to go to bed even though you're&nbsp;excited&nbsp;to see all of the toys you've missed' stuff is to fire up all my machines and make sure that they do their windows update stuff... Then the NAS devices need to be started and allowed to settle in, then the VPN needs to be checked, dyndns kicked, etc. I expect my wife should really know to do the 'you need to go to bed even though you're exicited to see all of the toys you've missed' stuff on me too...]]>
        
    </content>
</entry>

<entry>
    <title>WebSockets - I miss the TCP half close...</title>
    <link rel="alternate" type="text/html" href="http://www.lenholgate.com/blog/2011/07/websockets---i-miss-the-tcp-half-close.html" />
    <id>tag:www.lenholgate.com,2011:/blog//12.1128</id>

    <published>2011-07-08T15:25:59Z</published>
    <updated>2011-07-26T05:18:43Z</updated>

    <summary> As I mentioned here, the WebSockets protocol is, at this point, a bit of a mess due to the evolution of the protocol and the fact that it&apos;s being pulled in various directions by various interested parties. I&apos;m just...</summary>
    <author>
        <name>Len</name>
        
    </author>
    
        <category term="Rants" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Socket Servers" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.lenholgate.com/blog/">
        <![CDATA[<div>
As I mentioned <a href="http://www.lenholgate.com/blog/2011/07/the-websocket-protocol-design-by-committee-and-requirements-tracing.html">here</a>, the <a href="http://en.wikipedia.org/wiki/WebSockets" target="_blank">WebSockets protocol</a> is, at this point, a bit of a mess due to the evolution of the protocol and the fact that it's being pulled in various directions by various interested parties. I'm just ranting about some of the things that I find annoying...
</div>
<div><br /></div>
<div>
The WebSockets protocol includes a way for the endpoints to shut down the connection.
</div>
<div>
<pre><small>
   If an endpoint receives a Close frame and that endpoint did not
   previously send a Close frame, the endpoint MUST send a Close frame
   in response.  It SHOULD do so as soon as is practical.  An endpoint
   MAY delay sending a close frame until its current message is sent
   (for instance, if the majority of a fragmented message is already
   sent, an endpoint MAY send the remaining fragments before sending a
   Close frame).  However, there is no guarantee that the endpoint which
   has already sent a Close frame will continue to process data.

   After both sending and receiving a close message, an endpoint
   considers the WebSocket connection closed, and MUST close the
   underlying TCP connection.  The server MUST close the underlying TCP
   connection immediately; the client SHOULD wait for the server to
   close the connection but MAY close the connection at any time after
   sending and receiving a close message, e.g. if it has not received a
   TCP close from the server in a reasonable time period.
</small>
</pre>
</div>
Unfortunately it's a full close of the connection in both directions rather than an indication that the endpoint sending it has nothing more to send. In effect it's a <code>close()</code> rather than a <code>shutdown()</code>. This means that if you ever want to indicate that you're done sending but that you'd like the other end to finish up and then close you have to implement it yourself...]]>
        <![CDATA[<div>
TCP allows you to close each direction of the connection independently. The first peer to shut down their sending side is deemed to have issued the active close. Whoever issues the active close ends up in <code>TIME_WAIT</code> state (see <a href="http://www.serverframework.com/asynchronousevents/2011/01/time-wait-and-its-design-implications-for-protocols-and-scalable-servers.html" target="_blank">here</a> for more details on that). The WebSockets protocol provides a protocol level close message which is intended to do the following:
</div>
<div>
<pre>
<small>
   The closing handshake is intended to complement the TCP closing
   handshake (FIN/ACK), on the basis that the TCP closing handshake is
   not always reliable end-to-end, especially in the presence of man-in-
   the-middle proxies and other intermediaries.

   By sending a close frame and waiting for a close frame in response,
   certain cases are avoided where data may be unnecessarily lost.  For
   instance, on some platforms, if a socket is closed with data in the
   receive queue, a RST packet is sent, which will then cause recv() to
   fail for the party that received the RST, even if there was data
   waiting to be read.
</small>
</pre>
</div>
<div>
Which is all well and good but the ability to perform a half-close would be very useful and its unfortunate omission will no doubt lead to applications inventing their own...
</div> ]]>
    </content>
</entry>

<entry>
    <title>WebSockets - The deflate-stream extension is broken and badly designed</title>
    <link rel="alternate" type="text/html" href="http://www.lenholgate.com/blog/2011/07/websockets---the-deflate-stream-extension-is-broken-and-badly-designed.html" />
    <id>tag:www.lenholgate.com,2011:/blog//12.1126</id>

    <published>2011-07-08T15:00:00Z</published>
    <updated>2011-07-08T15:00:00Z</updated>

    <summary> As I mentioned here, the WebSockets protocol is, at this point, a bit of a mess due to the evolution of the protocol and the fact that it&apos;s being pulled in various directions by various interested parties. I&apos;m just...</summary>
    <author>
        <name>Len</name>
        
    </author>
    
        <category term="Rants" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Socket Servers" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.lenholgate.com/blog/">
        <![CDATA[<div>
As I mentioned <a href="http://www.lenholgate.com/blog/2011/07/the-websocket-protocol-design-by-committee-and-requirements-tracing.html">here</a>, the <a href="http://en.wikipedia.org/wiki/WebSockets" target="_blank">WebSockets protocol</a> is, at this point, a bit of a mess due to the evolution of the protocol and the fact that it's being pulled in various directions by various interested parties. I'm just ranting about some of the things that I find annoying...
</div>
<div><br /></div>
<div>
The WebSockets protocol is designed to be extended, which is all well and good. Extensions can, at present, be formally specified by RFCs or be "private use" extensions with names that are prefixed with an "x-". So far the only "official" extension is the <code>deflate-stream</code> extension that's detailed in the WebSockets protocol RFC itself. 
</div>
<div><br /></div>
<div>
Unfortunately, the <code>deflate-stream</code> extension isn't really an ideal example of how future extensions should work. A far better example would be the alternative <code>deflate-application-data</code> extension that's detailed <a href="http://tools.ietf.org/html/draft-tyoshino-hybi-websocket-perframe-deflate-01" target="_blank">here</a>.
</div>
<div><br /></div>
So, what's wrong with <code>deflate-stream</code>?]]>
        <![CDATA[<div>
The WebSockets protocol is very open to extension, possibly too open.
</div>
<div>
<pre><small>
4.8.  Extensibility

   The protocol is designed to allow for extensions, which will add
   capabilities to the base protocols.  The endpoints of a connection
   MUST negotiate the use of any extensions during the opening
   handshake.  This specification provides opcodes 0x3 through 0x7 and
   0xB through 0xF, the extension data field, and the frame-rsv1, frame-
   rsv2, and frame-rsv3 bits of the frame header for use by extensions.

   The negotiation of extensions is discussed in further detail in
   Section 9.1.  Below are some anticipated uses of extensions.  This
   list is neither complete nor proscriptive.

   o  Extension data may be placed in the payload data before the
      application data.

   o  Reserved bits can be allocated for per-frame needs.

   o  Reserved opcode values can be defined.

   o  Reserved bits can be allocated to the opcode field if more opcode
      values are needed.

   o  A reserved bit or an "extension" opcode can be defined which
      allocates additional bits out of the payload data to define larger
      opcodes or more per-frame bits.
</small>
</pre>
</div>
<div>
But even with all of this available the <code>deflate-stream</code> extension goes further. The <code>deflate-stream</code> extension completely replaces the wire format of the WebSockets protocol with a stream of compressed data. That is, all framing and headers are included in the compression and you can't decompress a portion of the stream without decompressing all of it. It means that any form of proxy that wants to inspect the contents of WebSocket traffic has to decompress the whole stream to look at the individual frames; it can't even simply use the header information to skip the data portions of the frames as the headers are also compressed. The WebSocket protocol doesn't really even hint at this being the intended use of the extension mechanism, in fact it seems to suggest that whilst extensions can fiddle with the header contents and the frame contents they can't simply replace the entire wire format. There are <a href="http://www.ietf.org/mail-archive/web/hybi/current/msg07093.html" target="_blank">those who think</a> the inclusion of "connection-level" extensions is a bad idea and I agree with them. After all, by following the example of the <code>deflate-stream</code> extension surely the obvious solution to the <a href="http://www.lenholgate.com/blog/2011/07/websockets-is-a-stream-not-a-message-based-protocol.html">rather broken message based</a> aspect of the protocol is simply to write an extension that replaces the entire WebSocket wire format with one that pleases you better; <code>x-raw-tcp-stream</code> anyone? 
</div>
<div><br /></div>
<div>
If the fact that the <code>deflate-stream</code> extension isn't exactly an ideal example of how extensions should be built isn't enough of a reason to remove it from the RFC then surely the fact that it <a href="http://www.ietf.org/mail-archive/web/hybi/current/msg07581.html" target="_blank">doesn't actually work</a> as expected might be? It doesn't seem likely. The problem is that now that <a href="http://www.lenholgate.com/blog/2011/07/websockets---why-do-we-need-to-mask-data-from-client-to-server.html">WebSockets requires client to server data frames to be masked</a> the data being sent from client to server is sufficiently random that compression can't be applied. So, at best, <code>deflate-stream</code>, simply burns server-side CPU when dealing with inbound WebSocket data and at worst it makes the data stream from client to server bigger than it need be. Ideally you'd simply not mask if you were going to use <code>deflate-stream</code> but that doesn't seem to be an option; there appear to be concerns that the extremely unlikely situation that client to server masking is supposed to protect against could occur using unmasked compressed data. Of course the attacker would have to know exactly how the data was going to be deflated and could therefore somehow come up with some payload data that results in a useful stream of deflated data; but really... 
</div>
<div><br /></div>
<div>
Ripping <code>deflate-stream</code> out of the RFC entirely and/or replacing it with <code>deflate-application-data</code> would seem to be the obvious course of action, but there <a href="http://www.ietf.org/mail-archive/web/hybi/current/msg07629.html" target="_blank">seems to be resistance</a> to this. Making it possible to enable <code>deflate-stream</code> in one direction only, i.e. from server to client, would also seem to be a potential win as you'd get your deflated stream in the direction that it can work and not waste time on data that can't be meaningfully compressed. 
</div>
]]>
    </content>
</entry>

<entry>
    <title>Another day, another deadlock avoided with no harm done</title>
    <link rel="alternate" type="text/html" href="http://www.lenholgate.com/blog/2011/07/another-day-another-deadlock-avoided-with-no-harm-done.html" />
    <id>tag:www.lenholgate.com,2011:/blog//12.1127</id>

    <published>2011-07-07T08:43:50Z</published>
    <updated>2011-07-07T09:23:10Z</updated>

    <summary><![CDATA[ I'm currently building a new example server for The&nbsp;Server&nbsp;Framework. This is a variation on one of our proxy server examples for a client that's doing some WebSockets work. The idea is that the server takes an inbound WebSockets connection,...]]></summary>
    <author>
        <name>Len</name>
        
    </author>
    
        <category term="Lock Explorer" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Socket Servers" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.lenholgate.com/blog/">
        <![CDATA[<div>
I'm currently building a new example server for <a href="http://www.serverframework.com" target="_blank">The&nbsp;Server&nbsp;Framework</a>. This is a variation on one of our proxy server examples for a client that's doing some <a href="http://en.wikipedia.org/wiki/WebSockets" target="_blank">WebSockets</a> work. The idea is that the server takes an inbound WebSockets connection, creates an outbound TCP connection to the target server and routes data to and from the remote server and the WebSockets client. It's fairly simple stuff to put together once you're up to speed on <a href="http://www.serverframework.com" target="_blank">The&nbsp;Server&nbsp;Framework</a> but my client needed a helping hand and it's another nice example of what you can do with the framework.
</div>
<div><br /></div>
<div>
As I've mentioned before, all of these example servers run a set of black box integration tests during the build process. Once the code has compiled the tests kick off automatically, start the server, run a client against it, check the results are as expected, etc. If the test fails then the build fails. 
</div>
<div><br /></div>
This works great at flushing out any latent issues that the unit tests of all the framework code don't happen to catch. It's good for race condition problems and deadlocks and the like. The fact that the integration tests run on all of my build servers (which are a nice mix of power, memory and processors) means that race conditions and whatever get shaken out of the framework pretty quickly.
]]>
        <![CDATA[<div>
As I mentioned a while back, I've now got <a href="http://www.lenholgate.com/blog/2010/11/tangential-testing.html">memory leak analysis</a> and <a href="http://www.lenholgate.com/blog/2010/11/a-lock-inversion-detector-as-part-of-the-build-is-good.html">lock inversion detection</a> built into the integration test runners. The lock inversion detection can find and report on potential deadlocks without the code under test needing to actually deadlock. It detects that the code COULD deadlock and reports why. You can download the lock inversion detector that I use from <a href="http://www.lockexplorer.com/lock-inversion-detector-download-free.html" target="_blank">here</a> on my <a href="http://www.lockexplorer.com/" target="_blank">www.lockexplorer.com</a> site.
</div>
<div><br /></div>
<div>
Anyway, I set up the integration tests for my new server example this morning and ran it. The tests ran fine but <a href="http://www.lockexplorer.com/lock-inversion-detector-download-free.html" target="_blank">LID</a> reported lock inversions. Every lock inversion is a deadlock waiting to happen and although the tests had run through fine and the server hadn't deadlocked the report from LID was showing me that, given the right set of threading circumstances, it could...  
</div>
<div><br /></div>
<div>
By default I run LID during the integration tests as this runs slightly faster than <a href="http://www.lockexplorer.com/lock-inversion-analyser-buy-now.html" target="_blank">LIA</a> the full featured lock inversion analyser. A simple adjustment to the configuration of the integration test lets me run LIA instead and the report was quite clear as to where the lock inversions were.
</div>
<div>
<small>
<pre class="brush: text gutter: false">****************New Log*****************
Target process has terminated
Process "E:\OutboundGatewayServer\Output\VS2010\URelease\OutboundGatewayServer.exe" exit code: 0
Checking 3151 lock acquisition sequences for inversions

Lock inversions detected!

Lock inversion in acquisition of locks 164 and 41
Primary lock acquisition sequence: 164 @ 171, 41 @ 173
Executed on thread: 8 [6164] "IOPool"
Secondary lock acquisition sequence: 41 @ 154, 164 @ 178
Executed on threads: 5 [1064] "IOPool", 17 [1236] "IOPool", 16 [1288] "IOPool", 3 [2028] "IOPool", 13 [3652] "IOPool", 9 [4056] "IOPool", 12 [4676] "IOPool", 10 [4948] "IOPool", 7 [5444] "IOPool", 8 [6164] "IOPool", 4 [6232] "IOPool", 15 [6412] "IOPool", 11 [6704] "IOPool", 6 [6836] "IOPool", 14 [6876] "IOPool", 18 [7080] "IOPool"
Secondary lock acquisition sequence: 41 @ 154, 164 @ 187
Executed on threads: 5 [1064] "IOPool", 17 [1236] "IOPool", 16 [1288] "IOPool", 3 [2028] "IOPool", 13 [3652] "IOPool", 9 [4056] "IOPool", 12 [4676] "IOPool", 10 [4948] "IOPool", 7 [5444] "IOPool", 8 [6164] "IOPool", 4 [6232] "IOPool", 15 [6412] "IOPool", 11 [6704] "IOPool", 6 [6836] "IOPool", 14 [6876] "IOPool", 18 [7080] "IOPool"
Secondary lock acquisition sequence: 41 @ 154, 164 @ 194
Executed on thread: 12 [4676] "IOPool"
Location: 154
e:\jetbytetools\win32tools\criticalsection.cpp(80) : CCriticalSection::Enter
e:\jetbytetools\win32tools\icriticalsection.cpp(44) : ICriticalSection::Owner::Owner
e:\jetbytetools\websockettools\hybi08\protocolhandler.cpp(260) : CProtocolHandler::OnDataReceived
e:\outboundgatewayserver\socketserver.cpp(206) : CSocketServer::OnReadCompleted
e:\jetbytetools\sockettools\streamsocketconnectionmanagerbase.cpp(128) : CStreamSocketConnectionManagerBase::OnReadCompleted
e:\jetbytetools\sockettools\streamsocketconnectionmanager.h(933) : TStreamSocketConnectionManager&lt;cstreamsocketconnectionmanagerbase&gt;::HandleOperation
e:\jetbytetools\sockettools\tasyncsocket.h(565) : TAsyncSocket&lt;ipoolablestreamsocket,istreamsocketconnectionmanager,istreamsocketcallback&gt;::HandleOperation
e:\jetbytetools\iotools\iopool.cpp(319) : CIOPool::WorkerThread::Run
e:\jetbytetools\win32tools\thread.cpp(241) : CThread::ThreadFunction
---
Location: 171
e:\jetbytetools\win32tools\criticalsection.cpp(80) : CCriticalSection::Enter
e:\jetbytetools\win32tools\icriticalsection.cpp(44) : ICriticalSection::Owner::Owner
e:\outboundgatewayserver\connection.cpp(128) : CConnection::OnConnectionEstablished
e:\outboundgatewayserver\socketserver.cpp(157) : CSocketServer::OnConnectionEstablished
e:\jetbytetools\sockettools\streamsocketconnectionmanagerbase.cpp(86) : CStreamSocketConnectionManagerBase::OnConnectionEstablished
e:\jetbytetools\sockettools\streamsocketconnectionmanager.h(1422) : TStreamSocketConnectionManager&lt;cstreamsocketconnectionmanagerbase&gt;::ConnectCompleted
e:\jetbytetools\sockettools\streamsocketconnectionmanager.h(981) : TStreamSocketConnectionManager&lt;cstreamsocketconnectionmanagerbase&gt;::HandleOperation
e:\jetbytetools\sockettools\tasyncsocket.h(565) : TAsyncSocket&lt;ipoolablestreamsocket,istreamsocketconnectionmanager,istreamsocketcallback&gt;::HandleOperation
e:\jetbytetools\iotools\iopool.cpp(319) : CIOPool::WorkerThread::Run
e:\jetbytetools\win32tools\thread.cpp(241) : CThread::ThreadFunction
---
Location: 173
e:\jetbytetools\win32tools\criticalsection.cpp(80) : CCriticalSection::Enter
e:\jetbytetools\win32tools\icriticalsection.cpp(44) : ICriticalSection::Owner::Owner
e:\jetbytetools\websockettools\hybi08\protocolhandler.cpp(996) : CProtocolHandler::TryRead
e:\jetbytetools\websockettools\hybi08\websocket.cpp(166) : CWebSocket::TryRead
e:\jetbytetools\websockettools\hybi08\websocket.cpp(145) : CWebSocket::TryRead
e:\outboundgatewayserver\connection.cpp(143) : CConnection::OnConnectionEstablished
e:\outboundgatewayserver\socketserver.cpp(157) : CSocketServer::OnConnectionEstablished
e:\jetbytetools\sockettools\streamsocketconnectionmanagerbase.cpp(86) : CStreamSocketConnectionManagerBase::OnConnectionEstablished
e:\jetbytetools\sockettools\streamsocketconnectionmanager.h(1422) : TStreamSocketConnectionManager&lt;cstreamsocketconnectionmanagerbase&gt;::ConnectCompleted
e:\jetbytetools\sockettools\streamsocketconnectionmanager.h(981) : TStreamSocketConnectionManager&lt;cstreamsocketconnectionmanagerbase&gt;::HandleOperation
e:\jetbytetools\sockettools\tasyncsocket.h(565) : TAsyncSocket&lt;ipoolablestreamsocket,istreamsocketconnectionmanager,istreamsocketcallback&gt;::HandleOperation
e:\jetbytetools\iotools\iopool.cpp(319) : CIOPool::WorkerThread::Run
e:\jetbytetools\win32tools\thread.cpp(241) : CThread::ThreadFunction
---
Location: 178
e:\jetbytetools\win32tools\criticalsection.cpp(80) : CCriticalSection::Enter
e:\jetbytetools\win32tools\icriticalsection.cpp(44) : ICriticalSection::Owner::Owner
e:\outboundgatewayserver\connection.cpp(165) : CConnection::OnReadCompleted
e:\outboundgatewayserver\socketserver.cpp(322) : CSocketServer::OnDataFrame
e:\jetbytetools\websockettools\hybi08\protocolhandler.cpp(917) : CProtocolHandler::HandleData
e:\jetbytetools\websockettools\hybi08\protocolhandler.cpp(692) : CProtocolHandler::DispatchFrame
e:\jetbytetools\websockettools\hybi08\protocolhandler.cpp(536) : CProtocolHandler::ProcessDataReceived
e:\jetbytetools\websockettools\hybi08\protocolhandler.cpp(341) : CProtocolHandler::HandleDataReceived
e:\jetbytetools\websockettools\hybi08\protocolhandler.cpp(284) : CProtocolHandler::OnDataReceived
e:\outboundgatewayserver\socketserver.cpp(206) : CSocketServer::OnReadCompleted
e:\jetbytetools\sockettools\streamsocketconnectionmanagerbase.cpp(128) : CStreamSocketConnectionManagerBase::OnReadCompleted
e:\jetbytetools\sockettools\streamsocketconnectionmanager.h(933) : TStreamSocketConnectionManager&lt;cstreamsocketconnectionmanagerbase&gt;::HandleOperation
e:\jetbytetools\sockettools\tasyncsocket.h(565) : TAsyncSocket&lt;ipoolablestreamsocket,istreamsocketconnectionmanager,istreamsocketcallback&gt;::HandleOperation
e:\jetbytetools\iotools\iopool.cpp(319) : CIOPool::WorkerThread::Run
e:\jetbytetools\win32tools\thread.cpp(241) : CThread::ThreadFunction
---
</pre>
</small>
</div>
<div>
Diving into the code for the lock acquisitions in question shows me that in one of the objects concerned I'm holding the lock for longer than I need to. Reducing the scope of the lock means that I don't hold it across the use of the other object which removes the lock inversion. 2 minutes and one recompile from discovery to confirmed fix. A nice start to the day.
</div>]]>
    </content>
</entry>

<entry>
    <title>WebSockets - Why do we need to mask data from client to server?</title>
    <link rel="alternate" type="text/html" href="http://www.lenholgate.com/blog/2011/07/websockets---why-do-we-need-to-mask-data-from-client-to-server.html" />
    <id>tag:www.lenholgate.com,2011:/blog//12.1125</id>

    <published>2011-07-06T14:52:04Z</published>
    <updated>2011-07-06T19:41:44Z</updated>

    <summary> As I mentioned here, the WebSockets protocol is, at this point, a bit of a mess due to the evolution of the protocol and the fact that it&apos;s being pulled in various directions by various interested parties. I&apos;m just...</summary>
    <author>
        <name>Len</name>
        
    </author>
    
        <category term="Rants" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Socket Servers" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.lenholgate.com/blog/">
        <![CDATA[<div>
As I mentioned <a href="http://www.lenholgate.com/blog/2011/07/the-websocket-protocol-design-by-committee-and-requirements-tracing.html">here</a>, the <a href="http://en.wikipedia.org/wiki/WebSockets" target="_blank">WebSockets protocol</a> is, at this point, a bit of a mess due to the evolution of the protocol and the fact that it's being pulled in various directions by various interested parties. I'm just ranting about some of the things that I find annoying...
</div>
<div><br /></div>
<div>
<small>
<pre>   The client MUST mask all frames sent to the server.  A server MUST
   close the connection upon receiving a frame with the MASK bit set to
   0.  In this case, a server MAY send a close frame with a status code
   of 1002 (protocol error) as defined in Section 7.4.1.
</pre>
</small>
</div>
<div>
Fair enough, but why?
</div>
]]>
        <![CDATA[<div>
The masking in itself is relatively painless to achieve but it interacts poorly with the albeit badly designed <code>deflate-stream</code> extension and forcing the client to mask zero length frames seems unnecessary - though I agree that <a href="http://www.ietf.org/mail-archive/web/hybi/current/msg07645.html" target="_blank">special cases</a> don't really seem warranted.
</div>
<div><br /></div>
<div>
The RFC doesn't explain why masking from client to server is considered essential but a search through the discussion list brings up plenty of <a href="http://www.google.co.uk/search?q=data+masking+site%3Ahttp%3A%2F%2Fwww.ietf.org%2Fmail-archive%2Fweb%2Fhybi%2Fcurrent%2F&amp;hl=en&amp;biw=1258&amp;bih=914&amp;num=10&amp;lr=&amp;ft=i&amp;cr=&amp;safe=off&amp;tbs=" target="_blank">hits</a>. The best descriptions of why can be found <a href="http://www.ietf.org/mail-archive/web/hybi/current/msg05292.html" target="_blank">here</a> and <a href="http://www.ietf.org/mail-archive/web/hybi/current/msg06173.html" target="_blank">here</a>.
</div>
<div><br /></div>
<div>
Masking of WebSocket traffic from client to server is required because of the unlikely chance that malicious code could cause some broken proxies to do the wrong thing and use this as an attack of some kind. Nobody has proved that this could actually happen, but since  the fact that it could happen was reason enough for browser vendors to get twitchy, masking was added to remove the possibility of it being used as an attack.
</div>
<div><br /></div>
<div>
The idea being that since the API level code generating the WebSocket frame gets to select a masking key and mask the data supplied by the application code the application code cannot in any meaningful way dictate the data that ends up passing through the potentially broken intermediaries and therefore can't cause trouble. Since the masking key is in the frame intermediaries can be written to understand and unmask the data to perform some form of clever inspection if they want to. 
</div>
<div><br /></div>
<div>
Now, would it be so hard to add something that explains this to the RFC?
</div>]]>
    </content>
</entry>

<entry>
    <title>WebSockets - Why differentiate between text and binary frames?</title>
    <link rel="alternate" type="text/html" href="http://www.lenholgate.com/blog/2011/07/websockets---why-differentiate-between-text-and-binary-frames.html" />
    <id>tag:www.lenholgate.com,2011:/blog//12.1124</id>

    <published>2011-07-06T13:14:49Z</published>
    <updated>2011-07-06T19:39:06Z</updated>

    <summary> As I mentioned here, the WebSockets protocol is, at this point, a bit of a mess due to the evolution of the protocol and the fact that it&apos;s being pulled in various directions by various interested parties. I&apos;m just...</summary>
    <author>
        <name>Len</name>
        
    </author>
    
        <category term="Rants" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Socket Servers" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en-us" xml:base="http://www.lenholgate.com/blog/">
        <![CDATA[<div>
As I mentioned <a href="http://www.lenholgate.com/blog/2011/07/the-websocket-protocol-design-by-committee-and-requirements-tracing.html">here</a>, the <a href="http://en.wikipedia.org/wiki/WebSockets" target="_blank">WebSockets protocol</a> is, at this point, a bit of a mess due to the evolution of the protocol and the fact that it's being pulled in various directions by various interested parties. I'm just ranting about some of the things that I find annoying...
</div>
<div><br /></div>
<div>
Back when binary frames were mentioned in the <a href="http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76" target="_blank">WebSocket protocol specification</a> as a slightly hand wavy "something for the future" and only text frames were actually possible to send and receive using the clients at the time then there MAY (in the strictest RFC meaning of the word) have been a need to differentiate between text and binary frames. Especially since text frames were <code>0xFF</code> terminated rather than length prefixed. Now, however, it seems pointless to have a protocol level differentiation between text and binary frame types.
</div>
<div><br /></div>
<div>
This would be, perhaps, less pointless if a general purpose protocol handler could reliably deliver complete messages to an application, but as we've <a href="http://www.lenholgate.com/blog/2011/07/websockets-is-a-stream-not-a-message-based-protocol.html">seen before</a>, that's not possible. Although backtracking to the last complete character in the UTF-8 stream is relatively straight forward (see <a href="http://debuggable.com/posts/streaming-utf-8-with-node-js:4bf28e8b-a290-432f-a222-11c1cbdd56cb" target="_blank">here</a>) there seems to be little value in converting a partial message to a wide string form only to have the have the application layer have to store and concatenate to obtain a complete message... 
</div>
<div><br /></div>
<div>
Robert Gezelter probably says it far better than I can <a href="http://www.rlgsc.com/blog/ruminations/websocket-rediscovered-travails.html" target="_blank">here</a> on his blog; the differentiation between binary and text should occur at the application level.
</div>]]>
        
    </content>
</entry>

</feed>

