diff options
author | Pixel <pixel@nobis-crew.org> | 2011-11-14 22:15:01 -0800 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2011-11-14 22:21:23 -0800 |
commit | 7c4a5846e83e41af5f26a56c37282e77d245ff46 (patch) | |
tree | 8c69838a6e12a746680dd3002c4984b6f48eac9d /includes | |
parent | 9f0a9645ea384527882d977e89e9c559124e22d2 (diff) |
As always, doing stuff during a constructor is a bad idea, especially if it contains a potential task switch.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/Socket.h | 17 |
1 files changed, 9 insertions, 8 deletions
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 Worker> 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; }; |