From 7c4a5846e83e41af5f26a56c37282e77d245ff46 Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 14 Nov 2011 22:15:01 -0800 Subject: As always, doing stuff during a constructor is a bad idea, especially if it contains a potential task switch. --- includes/Socket.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'includes/Socket.h') diff --git a/includes/Socket.h b/includes/Socket.h index 101c467..d5e58f6 100644 --- a/includes/Socket.h +++ b/includes/Socket.h @@ -57,15 +57,14 @@ class Socket : public Handle { template class Listener : public Task { public: - Listener(int port, const char * local = NULL, void * opaque = NULL) : m_listener(new Socket), m_stop(false), m_opaque(opaque) { - bool r = m_listener->setLocal(local, port); - Assert(r); - r = m_listener->listen(); - Assert(r); - m_name = String(ClassName(this).c_str()) + " - " + m_listener->getName(); - Printer::elog(E_SOCKET, "Created a listener task at %p", this); - } + Listener(int port, const char * local = "", void * opaque = NULL) : m_listener(new Socket), m_stop(false), m_local(local), m_port(port), m_opaque(opaque) { m_name = String(ClassName(this).c_str()) + " - Starting on " + m_local + ":" + port; } virtual void Do() { + bool r = m_listener->setLocal(m_local.to_charp(), m_port); + Assert(r); + r = m_listener->listen(); + Assert(r); + m_name = String(ClassName(this).c_str()) + " - " + m_listener->getName(); + Printer::elog(E_SOCKET, "Created a %s task at %p", ClassName(this).c_str(), this); waitFor(&m_evt); setOkayToEAgain(true); while (!m_stop) { @@ -93,6 +92,8 @@ class Listener : public Task { Events::Async m_evt; volatile bool m_stop; String m_name; + String m_local; + int m_port; void * m_opaque; }; -- cgit v1.2.3