Loading examples/httpclient.cpp +8 −10 Changes for examples/httpclient.cpp: 8 added lines, 10 removed lines. Original line number Diff line number Diff line Loading @@ -78,7 +78,7 @@ int main(int argc, char** argv){ #endif netplus::tcp cltsock(argv[1], atoi(argv[2]), 1, 0); netplus::tcp srvsock; char *data=new char[16384]; netplus::buffer data(16384); try{ srvsock.connect(&cltsock); try{ Loading @@ -98,7 +98,7 @@ int main(int argc, char** argv){ return -1; } size_t recv= srvsock.recvData(&data, 16384,0); size_t recv= srvsock.recvData(data,0); std::vector<char> html; libhttppp::HttpResponse res; Loading @@ -106,7 +106,7 @@ int main(int argc, char** argv){ bool chunked=false; long long rlen=0; hsize=res.parse(data, recv); hsize=res.parse(data.data.buf, recv); try { for(libhttppp::HttpHeader::HeaderData::Values *cval=res.getTransferEncoding(); cval; cval=cval->nextvalue()){ Loading @@ -123,10 +123,10 @@ int main(int argc, char** argv){ if(!chunked){ do{ std::copy(data + cpos, data+recv, std::back_inserter(html)); std::copy(data.data.buf + cpos, data.data.buf+recv, std::back_inserter(html)); rlen-=((long)recv- cpos); if(rlen>0){ recv=(long)srvsock.recvData(&data, 16384,0); recv=(long)srvsock.recvData(data,0); cpos=0; } }while(rlen>0); Loading @@ -137,7 +137,7 @@ int main(int argc, char** argv){ if (recv - cpos > 0) { if (readed == chunklen) { if ((chunklen = readchunk(data, recv, cpos)) == 0) { if ((chunklen = readchunk(data.data.buf, recv, cpos)) == 0) { break; } readed = 0; Loading @@ -145,7 +145,7 @@ int main(int argc, char** argv){ size_t len = (chunklen - readed) < (recv - cpos) ? (chunklen - readed) : (recv - cpos); std::copy(data + cpos, data + (cpos + len), std::back_inserter(html)); std::copy(data.data.buf + cpos, data.data.buf + (cpos + len), std::back_inserter(html)); cpos += len; readed += len; Loading @@ -155,7 +155,7 @@ int main(int argc, char** argv){ for (;;) { cpos = 0; try { recv = srvsock.recvData(&data, 16384,0); recv = srvsock.recvData(data,0); break; } catch (netplus::NetException& e) { Loading @@ -178,11 +178,9 @@ int main(int argc, char** argv){ } std::cout.write(html.data(),html.size())<<std::endl; delete[] data; return 0; }catch(netplus::NetException &exp){ std::cerr << exp.what() <<std::endl; delete[] data; return -1; } } src/http.cpp +24 −25 Changes for src/http.cpp: 24 added lines, 25 removed lines. Original line number Diff line number Diff line Loading @@ -190,7 +190,7 @@ void libhttppp::HttpClient::reconnect(){ } const std::vector<char> &libhttppp::HttpClient::Get(libhttppp::HttpRequest &nreq){ char* data = new char[BLOCKSIZE]; netplus::buffer data (BLOCKSIZE); try{ _ret.clear(); size_t hsize=0; Loading @@ -213,7 +213,7 @@ const std::vector<char> &libhttppp::HttpClient::Get(libhttppp::HttpRequest &nreq try{ for(;;){ try{ recv=_cltsock->recvData(&data,BLOCKSIZE); recv=_cltsock->recvData(data,BLOCKSIZE); break; }catch(netplus::NetException &re){ if(re.getErrorType()!=netplus::NetException::Note){ Loading @@ -229,11 +229,11 @@ const std::vector<char> &libhttppp::HttpClient::Get(libhttppp::HttpRequest &nreq throw he; } hsize=res.parse(data,recv); hsize=res.parse(data.data.buf,recv); recv-=++hsize; std::move(data+hsize,data+BLOCKSIZE,data); std::move(data.data.buf+hsize,data.data.buf+BLOCKSIZE,data.data.buf); cpos=0; Loading @@ -251,13 +251,13 @@ const std::vector<char> &libhttppp::HttpClient::Get(libhttppp::HttpRequest &nreq if(!chunked){ do{ try{ std::copy(data+cpos,data+recv,std::back_inserter(_ret)); std::copy(data.data.buf+cpos,data.data.buf+recv,std::back_inserter(_ret)); rlen-=recv; if(rlen>0){ for(;;){ cpos=0; try{ recv=_cltsock->recvData(&data,BLOCKSIZE); recv=_cltsock->recvData(data); break; }catch(netplus::NetException &e){ if(e.getErrorType()==netplus::NetException::Note){ Loading @@ -283,7 +283,7 @@ const std::vector<char> &libhttppp::HttpClient::Get(libhttppp::HttpRequest &nreq if(recv - cpos > 0){ if(readed==chunklen){ if( (chunklen=readchunk(data,recv,cpos)) == 0 ){ if( (chunklen=readchunk(data.data.buf,recv,cpos)) == 0 ){ break; } readed=0; Loading @@ -291,14 +291,14 @@ const std::vector<char> &libhttppp::HttpClient::Get(libhttppp::HttpRequest &nreq int len = (chunklen - readed) < (recv - cpos) ? (chunklen - readed) : (recv - cpos); std::copy(data+cpos,data+(cpos+len),std::back_inserter(_ret)); std::copy(data.data.buf+cpos,data.data.buf+(cpos+len),std::back_inserter(_ret)); cpos+=len; readed+=len; }else{ cpos=0; for(;;){ try{ recv=_cltsock->recvData(&data,BLOCKSIZE); recv=_cltsock->recvData(data); break; }catch(netplus::NetException &e){ if(e.getErrorType()!=netplus::NetException::Note){ Loading @@ -314,17 +314,15 @@ const std::vector<char> &libhttppp::HttpClient::Get(libhttppp::HttpRequest &nreq }; } }catch(netplus::NetException &e){ delete[] data; libhttppp::HTTPException ee; ee[libhttppp::HTTPException::Error] << e.what(); throw ee; } delete[] data; return _ret; } const std::vector<char> &libhttppp::HttpClient::Post(libhttppp::HttpRequest &nreq,const std::vector<char>& post){ char *data=new char[BLOCKSIZE]; netplus::buffer data(BLOCKSIZE); try{ _ret.clear(); Loading @@ -348,7 +346,8 @@ const std::vector<char> &libhttppp::HttpClient::Post(libhttppp::HttpRequest &nre try { while(sended!=post.size()){ sended+=_cltsock->sendData(post.data() + sended , post.size() - sended, 0); netplus::buffer data(post.data()+sended,post.size()-sended); sended+=_cltsock->sendData(data,0); } }catch(netplus::NetException &e){ throw HTTPException()[HTTPException::Error]<<e.what(); Loading @@ -359,7 +358,7 @@ const std::vector<char> &libhttppp::HttpClient::Post(libhttppp::HttpRequest &nre try{ for(;;){ try{ recv=_cltsock->recvData(&data,BLOCKSIZE); recv=_cltsock->recvData(data,BLOCKSIZE); break; }catch(netplus::NetException &re){ if(re.getErrorType()!=netplus::NetException::Note) Loading @@ -374,11 +373,11 @@ const std::vector<char> &libhttppp::HttpClient::Post(libhttppp::HttpRequest &nre throw he; } hsize=res.parse(data,recv); hsize=res.parse(data.data.buf,recv); recv-=++hsize; std::move(data+hsize,data+BLOCKSIZE,data); std::move(data.data.buf+hsize,data.data.buf+BLOCKSIZE,data.data.buf); cpos=0; Loading @@ -396,13 +395,13 @@ const std::vector<char> &libhttppp::HttpClient::Post(libhttppp::HttpRequest &nre if(!chunked){ do{ try{ std::copy(data+cpos,data+recv,std::back_inserter(_ret)); std::copy(data.data.buf+cpos,data.data.buf+recv,std::back_inserter(_ret)); rlen-=recv; if(rlen>0){ for(;;){ cpos=0; try{ recv=_cltsock->recvData(&data,BLOCKSIZE); recv=_cltsock->recvData(data,BLOCKSIZE); break; }catch(netplus::NetException &e){ if(e.getErrorType()==netplus::NetException::Note){ Loading @@ -428,7 +427,7 @@ const std::vector<char> &libhttppp::HttpClient::Post(libhttppp::HttpRequest &nre if(recv - cpos > 0){ if(readed==chunklen){ if( (chunklen=readchunk(data,recv,cpos)) == 0 ){ if( (chunklen=readchunk(data.data.buf,recv,cpos)) == 0 ){ break; } readed=0; Loading @@ -436,14 +435,14 @@ const std::vector<char> &libhttppp::HttpClient::Post(libhttppp::HttpRequest &nre int len = (chunklen - readed) < (recv - cpos) ? (chunklen - readed) : (recv - cpos); std::copy(data+cpos,data+(cpos+len),std::back_inserter(_ret)); std::copy(data.data.buf+cpos,data.data.buf+(cpos+len),std::back_inserter(_ret)); cpos+=len; readed+=len; }else{ cpos=0; for(;;){ try{ recv=_cltsock->recvData(&data,BLOCKSIZE); recv=_cltsock->recvData(data); break; }catch(netplus::NetException &e){ if(e.getErrorType()!=netplus::NetException::Note){ Loading @@ -461,10 +460,8 @@ const std::vector<char> &libhttppp::HttpClient::Post(libhttppp::HttpRequest &nre }catch(netplus::NetException &e){ libhttppp::HTTPException ee; ee[libhttppp::HTTPException::Error] << e.what(); delete[] data; throw ee; } delete[] data; return _ret; } Loading Loading @@ -1327,10 +1324,12 @@ void libhttppp::HttpRequest::send(std::shared_ptr<netplus::socket> dest){ printHeader(header); try { size_t send=dest->sendData(header.c_str(),header.length()); netplus::buffer data(header.c_str(),header.length()); size_t send=dest->sendData(data); while(send<_Request.length()){ send+=dest->sendData(_Request.substr(send,_Request.length()-send).c_str(), _Request.length()-send); netplus::buffer sendpart(_Request.substr(send,_Request.length()-send).c_str(),_Request.length()-send); send+=dest->sendData(sendpart); } }catch(netplus::NetException &e){ HTTPException excep; Loading Loading
examples/httpclient.cpp +8 −10 Changes for examples/httpclient.cpp: 8 added lines, 10 removed lines. Original line number Diff line number Diff line Loading @@ -78,7 +78,7 @@ int main(int argc, char** argv){ #endif netplus::tcp cltsock(argv[1], atoi(argv[2]), 1, 0); netplus::tcp srvsock; char *data=new char[16384]; netplus::buffer data(16384); try{ srvsock.connect(&cltsock); try{ Loading @@ -98,7 +98,7 @@ int main(int argc, char** argv){ return -1; } size_t recv= srvsock.recvData(&data, 16384,0); size_t recv= srvsock.recvData(data,0); std::vector<char> html; libhttppp::HttpResponse res; Loading @@ -106,7 +106,7 @@ int main(int argc, char** argv){ bool chunked=false; long long rlen=0; hsize=res.parse(data, recv); hsize=res.parse(data.data.buf, recv); try { for(libhttppp::HttpHeader::HeaderData::Values *cval=res.getTransferEncoding(); cval; cval=cval->nextvalue()){ Loading @@ -123,10 +123,10 @@ int main(int argc, char** argv){ if(!chunked){ do{ std::copy(data + cpos, data+recv, std::back_inserter(html)); std::copy(data.data.buf + cpos, data.data.buf+recv, std::back_inserter(html)); rlen-=((long)recv- cpos); if(rlen>0){ recv=(long)srvsock.recvData(&data, 16384,0); recv=(long)srvsock.recvData(data,0); cpos=0; } }while(rlen>0); Loading @@ -137,7 +137,7 @@ int main(int argc, char** argv){ if (recv - cpos > 0) { if (readed == chunklen) { if ((chunklen = readchunk(data, recv, cpos)) == 0) { if ((chunklen = readchunk(data.data.buf, recv, cpos)) == 0) { break; } readed = 0; Loading @@ -145,7 +145,7 @@ int main(int argc, char** argv){ size_t len = (chunklen - readed) < (recv - cpos) ? (chunklen - readed) : (recv - cpos); std::copy(data + cpos, data + (cpos + len), std::back_inserter(html)); std::copy(data.data.buf + cpos, data.data.buf + (cpos + len), std::back_inserter(html)); cpos += len; readed += len; Loading @@ -155,7 +155,7 @@ int main(int argc, char** argv){ for (;;) { cpos = 0; try { recv = srvsock.recvData(&data, 16384,0); recv = srvsock.recvData(data,0); break; } catch (netplus::NetException& e) { Loading @@ -178,11 +178,9 @@ int main(int argc, char** argv){ } std::cout.write(html.data(),html.size())<<std::endl; delete[] data; return 0; }catch(netplus::NetException &exp){ std::cerr << exp.what() <<std::endl; delete[] data; return -1; } }
src/http.cpp +24 −25 Changes for src/http.cpp: 24 added lines, 25 removed lines. Original line number Diff line number Diff line Loading @@ -190,7 +190,7 @@ void libhttppp::HttpClient::reconnect(){ } const std::vector<char> &libhttppp::HttpClient::Get(libhttppp::HttpRequest &nreq){ char* data = new char[BLOCKSIZE]; netplus::buffer data (BLOCKSIZE); try{ _ret.clear(); size_t hsize=0; Loading @@ -213,7 +213,7 @@ const std::vector<char> &libhttppp::HttpClient::Get(libhttppp::HttpRequest &nreq try{ for(;;){ try{ recv=_cltsock->recvData(&data,BLOCKSIZE); recv=_cltsock->recvData(data,BLOCKSIZE); break; }catch(netplus::NetException &re){ if(re.getErrorType()!=netplus::NetException::Note){ Loading @@ -229,11 +229,11 @@ const std::vector<char> &libhttppp::HttpClient::Get(libhttppp::HttpRequest &nreq throw he; } hsize=res.parse(data,recv); hsize=res.parse(data.data.buf,recv); recv-=++hsize; std::move(data+hsize,data+BLOCKSIZE,data); std::move(data.data.buf+hsize,data.data.buf+BLOCKSIZE,data.data.buf); cpos=0; Loading @@ -251,13 +251,13 @@ const std::vector<char> &libhttppp::HttpClient::Get(libhttppp::HttpRequest &nreq if(!chunked){ do{ try{ std::copy(data+cpos,data+recv,std::back_inserter(_ret)); std::copy(data.data.buf+cpos,data.data.buf+recv,std::back_inserter(_ret)); rlen-=recv; if(rlen>0){ for(;;){ cpos=0; try{ recv=_cltsock->recvData(&data,BLOCKSIZE); recv=_cltsock->recvData(data); break; }catch(netplus::NetException &e){ if(e.getErrorType()==netplus::NetException::Note){ Loading @@ -283,7 +283,7 @@ const std::vector<char> &libhttppp::HttpClient::Get(libhttppp::HttpRequest &nreq if(recv - cpos > 0){ if(readed==chunklen){ if( (chunklen=readchunk(data,recv,cpos)) == 0 ){ if( (chunklen=readchunk(data.data.buf,recv,cpos)) == 0 ){ break; } readed=0; Loading @@ -291,14 +291,14 @@ const std::vector<char> &libhttppp::HttpClient::Get(libhttppp::HttpRequest &nreq int len = (chunklen - readed) < (recv - cpos) ? (chunklen - readed) : (recv - cpos); std::copy(data+cpos,data+(cpos+len),std::back_inserter(_ret)); std::copy(data.data.buf+cpos,data.data.buf+(cpos+len),std::back_inserter(_ret)); cpos+=len; readed+=len; }else{ cpos=0; for(;;){ try{ recv=_cltsock->recvData(&data,BLOCKSIZE); recv=_cltsock->recvData(data); break; }catch(netplus::NetException &e){ if(e.getErrorType()!=netplus::NetException::Note){ Loading @@ -314,17 +314,15 @@ const std::vector<char> &libhttppp::HttpClient::Get(libhttppp::HttpRequest &nreq }; } }catch(netplus::NetException &e){ delete[] data; libhttppp::HTTPException ee; ee[libhttppp::HTTPException::Error] << e.what(); throw ee; } delete[] data; return _ret; } const std::vector<char> &libhttppp::HttpClient::Post(libhttppp::HttpRequest &nreq,const std::vector<char>& post){ char *data=new char[BLOCKSIZE]; netplus::buffer data(BLOCKSIZE); try{ _ret.clear(); Loading @@ -348,7 +346,8 @@ const std::vector<char> &libhttppp::HttpClient::Post(libhttppp::HttpRequest &nre try { while(sended!=post.size()){ sended+=_cltsock->sendData(post.data() + sended , post.size() - sended, 0); netplus::buffer data(post.data()+sended,post.size()-sended); sended+=_cltsock->sendData(data,0); } }catch(netplus::NetException &e){ throw HTTPException()[HTTPException::Error]<<e.what(); Loading @@ -359,7 +358,7 @@ const std::vector<char> &libhttppp::HttpClient::Post(libhttppp::HttpRequest &nre try{ for(;;){ try{ recv=_cltsock->recvData(&data,BLOCKSIZE); recv=_cltsock->recvData(data,BLOCKSIZE); break; }catch(netplus::NetException &re){ if(re.getErrorType()!=netplus::NetException::Note) Loading @@ -374,11 +373,11 @@ const std::vector<char> &libhttppp::HttpClient::Post(libhttppp::HttpRequest &nre throw he; } hsize=res.parse(data,recv); hsize=res.parse(data.data.buf,recv); recv-=++hsize; std::move(data+hsize,data+BLOCKSIZE,data); std::move(data.data.buf+hsize,data.data.buf+BLOCKSIZE,data.data.buf); cpos=0; Loading @@ -396,13 +395,13 @@ const std::vector<char> &libhttppp::HttpClient::Post(libhttppp::HttpRequest &nre if(!chunked){ do{ try{ std::copy(data+cpos,data+recv,std::back_inserter(_ret)); std::copy(data.data.buf+cpos,data.data.buf+recv,std::back_inserter(_ret)); rlen-=recv; if(rlen>0){ for(;;){ cpos=0; try{ recv=_cltsock->recvData(&data,BLOCKSIZE); recv=_cltsock->recvData(data,BLOCKSIZE); break; }catch(netplus::NetException &e){ if(e.getErrorType()==netplus::NetException::Note){ Loading @@ -428,7 +427,7 @@ const std::vector<char> &libhttppp::HttpClient::Post(libhttppp::HttpRequest &nre if(recv - cpos > 0){ if(readed==chunklen){ if( (chunklen=readchunk(data,recv,cpos)) == 0 ){ if( (chunklen=readchunk(data.data.buf,recv,cpos)) == 0 ){ break; } readed=0; Loading @@ -436,14 +435,14 @@ const std::vector<char> &libhttppp::HttpClient::Post(libhttppp::HttpRequest &nre int len = (chunklen - readed) < (recv - cpos) ? (chunklen - readed) : (recv - cpos); std::copy(data+cpos,data+(cpos+len),std::back_inserter(_ret)); std::copy(data.data.buf+cpos,data.data.buf+(cpos+len),std::back_inserter(_ret)); cpos+=len; readed+=len; }else{ cpos=0; for(;;){ try{ recv=_cltsock->recvData(&data,BLOCKSIZE); recv=_cltsock->recvData(data); break; }catch(netplus::NetException &e){ if(e.getErrorType()!=netplus::NetException::Note){ Loading @@ -461,10 +460,8 @@ const std::vector<char> &libhttppp::HttpClient::Post(libhttppp::HttpRequest &nre }catch(netplus::NetException &e){ libhttppp::HTTPException ee; ee[libhttppp::HTTPException::Error] << e.what(); delete[] data; throw ee; } delete[] data; return _ret; } Loading Loading @@ -1327,10 +1324,12 @@ void libhttppp::HttpRequest::send(std::shared_ptr<netplus::socket> dest){ printHeader(header); try { size_t send=dest->sendData(header.c_str(),header.length()); netplus::buffer data(header.c_str(),header.length()); size_t send=dest->sendData(data); while(send<_Request.length()){ send+=dest->sendData(_Request.substr(send,_Request.length()-send).c_str(), _Request.length()-send); netplus::buffer sendpart(_Request.substr(send,_Request.length()-send).c_str(),_Request.length()-send); send+=dest->sendData(sendpart); } }catch(netplus::NetException &e){ HTTPException excep; Loading