]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blame - modules/cons.py
- connections can't be nonblocking, since I often need to wait for a reply
[projects/pld-ftp-admin.git] / modules / cons.py
CommitLineData
e3aced8e
MM
1# vi: encoding=utf-8 ts=8 sts=4 sw=4 et
2
3import socket
4import os
5import select
6from common import fileexists
7import ftpio
8import cmds
9
10class Connection:
11 def __init__(self, sock, authorized):
e3aced8e
MM
12 self.sock=sock
13 self.authorized=authorized
14 self.fileno=sock.fileno
b55905f2 15 self.name=""
e3aced8e
MM
16 self.data=""
17 def destroy(self):
18 self.sock.close()
19 rm(self)
20 def handleinput(self):
21 newdata=self.sock.recv(8192)
22 if not newdata:
23 self.destroy()
24 self.data=self.data+newdata
25 try:
26 cmds.parse(self)
5fcf3f9a 27 except cmds.BailOut:
e3aced8e
MM
28 self.destroy()
29
30def add(con):
31 cons.append(con)
32
33def rm(con):
34 cons.remove(con)
35
36def readables():
37 lst=cons[:]
38 lst.append(privlistener)
39 lst.append(publistener)
40 inlst,outlst,errlst = select.select(lst, [], [], 0)
41 return inlst
42
43def createlistener(path):
44 if fileexists(path):
45 os.remove(path)
46
47 s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
48 s.setblocking(False)
49 s.bind(path)
50 if path==ftpio.pubsock:
51 os.chmod(path, 0606)
52 else:
53 os.chmod(path, 0600)
54 s.listen(3)
55 return s
56
57cons=[]
58
59privlistener=createlistener(ftpio.privsock)
60publistener=createlistener(ftpio.pubsock)
61
62
63
This page took 0.075508 seconds and 4 git commands to generate.