summaryrefslogtreecommitdiff
path: root/src/socketengines/pipeengine_win32.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2011-08-21 13:38:42 -0400
committerAdam <Adam@anope.org>2011-09-10 01:55:09 -0400
commit2eb708e5ad8b259876d24d828f7472b77864c256 (patch)
treebed6b70d4bc67eb413453a116e77f8f724cdf3fd /src/socketengines/pipeengine_win32.cpp
parent4fcb371bc8813cd647b7769a64d586e3a57d684d (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_win32.cpp')
-rw-r--r--src/socketengines/pipeengine_win32.cpp83
1 files changed, 22 insertions, 61 deletions
diff --git a/src/socketengines/pipeengine_win32.cpp b/src/socketengines/pipeengine_win32.cpp
index 3bd18d0cd..f34472870 100644
--- a/src/socketengines/pipeengine_win32.cpp
+++ b/src/socketengines/pipeengine_win32.cpp
@@ -1,89 +1,50 @@
#include "services.h"
-static ClientSocket *newsocket = NULL;
-
-class LSocket : public ListenSocket
-{
- public:
- LSocket(const Anope::string &host, int port) : ListenSocket(host, port, false) { }
-
- ClientSocket *OnAccept(int fd, const sockaddrs &addr)
- {
- newsocket = new ClientSocket(this, fd, addr);
- return newsocket;
- }
-};
-
-class PipeIO : public SocketIO
+Pipe::Pipe() : Socket(-1)
{
- 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];
- return recv(s->GetFD(), dummy, 512, 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 send(pipe->WritePipe, &dummy, 1, 0);
- }
-} pipeSocketIO;
+ sockaddrs localhost;
-Pipe::Pipe() : BufferedSocket()
-{
- LSocket lfs("127.0.0.1", 0);
+ localhost.pton(AF_INET, "127.0.0.1");
- int cfd = socket(AF_INET, SOCK_STREAM, 0);
+ int cfd = socket(AF_INET, SOCK_STREAM, 0), lfd = socket(AF_INET, SOCK_STREAM, 0);
if (cfd == -1)
throw CoreException("Error accepting new socket for Pipe");
+
+ if (bind(lfd, &localhost.sa, localhost.size()) == -1)
+ throw CoreException("Error accepting new socket for Pipe");
+ if (listen(lfd, 1) == -1)
+ throw CoreException("Error accepting new socket for Pipe");
- sockaddr_in addr;
- socklen_t sz = sizeof(addr);
- getsockname(lfs.GetFD(), reinterpret_cast<sockaddr *>(&addr), &sz);
+ sockaddrs lfd_addr;
+ socklen_t sz = sizeof(lfd_addr);
+ getsockname(lfd, &lfd_addr.sa, &sz);
- if (connect(cfd, reinterpret_cast<sockaddr *>(&addr), sz))
- throw CoreException("Error accepting new socket for Pipe");
- lfs.ProcessRead();
- if (!newsocket)
+ if (connect(cfd, &lfd_addr.sa, lfd_addr.size()))
throw CoreException("Error accepting new socket for Pipe");
+ CloseSocket(lfd);
- this->IO = &pipeSocketIO;
- this->Sock = cfd;
- this->WritePipe = newsocket->GetFD();
- this->IPv6 = false;
+ this->WritePipe = cfd;
SocketEngine::AddSocket(this);
- newsocket = NULL;
}
-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 (recv(this->GetFD(), dummy, 512, 0) == 512);
this->OnNotify();
return true;
}
void Pipe::Notify()
{
- this->IO->Send(this, "");
+ const char dummy = '*';
+ send(this->WritePipe, &dummy, 1, 0);
}
void Pipe::OnNotify()