summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-11-15 10:47:09 -0800
committerPixel <pixel@nobis-crew.org>2011-11-15 10:47:09 -0800
commit2ca2ef499eef0ebb1716857fc27121c0c4c3f2e3 (patch)
tree1f106ef5b1e85ed007f831ba0f1b3bd8bfc9c5b5
parent0173f9a80775821439a02adaa9535505cbfa9ec5 (diff)
Fixing the Socket code a bit, effectively making the listener system working.
-rw-r--r--includes/Socket.h6
-rw-r--r--src/Socket.cc11
2 files changed, 8 insertions, 9 deletions
diff --git a/includes/Socket.h b/includes/Socket.h
index d5e58f6..31830e1 100644
--- a/includes/Socket.h
+++ b/includes/Socket.h
@@ -34,9 +34,9 @@ class Socket : public Handle {
Socket(int fd);
class SocketEvent : public Events::BaseEvent {
public:
- SocketEvent(int fd, int evt = EV_READ | EV_WRITE) : m_task(NULL) { Printer::elog(E_SOCKET, "Got a new SocketEvent at %p", this); m_evt.set<SocketEvent, &SocketEvent::evt_cb>(this); m_evt.set(fd, evt); }
- virtual ~SocketEvent() { m_evt.stop(); }
- void stop() { reset(); m_evt.stop(); }
+ SocketEvent(int fd, int evt = ev::READ | ev::WRITE) : m_task(NULL) { Printer::elog(E_SOCKET, "Got a new SocketEvent at %p", this); m_evt.set<SocketEvent, &SocketEvent::evt_cb>(this); m_evt.set(fd, evt); }
+ virtual ~SocketEvent() { Printer::elog(E_SOCKET, "Destroying a SocketEvent at %p", this); m_evt.stop(); }
+ void stop() { Printer::elog(E_SOCKET, "Stopping a SocketEvent at %p", this); reset(); m_evt.stop(); }
private:
void evt_cb(ev::io & w, int revents) { Printer::elog(E_SOCKET, "Got a libev callback on a SocketEvent at %p", this); doSignal(); }
virtual void gotOwner(Task * task);
diff --git a/src/Socket.cc b/src/Socket.cc
index f625c91..6b1f551 100644
--- a/src/Socket.cc
+++ b/src/Socket.cc
@@ -18,7 +18,7 @@ void Balau::Socket::SocketEvent::gotOwner(Task * task) {
if (!m_task) {
Printer::elog(E_SOCKET, "...with a new task (%p)", task);
} else if (task == m_task) {
- m_evt.start();
+ Printer::elog(E_SOCKET, "...with the same task, doing nothing.");
return;
} else {
Printer::elog(E_SOCKET, "...with a new task (%p -> %p); stopping first", m_task, task);
@@ -235,8 +235,8 @@ static DNSRequest resolveName(const char * name, const char * service = NULL, st
Balau::Socket::Socket() throw (GeneralException) : m_fd(socket(AF_INET6, SOCK_STREAM, 0)), m_connected(false), m_connecting(false), m_listening(false) {
m_name = "Socket(unconnected)";
Assert(m_fd >= 0);
- m_evtR = new SocketEvent(m_fd, EV_READ);
- m_evtW = new SocketEvent(m_fd, EV_WRITE);
+ m_evtR = new SocketEvent(m_fd, ev::READ);
+ m_evtW = new SocketEvent(m_fd, ev::WRITE);
#ifdef _WIN32
u_long iMode = 1;
ioctlsocket(m_fd, FIONBIO, &iMode);
@@ -267,8 +267,8 @@ Balau::Socket::Socket(int fd) : m_fd(fd), m_connected(true), m_connecting(false)
Assert(rLocal);
Assert(rRemote);
- m_evtR = new SocketEvent(m_fd, EV_READ);
- m_evtW = new SocketEvent(m_fd, EV_WRITE);
+ m_evtR = new SocketEvent(m_fd, ev::READ);
+ m_evtW = new SocketEvent(m_fd, ev::WRITE);
#ifdef _WIN32
u_long iMode = 1;
ioctlsocket(m_fd, FIONBIO, &iMode);
@@ -505,7 +505,6 @@ Balau::IO<Balau::Socket> Balau::Socket::accept() throw (GeneralException) {
}
} else {
Printer::elog(E_SOCKET, "Listener at %p got a new connection", this);
- m_evtR->stop();
return IO<Socket>(new Socket(s));
}
}