From 4e07ceeb21dae4b6b8d5eaf7421228f735f14bda Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 18 Oct 2011 11:33:50 -0700 Subject: Adding a few more asserts, and using the proper function calls (ntohs instead of htons - which should be fundamentally the same, but, *shrug*) --- includes/Socket.h | 5 +++-- src/Socket.cc | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/includes/Socket.h b/includes/Socket.h index b762d9b..3b29f49 100644 --- a/includes/Socket.h +++ b/includes/Socket.h @@ -58,8 +58,9 @@ template class Listener : public Task { public: Listener(int port, const char * local = NULL) : m_stop(false) { - m_listener.setLocal(local, port); - bool r = m_listener.listen(); + 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); diff --git a/src/Socket.cc b/src/Socket.cc index 057c2ab..ba528aa 100644 --- a/src/Socket.cc +++ b/src/Socket.cc @@ -275,7 +275,7 @@ Balau::Socket::Socket(int fd) : m_fd(fd), m_connected(true), m_connecting(false) fcntl(m_fd, F_SETFL, O_NONBLOCK); #endif - m_name.set("Socket(Connected - [%s]:%i <- [%s]:%i)", rLocal, htons(m_localAddr.sin6_port), rRemote, htons(m_remoteAddr.sin6_port)); + m_name.set("Socket(Connected - [%s]:%i <- [%s]:%i)", rLocal, ntohs(m_localAddr.sin6_port), rRemote, ntohs(m_remoteAddr.sin6_port)); Printer::elog(E_SOCKET, "Created a new socket from listener at %p; %s", this, m_name.to_charp()); } @@ -351,6 +351,7 @@ bool Balau::Socket::connect(const char * hostname, int port) { Assert(!m_listening); Assert(!m_connected); Assert(hostname); + Assert(!isClosed()); if (!m_connecting) { Printer::elog(E_SOCKET, "Resolving %s", hostname); @@ -417,7 +418,7 @@ bool Balau::Socket::connect(const char * hostname, int port) { Assert(rLocal); Assert(rRemote); - m_name.set("Socket(Connected - [%s]:%i -> [%s]:%i)", rLocal, htons(m_localAddr.sin6_port), rRemote, htons(m_remoteAddr.sin6_port)); + m_name.set("Socket(Connected - [%s]:%i -> [%s]:%i)", rLocal, ntohs(m_localAddr.sin6_port), rRemote, ntohs(m_remoteAddr.sin6_port)); Printer::elog(E_SOCKET, "Connected; %s", m_name.to_charp()); m_evtW->stop(); @@ -448,6 +449,7 @@ bool Balau::Socket::listen() { Assert(!m_listening); Assert(!m_connecting); Assert(!m_connected); + Assert(!isClosed()); if (::listen(m_fd, 16) == 0) { m_listening = true; @@ -465,7 +467,7 @@ bool Balau::Socket::listen() { Assert(rLocal); - m_name.set("Socket(Listener - [%s]:%i)", rLocal, htons(m_localAddr.sin6_port)); + m_name.set("Socket(Listener - [%s]:%i)", rLocal, ntohs(m_localAddr.sin6_port)); Printer::elog(E_SOCKET, "Socket %i started to listen: %s", m_fd, m_name.to_charp()); } else { String msg = getErrorMessage(); -- cgit v1.2.3