This is a far less complicated way of triggering epoll.poll

This commit is contained in:
jesopo 2018-10-07 07:54:10 +01:00
parent 661199aa54
commit bb533ab9e8
2 changed files with 5 additions and 45 deletions

View file

@ -1,35 +0,0 @@
import os, socket
from src import Socket
class ControlSocket(object):
def __init__(self, bot):
self.bot = bot
location = bot.config["control-socket"]
if os.path.exists(location):
os.unlink(location)
self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.socket.bind(location)
self.socket.listen()
self.connected = True
def fileno(self):
return self.socket.fileno()
def waiting_send(self):
return False
def _send(self):
pass
def read(self):
client, addr = self.socket.accept()
self.bot.add_socket(Socket.Socket(client, self.on_read))
return []
def parse_data(self, data):
command = data.split(" ", 1)[0].upper()
if command == "TRIGGER":
pass
else:
raise ValueError("unknown control socket command: '%s'" %
command)
def on_read(self, sock, data):
data = data.strip("\r\n")

View file

@ -1,6 +1,6 @@
import os, select, socket, sys, threading, time, traceback, uuid import os, select, socket, sys, threading, time, traceback, uuid
from src import ControlSocket, EventManager, Exports, IRCServer, Logging from src import EventManager, Exports, IRCServer, Logging, ModuleManager
from src import ModuleManager, utils from src import Socket, utils
class Bot(object): class Bot(object):
def __init__(self, directory, args, cache, config, database, events, def __init__(self, directory, args, cache, config, database, events,
@ -23,16 +23,11 @@ class Bot(object):
self.servers = {} self.servers = {}
self.other_sockets = {} self.other_sockets = {}
self._trigger_server, self._trigger_client = socket.socketpair()
if "contorl-socket" in self.config: self.add_socket(Socket.Socket(self._trigger_server, lambda x: x))
self.control_socket = ControlSocket.ControlSocket(self)
self.add_socket(self.control_socket)
self._control_sclient = socket.socket(
socket.AF_UNIX, socket.SOCK_STREAM)
self._control_client.connect(self.config["control-socket"])
def trigger(self): def trigger(self):
self._control_client.send(b"TRIGGER") self._trigger_client.send(b"TRIGGER")
def add_server(self, server_id, connect=True): def add_server(self, server_id, connect=True):
(_, alias, hostname, port, password, ipv4, tls, bindhost, nickname, (_, alias, hostname, port, password, ipv4, tls, bindhost, nickname,