Example #1
0
    void IoThread()
    {
        StreamSocket acceptor;
        EXPECT_TRUE(m_listener.Accept(&acceptor));
        SocketAddressInet peer_address;
        EXPECT_TRUE(acceptor.GetPeerAddress(&peer_address));
#if __unix__
        int keep_alive;
        int idle;
        int interval;
        int count;
        EXPECT_TRUE(acceptor.SetTcpKeepAliveOption(14400, 150, 5));
        EXPECT_TRUE(acceptor.GetOption(SOL_SOCKET, SO_KEEPALIVE, &keep_alive));
        EXPECT_EQ(1, keep_alive);
        EXPECT_TRUE(acceptor.GetOption(SOL_TCP, TCP_KEEPIDLE, &idle));
        EXPECT_EQ(14400, idle);
        EXPECT_TRUE(acceptor.GetOption(SOL_TCP, TCP_KEEPINTVL, &interval));
        EXPECT_EQ(150, interval);
        EXPECT_TRUE(acceptor.GetOption(SOL_TCP, TCP_KEEPCNT, &count));
        EXPECT_EQ(5, count);
#endif
        std::string line;
        while (acceptor.ReceiveLine(&line) && !line.empty())
        {
            acceptor.SendAll(line.data(), line.size());
        }
    }
Example #2
0
TEST(Socket, SocketOption)
{
    StreamSocket socket;
    EXPECT_TRUE(socket.Create(AF_INET));
    EXPECT_TRUE(socket.SetCloexec(true));
    EXPECT_TRUE(socket.SetLinger(true, 5));
    struct linger l;
    EXPECT_TRUE(socket.GetOption(SOL_SOCKET, SO_LINGER, &l));
    EXPECT_TRUE(l.l_onoff);
    EXPECT_EQ(5, l.l_linger);
}