return msg;
}
+ void nozero_assert(int code, const char* msg){
+ if ( code != 0 )
+ throw socket_exception(code, ::std::string(msg) + ' ' + get_last_error_msg());
+ }
+
public:
socket(int af=AF_INET, int type=SOCK_STREAM, int protocol=0)
: m_sock(NULL)
m_sock = ::socket(af, type, protocol);
- if ( ::WSAGetLastError() != 0 )
- throw socket_exception(::WSAGetLastError(), "roast::socket::socket() ::socket() function was error.");
+ nozero_assert(::WSAGetLastError(), "roast::socket::socket() ::socket() function was error.");
+
if ( m_sock == INVALID_SOCKET )
throw socket_exception(::WSAGetLastError(), "roast::socket::socket() m_sock is INVALID_SOCKET.");
}
{
::closesocket(m_sock);
- if ( ::WSAGetLastError() != 0 )
- throw socket_exception(::WSAGetLastError(), "roast::socket::close() ::closesocket() function was error.");
+ nozero_assert(::WSAGetLastError(), "roast::socket::close() ::closesocket() function was error.");
m_sock = INVALID_SOCKET;
}
#pragma warning(default: 4996)
::addrinfo *addr=NULL;
- if ( ::getaddrinfo(host, port_str, &hints, &addr) != 0 )
- throw socket_exception(::WSAGetLastError(), "roast::socket::connect() ::getaddrinfo() function was error.");
+ nozero_assert( ::getaddrinfo(host, port_str, &hints, &addr), "roast::socket::connect() ::getaddrinfo() function was error.");
- if ( ::connect(m_sock, addr->ai_addr, addr->ai_addrlen) != 0 ){
+ int code = ::connect(m_sock, addr->ai_addr, addr->ai_addrlen);
+ if ( code != 0 ){
::freeaddrinfo(addr);
- throw socket_exception(::WSAGetLastError(), "roast::socket::connect() ::connect() function was error.");
+ throw socket_exception(::WSAGetLastError(), "roast::socket::connect() ::connect() function was error." + ' ' + get_last_error_msg());
}
::freeaddrinfo(addr);