aboutsummaryrefslogtreecommitdiff
path: root/src/ControlSocket.py
diff options
context:
space:
mode:
authorGravatar jesopo2018-10-06 15:37:05 +0100
committerGravatar jesopo2018-10-06 15:37:05 +0100
commit0794a5173ae2a45aad4f91f76a0fd0a9fe2939c4 (patch)
tree6652a20f47bb0113d9a70b392533a608664b12a4 /src/ControlSocket.py
parentAttempt to register servers for read/write when sending github hook notices (diff)
signature
Add a way to track non-IRC sockets within the main epoll loop; use this for a
unix domain control socket!
Diffstat (limited to 'src/ControlSocket.py')
-rw-r--r--src/ControlSocket.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/ControlSocket.py b/src/ControlSocket.py
new file mode 100644
index 00000000..ead2624b
--- /dev/null
+++ b/src/ControlSocket.py
@@ -0,0 +1,36 @@
+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")
+ print(data)