forked from agrover/python-rds
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
37 lines (23 loc) · 732 Bytes
/
server.py
File metadata and controls
37 lines (23 loc) · 732 Bytes
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
30
31
32
33
34
import rdma
import pickle
import mmap
import os
sock = rdma.RdmaSocket()
sock.bind("10.1.3.98", 6666)
os.chdir(os.path.expanduser("~/"))
user_token = 0xcafe
while (True):
pickled_cmd, sender, flags, ancillary = sock.recvmsg()
if ancillary:
print "ancillary: ",
print ancillary
continue
cmd = pickle.loads(pickled_cmd)
print cmd
offset = cmd["offset"]
length = cmd["length"]
f = open(cmd["filename"], "rb")
m = mmap.mmap(f.fileno(), 0, flags=mmap.MAP_PRIVATE) # mmap whole file
sock.rdma_sendmsg(m[offset:offset+length], cmd["cookie"],
offset, length, user_token, host=sender[0],
port=sender[1], data="here it is")