So this weekend I decided it was high time that I document my project that I undertook more than 6 months ago. Its a C-based software broker that I’ve been tinkering with for a long time now and the whole idea behind it has been achieved so their is no point in continuing. The idea was to learn how the broker pattern works and moreover how TCP/IP sockets work. To that end, I’m done – I know how the broker pattern works and why its useful and how to communicate between the various components in the design.

Someone told me once that in order to move on, you need to celebrate the end of the previous. To that end, I’m ceremoniously declaring my broker finished and done so I now have no need to work on it. I can totally understand the sentiments of the previous saying because I’m continually ‘tinkering’ with it, as if its not finished but I’ve got no goals for it now so the tinkering seems empty and pointless. I want to stop working on it and move on to other projects. Its nice to say that something is done. I wrote about the broker here and you can read about it there. That was the primary thing I did yesterday.

If I was going to write another broker, I’d do most things the same but I’d do a lot differently . One thing I’d so is allowing the protocol format to change easily. By far the part that I spent the most time on trying to figure out was how to call a C function when you’ve received a protocol message saying that a specific function should be called with the provided arguments:

{ "request-type" : SERVICE_REQUEST }
{ "message-id": 3456789 }
{ "sender-address" : "127.0.0.1" }	
{ "reply-port": 8090 }	
{ "op"=>"getServerDate" }	
{ "params" => [ buffer, length, ... ] }

So I’d now have to dynamically figure out how to call getServerDate(buffer, length) or whatever the protocol message says I should do. I spent a long time trying to figure out how to do that. But because this is C (and C can do anything) I was determined to do this somehow but didn’t know how. So I’ve ended up creating an array of void pointers for each parameter and then somehow I’d cast those void pointers to the right pointer types parameters, based on the type of parameter that is passed in to the “params” section above (in libmsgpack you can specify the type) to call a real C function…