Esempio n. 1
0
    void TCPSocket::Connect(const SocketAddress& address)
    {
        if (!_socket.IsValid())
            /* throw invalid socket */
            throw InvalidSocketException{ LOGIC_EXCEPT("Invalid socket") };

        auto rc = 0;

        do
        {
            rc = ::connect(_socket, address.GetRawAddress(), address.RawLength());
        }
        while (rc == NET_SOCKET_ERROR && Socket::LastError() == NETERRNO(EINTR));

        if (rc == NET_SOCKET_ERROR)
            OnSocketError();
    }
Esempio n. 2
0
    std::uint32_t UDPSocket::SendTo(const SocketAddress& address, const std::uint8_t*buffer, std::uint32_t length, std::uint32_t flags)
    {
        if (!_socket.IsValid())
            throw InvalidSocketException{ LOGIC_EXCEPT("Invalid socket") };

        auto rc = 0;

        do
        {
            rc = ::sendto(_socket, reinterpret_cast<const char*>(buffer), length, flags, address.GetRawAddress(), address.RawLength());
        } 
        while (rc < 0 && Socket::LastError() == NETERRNO(EINTR));

        if (rc < 0)
        {
            OnSocketError();
            rc = 0;
        }

        return static_cast<std::uint32_t>(rc);
    }