diff options
author | Adam <Adam@anope.org> | 2011-08-21 13:38:42 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2011-09-10 01:55:09 -0400 |
commit | 2eb708e5ad8b259876d24d828f7472b77864c256 (patch) | |
tree | bed6b70d4bc67eb413453a116e77f8f724cdf3fd /src/socketengines/pipeengine_pipe.cpp | |
parent | 4fcb371bc8813cd647b7769a64d586e3a57d684d (diff) |
Cleaned up some of the socket code, cleaned up the pipe engines, added support for binary sockets, and cleaned up the asynch connect/accept code
Diffstat (limited to 'src/socketengines/pipeengine_pipe.cpp')
-rw-r--r-- | src/socketengines/pipeengine_pipe.cpp | 49 |
1 files changed, 11 insertions, 38 deletions
diff --git a/src/socketengines/pipeengine_pipe.cpp b/src/socketengines/pipeengine_pipe.cpp index b3ca15d87..ceaded8ea 100644 --- a/src/socketengines/pipeengine_pipe.cpp +++ b/src/socketengines/pipeengine_pipe.cpp @@ -1,67 +1,40 @@ #include "services.h" -class PipeIO : public SocketIO -{ - 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) - { - static char dummy[512]; - while (read(s->GetFD(), &dummy, 512) == 512); - return 0; - } - - /** 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) - { - static const char dummy = '*'; - Pipe *pipe = debug_cast<Pipe *>(s); - return write(pipe->WritePipe, &dummy, 1); - } -} pipeSocketIO; - -Pipe::Pipe() : BufferedSocket() +Pipe::Pipe() : Socket(-1) { int fds[2]; if (pipe(fds)) - throw CoreException(Anope::string("Could not create pipe: ") + Anope::LastError()); + throw CoreException("Could not create pipe: " + Anope::LastError()); int flags = fcntl(fds[0], F_GETFL, 0); fcntl(fds[0], F_SETFL, flags | O_NONBLOCK); flags = fcntl(fds[1], F_GETFL, 0); fcntl(fds[1], F_SETFL, flags | O_NONBLOCK); - this->IO = &pipeSocketIO; + this->~Socket(); + this->Sock = fds[0]; this->WritePipe = fds[1]; - this->IPv6 = false; SocketEngine::AddSocket(this); } -bool Pipe::ProcessRead() +Pipe::~Pipe() { - this->IO->Recv(this, NULL, 0); - return this->Read(""); + CloseSocket(this->WritePipe); } -bool Pipe::Read(const Anope::string &) +bool Pipe::ProcessRead() { + char dummy[512]; + while (read(this->GetFD(), &dummy, 512) == 512); this->OnNotify(); return true; } void Pipe::Notify() { - this->IO->Send(this, ""); + const char dummy = '*'; + write(this->WritePipe, &dummy, 1); } void Pipe::OnNotify() |