In an earlier item I described issues I was having regarding writing a bunch of KV pairs to the dictionary and getting a "socket closed" error back in mid-stream.
It turns out that this is because my program attempts to open the dictionary, emit a bunch of KV pairs, and close the dictionary. Apparently CPhidgetDictionary_close() is immediate and pays no attention to content that is queued for transmission to the server; the "socket closed" error is presumably because the writer thread is still trying to crank out KV pairs and the dictionary closes beneath it.
It appears to me that there is no mechanism to close the dictionary in an graceful fashion--basically, you have to wait "long enough" before closing it. This seems like a hole in the API.
Most open/close protocols have a "graceful" close and an "immediate" close as an option. Could you add one? Probably the only backward-compatible mechanism would be to add a separate call for the graceful close. You could then use the server disconnect callback to signal when the close completed. Extra credit for having an option for a blocking version of the close call for folks that aren't implementing the full even-driven paradigm.
While I can work around this issue, it does appear to be a fundamental flaw in the dictionary library, and it would be nice for it to be fixed.