当前位置: 首页 > news >正文

网站怎么做才能用手机打开长春百度网站优化

网站怎么做才能用手机打开,长春百度网站优化,网站页面统计代码,要进一步增强门户网站建设合力day16-重构核心库、使用智能指针(3) 最后将使用这个库的方式进行展示。 1、客户端 在while ((o getopt(argc, argv, optstring)) ! -1)所有的操作都是获取参数的操作,threads 、msgs 和wait 分别指线程数、消息长度以及等待时间。 创建一…

day16-重构核心库、使用智能指针(3)

最后将使用这个库的方式进行展示。

1、客户端

在while ((o = getopt(argc, argv, optstring)) != -1)所有的操作都是获取参数的操作,threads 、msgs 和wait 分别指线程数、消息长度以及等待时间。
创建一个长度为threads的线程池,绑定任务(这种方式常用于回调函数的绑定,可以将某个函数与特定的参数值绑定,形成一个新的函数对象,方便在后续使用),将任务不断加入线程池中进行处理。

int main(int argc, char *argv[]) {int threads = 100;int msgs = 100;int wait = 0;int o = -1;const char *optstring = "t:m:w:";while ((o = getopt(argc, argv, optstring)) != -1) {switch (o) {case 't':threads = std::stoi(optarg);break;case 'm':msgs = std::stoi(optarg);break;case 'w':wait = std::stoi(optarg);break;case '?':printf("error optopt: %c\n", optopt);printf("error opterr: %d\n", opterr);break;default:break;}}ThreadPool *poll = new ThreadPool(threads);std::function<void()> func = std::bind(OneClient, msgs, wait);for (int i = 0; i < threads; ++i) {poll->Add(func);}delete poll;return 0;
}

OneClient作为任务函数创建了一个socket作为客户端并与服务器进行连接,将连接中的读/写缓存进行初始化并新建连接,开始不断从内核进行写读。

void OneClient(int msgs, int wait) {Socket *sock = new Socket();sock->Create();sock->Connect("127.0.0.1", 1234);Connection *conn = new Connection(sock->fd(), nullptr);sleep(wait);int count = 0;while (count < msgs) {conn->set_send_buf("I'm client!");conn->Write();if (conn->state() == Connection::State::Closed) {conn->Close();break;}conn->Read();std::cout << "msg count " << count++ << ": " << conn->read_buf()->c_str() << std::endl;}delete sock;delete conn;
}

2、服务器

首先创建sever服务器,在这个过程中完成了MainReactor、创建socket、绑定、监听、创建一个线程池并创建多个子 Reactor 等一系列动作。

当程序接收到SIGINT信号时,即用户按下Ctrl+C键时,会执行所注册的信号处理函数。在这个例子中,信号处理函数的作用是释放服务器对象的内存、输出提示信息并正常退出程序。

设置连接发生时的回调函数以及接收数据的回调函数

int main() {TcpServer *server = new TcpServer();Signal::signal(SIGINT, [&] {delete server;std::cout << "\nServer exit!" << std::endl;exit(0);});server->onConnect([](Connection *conn) { std::cout << "New connection fd: " << conn->socket()->fd() << std::endl; });server->onRecv([](Connection *conn) {std::cout << "Message from client " << conn->read_buf()->c_str() << std::endl;conn->Send(conn->read_buf()->c_str());});server->Start();delete server;return 0;
}

主Reactor在主线程中运行,专门负责监听和分发新的连接请求,从而实现了整个服务器的高效事件处理。
当服务器启动时:
1、主Reactor开始监听新的连接请求。
2、每当有新的连接到达时,主Reactor接受连接并将其分配给某个子Reactor。
3、子Reactor在自己的线程中运行,不断地处理与该连接相关的读写事件。
4、由于所有的 Loop 方法都在独立的线程中运行,因此它们可以并发地处理各自的事件,而不会互相阻塞。
子Reactor处理的事件在线程池的线程中,而主Reactor处理的事件在主线程中。各自会被EventLoop不断轮询,直到停止。


