a working socket error handling implementation