msgpack/msgpack-rpc — pull request #49 by sugi (2012-03-29 07:42:59+00:00)
Title: [PATCH] various fix on php library (error handling and misc)

Hello!

I sent single pull request with recent changes.
If you convenient, I'll split the request for each features.
Plese feel free to request me if so.

Details of changes follows (ordered by priority);

Spec violation on error handling.
----------------------------------------------------------

I found PHP library has two violations against MessagePack RPC spec on error response.

* Treating empty string of error field of response object as success. This must be null (Nil on spec).
* User get fatal error when error is not string (e.g. object, array).

Here is a minimal fix for these problem.
(NOTE: This change breaks backward compatibility.)

Error handling improvements
------------------------------------------------------

1. Add exception classes with suitable messasge

Currently the library uses base 'Exception' class directly with just two error message for any error.
So user have poor way to handle errors.

Fix by splitting exception class for each case and throw it with suitable error messasge.

2. Handle exception on backend service

PHP server always return success as response and will die
when get any exception from method call of backend service.

I worte change to handle exceptions and return error object correctly.

Fix require chain properly.
--------------------------------------------------

Tiny fixes for require/include chain properly:
* Add require backend library to Server.php.
* Change to use 'require' intead of 'include'. In the fact, library dose not work completely when include fails.

Make sure to close server socket.
------------------------------------------------

Currently Server library will leaves listen socket when
get any exception or signal. The socket will be closed
by OS after some period, but it is not convenient.

This is a simple patch to make sure to close listen socket
when finish server process.