/* * Check that RemoveWriteDescriptor is reentrant. * Similar to the case above, but this removes & deletes the descriptor from * within the OnRead callback of the same descriptor. */ void SelectServerTest::testRemoveWriteWhenReadable() { // Ownership is transferred to the SelectServer. LoopbackDescriptor *loopback = new LoopbackDescriptor(); loopback->Init(); loopback->SetOnData(NewCallback( this, &SelectServerTest::ReadDataAndRemove, static_cast<ConnectedDescriptor*>(loopback))); loopback->SetOnWritable(NewCallback(this, &SelectServerTest::NullHandler)); OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(loopback)); OLA_ASSERT_TRUE(m_ss->AddWriteDescriptor(loopback)); OLA_ASSERT_EQ(2, connected_read_descriptor_count->Get()); OLA_ASSERT_EQ(1, write_descriptor_count->Get()); OLA_ASSERT_EQ(0, read_descriptor_count->Get()); // Send some data to make this descriptor readable. uint8_t data[] = {'a'}; loopback->Send(data, arraysize(data)); m_ss->Run(); OLA_ASSERT_EQ(0, write_descriptor_count->Get()); OLA_ASSERT_EQ(1, connected_read_descriptor_count->Get()); OLA_ASSERT_EQ(0, read_descriptor_count->Get()); }