# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. """ Simplistic RPC implementation. Exposes all functions of a Server object. Uses pickle for serialization and the socket interface. """ import os,pdb,pickle,time,errno,sys,_thread,traceback,socket,threading,gc import logging LOG = logging.getLogger(__name__) # default PORT=12032 ######################################################################### # simple I/O functions def inline_send_handle(f, conn): st = os.fstat(f.fileno()) size = st.st_size pickle.dump(size, conn) conn.write(f.read(size)) def inline_send_string(s, conn): size = len(s) pickle.dump(size, conn) conn.write(s) class FileSock: " wraps a socket so that it is usable by pickle/cPickle " def __init__(self,sock): self.sock = sock self.nr=0 def write(self, buf): # print("sending %d bytes"%len(buf)) #self.sock.sendall(buf) # print("...done") bs = 512 * 1024 ns = 0 while ns < len(buf): sent = self.sock.send(buf[ns:ns + bs]) ns += sent def read(self,bs=512*1024): #if self.nr==10000: pdb.set_trace() self.nr+=1 # print("read bs=%d"%bs) b = [] nb = 0 while len(b)