diff options
author | Adam <Adam@anope.org> | 2010-10-01 21:45:46 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2010-10-01 21:45:46 -0400 |
commit | e3afb119b925513c103c661ffc3c75c7602005e1 (patch) | |
tree | ef2c7d82e1fc04743995b78f50675bec08f4e51b /src/socketengines/socketengine_pipe.cpp | |
parent | d44f7971b129aa7ba80999f16f17b8c7499686e1 (diff) |
Fixed pipe and win32 socketengine builds
Diffstat (limited to 'src/socketengines/socketengine_pipe.cpp')
-rw-r--r-- | src/socketengines/socketengine_pipe.cpp | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/src/socketengines/socketengine_pipe.cpp b/src/socketengines/socketengine_pipe.cpp index 21a558d66..9d5b47154 100644 --- a/src/socketengines/socketengine_pipe.cpp +++ b/src/socketengines/socketengine_pipe.cpp @@ -1,17 +1,33 @@ #include "services.h" -int Pipe::RecvInternal(char *buf, size_t sz) const +class PipeIO : public SocketIO { - static char dummy[512]; - while (read(this->Sock, &dummy, 512) == 512); - return 0; -} + 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 char dummy[512]; + while (read(s->GetFD(), &dummy, 512) == 512); + return 0; + } -int Pipe::SendInternal(const Anope::string &) const -{ - static const char dummy = '*'; - return write(this->WritePipe, &dummy, 1); -} + /** 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 + { + static const char dummy = '*'; + Pipe *pipe = debug_cast<Pipe *>(s); + return write(pipe->WritePipe, &dummy, 1); + } +} pipeSocketIO; Pipe::Pipe() : BufferedSocket() { @@ -23,6 +39,7 @@ Pipe::Pipe() : BufferedSocket() flags = fcntl(fds[1], F_GETFL, 0); fcntl(fds[1], F_SETFL, flags | O_NONBLOCK); + this->IO = &pipeSocketIO; this->Sock = fds[0]; this->WritePipe = fds[1]; this->IPv6 = false; @@ -32,7 +49,7 @@ Pipe::Pipe() : BufferedSocket() bool Pipe::ProcessRead() { - this->RecvInternal(NULL, 0); + this->IO->Recv(this, NULL, 0); return this->Read(""); } @@ -44,7 +61,7 @@ bool Pipe::Read(const Anope::string &) void Pipe::Notify() { - this->SendInternal(""); + this->IO->Send(this, ""); } void Pipe::OnNotify() |