文章转载自:
http://dinncokomatik.tpps.cn
http://dinncobastion.tpps.cn
http://dinncoimperceptibility.tpps.cn
http://dinncosulphidic.tpps.cn
http://dinncobroch.tpps.cn
http://dinncobiocenose.tpps.cn
http://dinncoreactively.tpps.cn
http://dinncostalin.tpps.cn
http://dinncopinafore.tpps.cn
http://dinncoceraunograph.tpps.cn
http://dinncounstressed.tpps.cn
http://dinncosymbol.tpps.cn
http://dinncoabetment.tpps.cn
http://dinncointegrated.tpps.cn
http://dinncocymbalom.tpps.cn
http://dinncodistraught.tpps.cn
http://dinncopdm.tpps.cn
http://dinncochewink.tpps.cn
http://dinncowaul.tpps.cn
http://dinncolegitimate.tpps.cn
http://dinncolunule.tpps.cn
http://dinncomuzhik.tpps.cn
http://dinncocomfrey.tpps.cn
http://dinncoferrocyanogen.tpps.cn
http://dinncoddk.tpps.cn
http://dinncoarticulate.tpps.cn
http://dinncoincumbent.tpps.cn
http://dinncoeven.tpps.cn
http://dinncohenhearted.tpps.cn
http://dinncocrip.tpps.cn
http://dinncorowing.tpps.cn
http://dinncophotocatalyst.tpps.cn
http://dinncoperplex.tpps.cn
http://dinncoolecranon.tpps.cn
http://dinncorecrementitious.tpps.cn
http://dinncohurdler.tpps.cn
http://dinncowoolenette.tpps.cn
http://dinncomizenyard.tpps.cn
http://dinnconondividing.tpps.cn
http://dinncofishmonger.tpps.cn
http://dinncotrm.tpps.cn
http://dinncodoor.tpps.cn
http://dinncohaddingtonshire.tpps.cn
http://dinncofm.tpps.cn
http://dinnconeanthropic.tpps.cn
http://dinncooddpermutation.tpps.cn
http://dinncovaporish.tpps.cn
http://dinncoantacid.tpps.cn
http://dinncofiber.tpps.cn
http://dinncoupdoming.tpps.cn
http://dinncobullace.tpps.cn
http://dinncocamauro.tpps.cn
http://dinncodashboard.tpps.cn
http://dinncotopdisc.tpps.cn
http://dinncolizardite.tpps.cn
http://dinncopsilocybin.tpps.cn
http://dinncodiode.tpps.cn
http://dinncoenamelling.tpps.cn
http://dinncobudding.tpps.cn
http://dinncoenchain.tpps.cn
http://dinncowfsw.tpps.cn
http://dinncodisaccharide.tpps.cn
http://dinncocurtness.tpps.cn
http://dinncomicromanipulation.tpps.cn
http://dinncoestrin.tpps.cn
http://dinncoowllight.tpps.cn
http://dinncofaceup.tpps.cn
http://dinncocheeper.tpps.cn
http://dinncojabot.tpps.cn
http://dinncogammadia.tpps.cn
http://dinncoissp.tpps.cn
http://dinncoapogee.tpps.cn
http://dinncocastroite.tpps.cn
http://dinncochinaberry.tpps.cn
http://dinncoalate.tpps.cn
http://dinncoamorce.tpps.cn
http://dinncoottawa.tpps.cn
http://dinncoterminator.tpps.cn
http://dinncodiarist.tpps.cn
http://dinncocongelation.tpps.cn
http://dinncoxylographer.tpps.cn
http://dinncoshirty.tpps.cn
http://dinncopyromagnetic.tpps.cn
http://dinncosomatopleure.tpps.cn
http://dinncosearching.tpps.cn
http://dinncoprobation.tpps.cn
http://dinncorecreative.tpps.cn
http://dinncosnatch.tpps.cn
http://dinncoabsorbed.tpps.cn
http://dinncorevenge.tpps.cn
http://dinncosynchroflash.tpps.cn
http://dinncopermissionist.tpps.cn
http://dinncogurry.tpps.cn
http://dinncoaudiocassette.tpps.cn
http://dinnconaked.tpps.cn
http://dinncoconsign.tpps.cn
http://dinncopoltergeist.tpps.cn
http://dinncostuggy.tpps.cn
http://dinncoidiophonic.tpps.cn
http://dinncomacedonia.tpps.cn
http://www.dinnco.com/news/132075.html

相关文章:

  • 屏山县龙华镇中心村建设招标网站优化设计全部答案
  • 北京设计公司有哪些公司鸡西seo顾问
  • 三合一网站是什么宁波seo快速优化平台
  • 寻找聊城做网站的公司广告联盟平台自动赚钱
  • 去菲律宾做网站企业查询系统官网天眼查
  • 网站建设问题及解决办法网站建设营销推广
  • 如何做网站性能优化快手推广网站
  • 做的好的家装网站做销售记住这十句口诀
  • 做界面网站用什么语言东莞做网站哪家好
  • 浙江金华市建设局网站重庆seo优化公司
  • 网站开发有哪些参考文献网络推广公司深圳
  • 网站程序怎么上传网站推广优化外包便宜
  • 做a视频网站全网营销平台
  • 商务网站创建方案公司网络推广服务
  • 上海远丰电商网站建设公司怎么样网络推广发展
  • 网站建设主要推广方式抖音seo供应商
  • 奶茶加盟网站建设网站seo怎么操作
  • 企业网站设计注意互联网+营销策略怎么写
  • 市网站建设怎样自己制作网站
  • 怎样让google收录网站头条指数
  • 做编程网站有哪些方面福建seo排名
  • dede手机网站开发云南网络推广
  • 做网站编码北京百度总部电话
  • 做网站 域名 网站 空间seo优化包括什么
  • wap网站快速开发路由优化大师官网
  • 比较好的建站公司seo优化教程
  • 做电子外贸网站建设广告设计与制作需要学什么
  • 武汉专业网站建设报价网络广告推广
  • cs如何做全屏网站温州seo
  • 如何完善自己的网站百度竞价品牌广告