# RFC: Changes to OSC Block

**URL:** <https://discourse.libcinder.org/t/rfc-changes-to-osc-block/216>\
**Category:** CinderBlocks\
**Created:** [August 9, 2016, 9:39pm UTC](https://discourse.libcinder.org/t/rfc-changes-to-osc-block/216 "2016-08-09T21:39:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryanbartley](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/ryanbartley/32/5_2.png) [@ryanbartley](https://discourse.libcinder.org/u/ryanbartley)\
**Post date:** [August 9, 2016, 9:39pm UTC](https://discourse.libcinder.org/t/rfc-changes-to-osc-block/216/1 "2016-08-09T21:39:34Z")

</div>

Hi all,

Sorry for making so many posts in the last couple of days. Basically, over the last couple of months since OSC’s release a few issues have come up to the API design and I wanted to take care of those things and see what people think.

There are three major changes to the API.

1. Synchronous functions throw `osc::Exception`'s which wrap the `asio::error_code` returned from the `bind`, `close` and `shutdown` methods.

2. Asynchronous functions now take as arguments error handlers and possible complete handlers. Functions such as `send` and `listen`, which dispatch their work to the given `asio::io_service` take functions as arguments. For instance, the `send` function takes an optional `OnErrorFn` with the signature `void( asio::error_code )` and another optional `OnCompleteFn` with the signature `void()`. The errorFn would be called in the case of an error on the send and the completeFn would be called if there was no error. This basically replaces the global handlers and setters that is in the api now.

3. Finally, and possibly the most controversial change, is the choice to separate the naming scheme between `osc::ReceiverUdp` and `osc::ReceiverTcp` of the operation that begins reception at the OS level. For `osc::ReceiverUdp`, the function’s name is `listen`. For `osc::ReceiverTcp`, the function’s name is `accept`. The differences were chosen to signal the underlying differences in what is actually happening. With `listen` on the `osc::ReceiverUdp` side, we’re indiscriminately reading and accepting messages. With `accept` on the `osc::ReceiverTcp` side, we’re binding a socket that’s accepting Tcp connections and then firing asynchronous read’s on the newly created sockets. Most of the reason for the change is not only clarity on the operation but also due to the fact that there are different arguments in each signature. The `osc::ReceiverUdp::listen` signature accepts an `OnErrorFn`, with signature `bool( const asio::error_code &/*error*/, const protocol::endpoint &/*originator*/)` that is used by the underlying read function. The `osc::ReceiverTcp::accept` signature takes an `OnAcceptErrorFn`, which is called in the case of an acceptor error, and has the signature `bool( asio::error_code error )`, and `OnAcceptFn`, which controls the caching of a newly created and connected socket and has the signature `bool( TcpSocketRef, uint64_t )`. That was a mouthful. There was some discussion about whether this difference was needed. Some believed that it was more important to allow an ease of swap between the two different protocols as far as `ci::osc` was concerned but my belief is that, because these two protocols are so different that abstracting them would make it very hard to handle and control the underlying complexity.

Anyway, you can see examples and some comments detailing all of the API changes in the SimpleReceiver [sample](https://github.com/ryanbartley/Cinder/blob/13d3aa0ca9c45f71a3210f503f676c940494c025/blocks/OSC/samples/SimpleReceiver/src/SimpleReceiverApp.cpp) and SimpleSender [sample](https://github.com/ryanbartley/Cinder/blob/13d3aa0ca9c45f71a3210f503f676c940494c025/blocks/OSC/samples/SimpleSender/src/SimpleSenderApp.cpp). Definitely would love to hear what people think.

Best,  
Ryan

---

<div class="post-metadata">

**Author:** ![ryanbartley](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/ryanbartley/32/5_2.png) [@ryanbartley](https://discourse.libcinder.org/u/ryanbartley)\
**Post date:** [October 18, 2016, 3:44am UTC](https://discourse.libcinder.org/t/rfc-changes-to-osc-block/216/2 "2016-10-18T03:44:00Z")

</div>

Fyi, these changes have been merged into master.
