forked from dcramer/mangodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
29 lines (25 loc) · 832 Bytes
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from gevent.server import StreamServer
import os
def mangodb(socket, address):
socket.sendall('HELLO\r\n')
client = socket.makefile()
output = open('/dev/null', 'w')
while 1:
line = client.readline()
if not line:
break
cmd_bits = line.split(' ', 1)
cmd = cmd_bits[0]
if cmd == 'BYE':
break
if len(cmd_bits) > 1:
output.write(cmd_bits[1])
if os.environ.get('MANGODB_DURABLE', False):
output.flush()
os.fsync(output.fileno())
client.write('OK' + os.urandom(1024).encode('string-escape') + '\r\n')
client.flush()
if __name__ == '__main__':
server = StreamServer(('0.0.0.0', 27017), mangodb)
print ('Starting MangoDB on port 27017')
server.serve_forever()