mirror of
https://github.com/anope/anope.git
synced 2026-07-03 03:03:13 +02:00
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
This commit is contained in:
@@ -1,64 +1,29 @@
|
||||
#include "services.h"
|
||||
#include <sys/eventfd.h>
|
||||
|
||||
class PipeIO : public SocketIO
|
||||
Pipe::Pipe() : Socket(eventfd(0, EFD_NONBLOCK))
|
||||
{
|
||||
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 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)
|
||||
{
|
||||
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;
|
||||
throw CoreException("Could not create pipe: " + Anope::LastError());
|
||||
|
||||
SocketEngine::AddSocket(this);
|
||||
}
|
||||
|
||||
bool Pipe::ProcessRead()
|
||||
Pipe::~Pipe()
|
||||
{
|
||||
this->IO->Recv(this, NULL, 0);
|
||||
return this->Read("");
|
||||
}
|
||||
|
||||
bool Pipe::Read(const Anope::string &)
|
||||
bool Pipe::ProcessRead()
|
||||
{
|
||||
eventfd_t dummy;
|
||||
eventfd_read(this->GetFD(), &dummy);
|
||||
this->OnNotify();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Pipe::Notify()
|
||||
{
|
||||
/* Note we send this immediatly. If use use Socket::Write and if this functions is called
|
||||
* from a thread, only epoll is able to pick up the change to this sockets want flags immediately
|
||||
* Other engines time out then pick up and write the change then read it back, which
|
||||
* is too slow for most things.
|
||||
*/
|
||||
this->IO->Send(this, "");
|
||||
eventfd_write(this->GetFD(), 1);
|
||||
}
|
||||
|
||||
void Pipe::OnNotify()
|
||||
|
||||
Reference in New Issue
Block a user