См. документацию.00001
00002
00003
00004
00005
00006
00007
00008 #include "WriteFiles.h"
00009 #include <errno.h>
00010
00011 WriteFiles::WriteFiles(Protocol &protocol, ServerConfig* sc, BinaryProtocol* bp) {
00012 this->sc = sc;
00013 this->bp = bp;
00014 this->protocol = &protocol;
00015 this->max_readsize=sc->getModuleAttributeInt(L"lib_file_opertion",L"max_read_size",409600);
00016 cout<<"max_readsize"<<max_readsize<<endl;
00017 protocol.addIQHandler(this, WriteFile_xmlns);
00018 }
00019
00020 void WriteFiles::handleTag(TagIQ &tag){
00021
00022 TagIQ::IQType t = tag.getType();
00023
00024 #ifdef debug_output
00025 cout << "STEP1 read" << endl;
00026 #endif
00027 if (t == TagIQ::Set) {
00028
00029 string path;
00030 size_t size;
00031 size_t offset;
00032 fuse_file_info fi;
00033
00034 int fDesc;
00035 struct stat fb;
00036
00037
00038
00039 WriteFile wf(tag);
00040 #ifdef debug_output
00041 cout << "STEP2 read" << endl;
00042 #endif
00043
00044 WriteFile wfResp(NULL, "server", "client", TagIQ::Set, tag.getID());
00045 wf.getFileData(path, offset, size, fi);
00046 #ifdef debug_output
00047 cout << "path:" << path << " offset:" << offset << "size:" << size << endl;
00048 #endif
00049 string dpath = sc->getSharedDir() + path;
00050
00051 fDesc = open(dpath.c_str(), O_RDWR );
00052 if (fDesc == -1) {
00053 cout << "erroropenfile!" << errno << endl;
00054 cout << "filename" << dpath << endl;
00055 }
00056
00057 lseek(fDesc,offset,SEEK_SET);
00058
00059 unsigned int pktID=bp->getNextId();
00060
00061
00062
00063
00064
00065
00066 void* buf1= malloc(size);
00067 if (buf1==NULL){
00068 cout<<"Не могу выделить памяти!!!"<<errno<<endl;
00069 }
00070 bp->setFillBuffer(buf1,size,pktID);
00071
00072 wfResp.setResult(pktID,size);
00073 protocol->sendNode(wfResp);
00074 bp->waiteFillBuffer(pktID);
00075 size_t wres=0;
00076 size_t wbts=0;
00077 char* buf=(char*)buf1;
00078 while (wbts<size){
00079 wres=write(fDesc,buf,size);
00080 if (wres>0){
00081 buf+=wres;
00082 wbts+=wres;
00083 }else{
00084 break;
00085 }
00086 }
00087 close(fDesc);
00088 free(buf1);
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00213 }
00214 #ifdef debug_output
00215 cout << "STEP END read" << endl;
00216 #endif
00217
00218 }
00219
00220 WriteFiles::WriteFiles() {
00221
00222
00223 }
00224
00225 WriteFiles::~WriteFiles() {
00226
00227 this->protocol->removeIQHandler(this);
00228 }