From d4111cb49581935d169c5eccc95aab60c69f9bdf Mon Sep 17 00:00:00 2001 From: root Date: Mon, 19 Dec 2016 14:11:17 +0800 Subject: [PATCH] with size and targetdir --- client.cpp | 16 +++++++++------- client.h | 2 +- client.py | 31 ++++++++++++++++++++----------- libclient.so | Bin 13285 -> 13291 bytes main.cpp | 2 +- server.py | 30 +++++++++++++++++++----------- 6 files changed, 50 insertions(+), 31 deletions(-) diff --git a/client.cpp b/client.cpp index ff19c8a..0072faa 100644 --- a/client.cpp +++ b/client.cpp @@ -1,9 +1,9 @@ #include "client.h" -void transfer(const char *action,const char *host,const char *filepath,const char *uid,const char *gid,const char *position) +void transfer(const char *action,const char *host,const char *filepath,const char *targetdir,const char *uid,const char *gid,const char *position,const char *size) { Py_Initialize(); - if(Py_IsInitialized()) + if(!Py_IsInitialized()) { printf("can't initialize\n"); } @@ -14,17 +14,19 @@ void transfer(const char *action,const char *host,const char *filepath,const cha PyRun_SimpleString("import os"); PyRun_SimpleString("import string"); PyRun_SimpleString("sys.path.append('./')"); - PyObject *pArgs = PyTuple_New(6); + PyObject *pArgs = PyTuple_New(8); PyTuple_SetItem(pArgs,0,Py_BuildValue("s",action)); PyTuple_SetItem(pArgs,1,Py_BuildValue("s",host)); PyTuple_SetItem(pArgs,2,Py_BuildValue("s",filepath)); - PyTuple_SetItem(pArgs,3,Py_BuildValue("s",uid)); - PyTuple_SetItem(pArgs,4,Py_BuildValue("s",gid)); - PyTuple_SetItem(pArgs,5,Py_BuildValue("s",position)); + PyTuple_SetItem(pArgs,3,Py_BuildValue("s",targetdir)); + PyTuple_SetItem(pArgs,4,Py_BuildValue("s",uid)); + PyTuple_SetItem(pArgs,5,Py_BuildValue("s",gid)); + PyTuple_SetItem(pArgs,6,Py_BuildValue("s",position)); + PyTuple_SetItem(pArgs,7,Py_BuildValue("s",size)); pModule = PyImport_ImportModule("client"); if(pModule == NULL) { - printf("can't python file\n"); + printf("can't load module\n"); } pFunc = PyObject_GetAttrString(pModule,"entrance"); if(pFunc == NULL) diff --git a/client.h b/client.h index 0750a2f..acfea88 100644 --- a/client.h +++ b/client.h @@ -3,5 +3,5 @@ #include #include using namespace std; -void transfer(const char *action,const char *host,const char *filepath,const char *uid,const char *gid,const char *position); +void transfer(const char *action,const char *host,const char *filepath,const char *targetdir,const char *uid,const char *gid,const char *position,const char *size); #endif diff --git a/client.py b/client.py index 51a2568..7f50bea 100644 --- a/client.py +++ b/client.py @@ -1,9 +1,12 @@ from tornado.httpclient import HTTPRequest, AsyncHTTPClient +from tornado.simple_httpclient import SimpleAsyncHTTPClient import tornado.ioloop import tornado.web import os,sys from tornado import gen from functools import partial +#import time,datatime + total_downloaded = 0 #action = sys.argv[1] @@ -11,12 +14,12 @@ total_downloaded = 0 #uid = sys.argv[3] #gid = sys.argv[4] #pos = sys.argv[5] -def geturl(action,host,filepath,uid,gid,pos): +def geturl(action,host,filepath,uid,gid,pos,size): if action=="read": # uid = sys.argv[3] # gid = sys.argv[4] # pos = sys.argv[5] - url = "http://"+host+":8880/read?filepath="+filepath+"&uid="+uid+"&gid="+gid+"&pos="+pos + url = "http://"+host+":8888/read?filepath="+filepath+"&uid="+uid+"&gid="+gid+"&pos="+pos+"&size="+size print(url) return url @@ -27,25 +30,31 @@ def chunky(path, chunk): total_downloaded += len(chunk) print("chunk size",len(chunk)) # the OS blocks on file reads + writes -- beware how big the chunks is as it could effect things - with open(path, 'a+b') as f: + with open(path, 'ab') as f: f.write(chunk) @gen.coroutine -def writer(action,host,filepath,uid,gid,pos): +def writer(action,host,filepath,targetdir,uid,gid,pos,size): print("writer function") # tornado.ioloop.IOLoop.instance().start() - file_name = os.path.basename(filepath)+"_new" - f = open(os.path.basename(filepath)+"_new",'w') + file_name = targetdir+os.path.basename(filepath) + if os.path.exists(targetdir): + pass + else: + os.mkdir(targetdir) + f = open(file_name,'w') f.close() - request = HTTPRequest(geturl(action,host,filepath,uid,gid,pos), streaming_callback=partial(chunky, file_name)) - http_client = AsyncHTTPClient() + request = HTTPRequest(geturl(action,host,filepath,uid,gid,pos,size), streaming_callback=partial(chunky, file_name)) + AsyncHTTPClient.configure('tornado.simple_httpclient.SimpleAsyncHTTPClient', max_body_size=512*1024*1024) + http_client = AsyncHTTPClient(force_instance=True) + #http_client.configure("tornado.simple_httpclient.SimpleAsyncHTTPClient",max_body_size=524288000) response = yield http_client.fetch(request) tornado.ioloop.IOLoop.instance().stop() print("total bytes downloaded was", total_downloaded) -def entrance(action,host,filepath,uid,gid,pos): - print("entrance function") - writer(action,host,filepath,uid,gid,pos) +def entrance(action,host,filepath,targetdir,uid,gid,pos,size): + #print("entrance function") + writer(action,host,filepath,targetdir,uid,gid,pos,size) tornado.ioloop.IOLoop.instance().start() diff --git a/libclient.so b/libclient.so index 5bcd6d73b65786bfa0794b6f60c74fa39dc32803..a59be23fd56fa0bcefe42f9622d04b82c402e1e7 100755 GIT binary patch delta 2262 zcmZuz4NOy46u$SBVhjC6u&n}p9aO0xB`%0RYh*#<+ZIFpVd^5$5~GqZe-?gPFQW^6Z|9}?SHaOs#s|f zJdPwKh7*2<;B~Bv1i~OqeX##y^)hJ*V;uh$h@Kdev9`|DsbNgT{K%0}eO0`kaQ)00 zEn^aE1&79B3+RYrtUF52sBw3p%=;cZkK3PjPIw+Q3Bv(P1huM?&WLxTeUN|@#$)F<#|!bya?qkd$Z z7l}|4(JlmM2qzP65cnkFX@qwQe2g%SCbUW5&j{ndS;#B!5yCXlp;Ce0C!9*SNZ?Mw zG&v#JFNn8^pcM<51b&mSfiM$z4`CzW@LxzcUm;8@778F%+SEIdP})4zSX3&mh|+RX zX^a?lOI2r;R&~?#*c6XdMFTX0s9zM*&rgR9I)}eP2rk!+RVgj!qt{8(;CYB7tDmDZ zdP?Z65@Xisu#a(*%z^{hZEzc=QgvQ^39I?Nvs=gtjrJx?ix$!|j6zm78x#0BEtbH{ zN^E}&X^a)UR25o_0gUzrn9waseP^&~P{d!Yf>QmQ7nk6I1-;nKDG{#CQ%uCtNkkzL zg_DSUBC?P;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