diff options
author | Adam <Adam@anope.org> | 2010-10-01 21:01:49 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2010-10-01 21:01:49 -0400 |
commit | d44f7971b129aa7ba80999f16f17b8c7499686e1 (patch) | |
tree | a86d08c3e641ed6b499b53b3bbb74e2a7f5b0dfb /src/socketengines | |
parent | 70056dd4689eeab4f7a9b31a921e0d7e40d5ed0d (diff) |
Rewrote some of the socket code to allow m_ssl to be a service.
This allows modules (xmlrpc) to create and accept SSL connections.
Also fixed unloading m_mysql at certain times and made the threading
engine always work correctly on Windows.
Diffstat (limited to 'src/socketengines')
-rw-r--r-- | src/socketengines/socketengine_eventfd.cpp | 41 | ||||
-rw-r--r-- | src/socketengines/socketengine_pipe.cpp | 3 | ||||
-rw-r--r-- | src/socketengines/socketengine_win32.cpp | 7 |
3 files changed, 32 insertions, 19 deletions
diff --git a/src/socketengines/socketengine_eventfd.cpp b/src/socketengines/socketengine_eventfd.cpp index a0efe5286..4e4016326 100644 --- a/src/socketengines/socketengine_eventfd.cpp +++ b/src/socketengines/socketengine_eventfd.cpp @@ -1,32 +1,47 @@ #include "services.h" #include <sys/eventfd.h> -int Pipe::RecvInternal(char *buf, size_t sz) const +class PipeIO : public SocketIO { - static eventfd_t dummy; - return !eventfd_read(this->Sock, &dummy); -} - -int Pipe::SendInternal(const Anope::string &) const -{ - return !eventfd_write(this->Sock, 1); -} - -Pipe::Pipe() : Socket() + public: + /** Receive something from the buffer + * @param s The socket + * @param buf The buf to read to + * @param sz How much to read + * @return Number of bytes received + */ + int Recv(Socket *s, char *buf, size_t sz) const + { + static eventfd_t dummy; + return !eventfd_read(s->GetFD(), &dummy); + } + + /** Write something to the socket + * @param s The socket + * @param buf What to write + * @return Number of bytes written + */ + int Send(Socket *s, const Anope::string &buf) const + { + return !eventfd_write(s->GetFD(), 1); + } +} pipeSocketIO; + +Pipe::Pipe() : BufferedSocket() { + this->IO = &pipeSocketIO; this->Sock = eventfd(0, EFD_NONBLOCK); if (this->Sock < 0) throw CoreException(Anope::string("Could not create pipe: ") + Anope::LastError()); this->IPv6 = false; - this->Type = SOCKTYPE_CLIENT; SocketEngine->AddSocket(this); } bool Pipe::ProcessRead() { - this->RecvInternal(NULL, 0); + this->IO->Recv(this, NULL, 0); return this->Read(""); } diff --git a/src/socketengines/socketengine_pipe.cpp b/src/socketengines/socketengine_pipe.cpp index b0be664c8..21a558d66 100644 --- a/src/socketengines/socketengine_pipe.cpp +++ b/src/socketengines/socketengine_pipe.cpp @@ -13,7 +13,7 @@ int Pipe::SendInternal(const Anope::string &) const return write(this->WritePipe, &dummy, 1); } -Pipe::Pipe() : Socket() +Pipe::Pipe() : BufferedSocket() { int fds[2]; if (pipe(fds)) @@ -26,7 +26,6 @@ Pipe::Pipe() : Socket() this->Sock = fds[0]; this->WritePipe = fds[1]; this->IPv6 = false; - this->Type = SOCKTYPE_CLIENT; SocketEngine->AddSocket(this); } diff --git a/src/socketengines/socketengine_win32.cpp b/src/socketengines/socketengine_win32.cpp index 1b1a4e50d..5d2c2d7cb 100644 --- a/src/socketengines/socketengine_win32.cpp +++ b/src/socketengines/socketengine_win32.cpp @@ -7,9 +7,9 @@ class LSocket : public ListenSocket public: LSocket(const Anope::string &host, int port) : ListenSocket(host, port) { } - bool OnAccept(Socket *s) + bool OnAccept(int fd, const sockaddrs &) { - newsocket = s; + newsocket = new Socket(fd, this->IPv6); return true; } }; @@ -26,7 +26,7 @@ int Pipe::SendInternal(const Anope::string &) const return write(this->WritePipe, &dummy, 1); } -Pipe::Pipe() : Socket() +Pipe::Pipe() : BufferedSocket() { LSocket lfs("127.0.0.1", 0); @@ -47,7 +47,6 @@ Pipe::Pipe() : Socket() this->Sock = cfd; this->WritePipe = newsocket->GetSock(); this->IPv6 = false; - this->Type = SOCKTYPE_CLIENT; SocketEngine->AddSocket(this); newsocket = NULL; |