]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blob - 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
1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
2
3 import socket
4 import os
5 import select
6 from common import fileexists
7 import ftpio
8 import cmds
9
10 class Connection:
11     def __init__(self, sock, authorized):
12         self.sock=sock
13         self.authorized=authorized
14         self.fileno=sock.fileno
15         self.name=""
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)
27         except cmds.BailOut:
28             self.destroy()
29
30 def add(con):
31     cons.append(con)
32    
33 def rm(con):
34     cons.remove(con)
35
36 def readables():
37     lst=cons[:]
38     lst.append(privlistener)
39     lst.append(publistener)
40     inlst,outlst,errlst = select.select(lst, [], [], 0)
41     return inlst
42
43 def 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
57 cons=[]
58
59 privlistener=createlistener(ftpio.privsock)
60 publistener=createlistener(ftpio.pubsock)
61
62
63
This page took 0.046976 seconds and 3 git commands to generate.