* @brief This file is the implementation file of tcpsock example
*/
#include <stddef.h>
+#include <memory>
#include <dpl/tcp_socket.h>
#include <dpl/abstract_socket.h>
#include <dpl/application.h>
#include <dpl/generic_event.h>
#include <dpl/binary_queue.h>
-#include <dpl/scoped_array.h>
-#include <dpl/log/log.h>
+#include <dpl/log/wrt_log.h>
#include <string>
#include <dpl/assert.h>
virtual void OnEventReceived(const DPL::AbstractSocketEvents::ConnectedEvent &event)
{
(void)event;
- LogDebug("Connected!");
+ WrtLogD("Connected!");
// Send request
DPL::BinaryQueue data;
virtual void OnEventReceived(const DPL::AbstractSocketEvents::ReadEvent &event)
{
(void)event;
- LogDebug("Read!");
+ WrtLogD("Read!");
DPL::BinaryQueueAutoPtr data = m_socket.Read(100); // Bad: DLOG cannot log more than about 450 bytes...
if (data->Empty())
{
- LogDebug("Connection closed!");
+ WrtLogD("Connection closed!");
m_socket.Close();
// Done
}
// Show data
- DPL::ScopedArray<char> text(new char[data->Size()]);
- data->Flatten(text.Get(), data->Size());
+ std::unique_ptr<char[]> text(new char[data->Size()]);
+ data->Flatten(text.get(), data->Size());
- LogPedantic("READ: \n--------------------------------------------------------\n"
- << std::string(text.Get(), text.Get() + data->Size()) <<
+ WrtLogD("READ: \n--------------------------------------------------------\n"
+ << std::string(text.Get(), text.get() + data->Size()) <<
"\n--------------------------------------------------------");
}
MyApplication(int argc, char **argv)
: Application(argc, argv, "tcpsock")
{
- LogDebug("CTOR!");
+ WrtLogD("CTOR!");
// Add listeners
m_socket.DPL::EventSupport<DPL::AbstractSocketEvents::ConnectedEvent>::AddListener(this);
// Connect
m_socket.Open();
- LogDebug("Connecting...");
+ WrtLogD("Connecting...");
m_socket.Connect(DPL::Address("en.wikipedia.org", 80));
}
virtual ~MyApplication()
{
- LogDebug("DTOR!");
+ WrtLogD("DTOR!");
// Remove listeners
m_socket.DPL::EventSupport<DPL::AbstractSocketEvents::ConnectedEvent>::RemoveListener(this);