Ejemplo n.º 1
0
bool xtcp_server::start(const xtcp_endpoint& endpoint)
{
    xdebug_info((xchar_format(xtr(_X("Starting TCP server at endpoint ({1}:{2})..."))) %
            match_str<xstring, std::string>::apply(endpoint.address().to_string()) %
            endpoint.port()));
    xerror_code error_code;
    acceptor_.open(endpoint.protocol(), error_code);
    if (error_code)
    {
        xlog_error(xchar_format(xtr(_X("Failed to open acceptor with endpoint ({1}:{2}) with error \"{3}\"."))) %
            match_str<xstring, std::string>::apply(endpoint.address().to_string()) %
            endpoint.port() %
            match_str<xstring, std::string>::apply(error_code.message()));
        return false;
    }
    //
    acceptor_.bind(endpoint, error_code);
    if (error_code)
    {
        xlog_error(xchar_format(xtr(_X("Failed to bind acceptor with endpoint ({1}:{2}) with error \"{3}\"."))) %
            match_str<xstring, std::string>::apply(endpoint.address().to_string()) %
            endpoint.port() %
            match_str<xstring, std::string>::apply(error_code.message()));
        return false;
    }
    //
    acceptor_.listen(MAX_CONNECTIONS, error_code);
    if (error_code)
    {
        xlog_error(xchar_format(xtr(_X("Failed to listen to endpoint ({1}:{2}) with error \"{3}\"."))) %
            match_str<xstring, std::string>::apply(endpoint.address().to_string()) %
            endpoint.port() %
            match_str<xstring, std::string>::apply(error_code.message()));
        return false;
    }
    start_accept();
    return true;
}
Ejemplo n.º 2
0
			inline void log_dx_error(HRESULT hr)
			{
				const wchar_t* msg = ::DXGetErrorString9(hr);
				xlog_error("0x%8x %ls", hr, msg);
			}