123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- #include <QCoreApplication>
- #include <thread>
- #include <chrono>
- #include <iostream>
- #include <QDateTime>
- #include "ivservice.h"
- void ProcReq(std::shared_ptr<char> pstr_req,const int nreqsize,std::shared_ptr<char> & pstr_res,int & nressize)
- {
- pstr_res = std::shared_ptr<char>(new char[100]);
- nressize = 100;
- }
- void ProcAsync(std::shared_ptr<char> & pstr_res,int & ndatasize,int nres)
- {
- if(nres == 0)
- {
- std::cout<<"extend time."<<std::endl;
- }
- if(nres == 1)
- {
- std::cout<<"Aysnc Service return."<<std::endl;
- }
- }
- void threadclientai(int ai)
- {
- iv::service::Client xclient("helloa");
- // std::this_thread::sleep_for(std::chrono::milliseconds(3));
- // std::cout<<"Send Time : "<<QDateTime::currentMSecsSinceEpoch()<<std::endl;
- std::shared_ptr<char> pstr_req = std::shared_ptr<char>(new char[1000000]);
- std::shared_ptr<char> pstr_res;
- int nressize = 0;
- int nsendsize = 100;
- while(nsendsize < 1000000)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(1000));
- nsendsize = nsendsize * 1;
- if(nsendsize >= 1000000)break;
- std::cout<<ai<<" Send Time : "<<QDateTime::currentMSecsSinceEpoch()<<std::endl;
- if(iv::service::Client::HAVE_RES == xclient.SendRequest(pstr_req,nsendsize,pstr_res,nressize))
- {
- std::cout<<ai<<" Res Time: "<<QDateTime::currentMSecsSinceEpoch()<<std::endl;
- std::cout<<ai<<" nres: "<<nressize<<std::endl;
- }
- else
- {
- std::cout<<ai<<" Fail Get Result."<<std::endl;
- }
- break;
- }
- }
- void threadclient()
- {
- iv::service::Client xclient("hellob");
- // std::this_thread::sleep_for(std::chrono::milliseconds(3));
- std::cout<<"Send Time : "<<QDateTime::currentMSecsSinceEpoch()<<std::endl;
- std::shared_ptr<char> pstr_req = std::shared_ptr<char>(new char[1000000]);
- std::shared_ptr<char> pstr_res;
- int nressize = 0;
- if(iv::service::Client::HAVE_RES == xclient.SendRequest(pstr_req,100,pstr_res,nressize))
- {
- std::cout<<"Res Time: "<<QDateTime::currentMSecsSinceEpoch()<<std::endl;
- std::cout<<" nres: "<<nressize<<std::endl;
- }
- else
- {
- std::cout<<" Fail Get Result."<<std::endl;
- }
- return ;
- int nsendsize = 100;
- while(nsendsize < 1000000)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(1000));
- nsendsize = nsendsize * 1;
- if(nsendsize >= 1000000)break;
- std::cout<<"Send Time : "<<QDateTime::currentMSecsSinceEpoch()<<std::endl;
- if(iv::service::Client::HAVE_RES == xclient.SendRequest(pstr_req,nsendsize,pstr_res,nressize))
- {
- std::cout<<"Res Time: "<<QDateTime::currentMSecsSinceEpoch()<<std::endl;
- std::cout<<" nres: "<<nressize<<std::endl;
- }
- else
- {
- std::cout<<" Fail Get Result."<<std::endl;
- }
- }
- }
- int main(int argc, char *argv[])
- {
- QCoreApplication a(argc, argv);
- std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> tp =std::chrono::system_clock::now();
- qint64 xtime1 = std::chrono::system_clock::now().time_since_epoch().count();
- qint64 xtime2 = std::chrono::system_clock::now().time_since_epoch().count();
- qint64 xtd = xtime2 - xtime1;
- // iv::service::Server xserver("helloa",ProcReq);
- // std::this_thread::sleep_for(std::chrono::milliseconds(300));
- // std::thread * pthread_a = new std::thread(threadclientai,1);
- // std::thread * pthread_b = new std::thread(threadclientai,2);
- iv::service::Client xaync("async");
- std::shared_ptr<char> pstr_async = std::shared_ptr<char>(new char[1000]);
- xaync.AsyncSendRequest(pstr_async,100,ProcAsync);
- std::this_thread::sleep_for(std::chrono::milliseconds(10000));
- iv::service::Server xserver("async",ProcReq);
- // std::thread * pthread = new std::thread(threadclient);
- // int i;
- // for(i=0;i<100;i++)
- // {
- // std::this_thread::sleep_for(std::chrono::milliseconds(3000));
- // pthread = new std::thread(threadclient);
- // }
- return a.exec();
- }
|