bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

boost::asio::streambuf基本用法和注意事項(xiàng)

streamsize  sgetn(char_type *store,streamsize n)    返回緩沖區(qū)下n個(gè)字符并存儲(chǔ)到store中,并將緩沖區(qū)位置后移n個(gè)字節(jié)

成都創(chuàng)新互聯(lián)是專業(yè)的湖南網(wǎng)站建設(shè)公司,湖南接單;提供成都網(wǎng)站建設(shè)、成都做網(wǎng)站,網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行湖南網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!

代碼說(shuō)明:本來(lái)是想不斷的通過(guò)sgetn函數(shù)獲取到streambuf的內(nèi)容,由于沒(méi)有完全理解sgetn獲取流的方式,導(dǎo)致了問(wèn)題的產(chǎn)生

int Teststreambuf()

{

boost::asio::streambuf request;

std::ostream request_stream(&request);

request_stream << "GET /cs/restfull/operationRestfullApi/testGet/ HTTP/1.1\r\n";

request_stream << "Accept: application/x-ms-application, p_w_picpath/jpeg, application/xaml+xml, p_w_picpath/gif, p_w_picpath/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\r\n";

request_stream << "Accept-Language: zh-CN\r\n";

request_stream << "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3)\r\n";

request_stream << "Host: " << "192.168.0.88:8080" << "\r\n";

request_stream << "Connection: Keep-Alive\r\n\r\n";

//當(dāng)?shù)谝淮问褂胹getn函數(shù)的時(shí)候,已經(jīng)將所有的數(shù)據(jù)讀完,指向流的結(jié)束位置

char buf[1024] = { 0 };

int len = request.size();

request.sgetn(buf, len);

//當(dāng)?shù)诙问褂胹getn函數(shù)的時(shí)候,由于第一次函數(shù)調(diào)用指向了流的結(jié)束位置,

//所以第二次讀取到的buf1是空的

char buf1[1024] = { 0 };

int len1 = request.size();

request.sgetn(buf1, len1);

return 0;

}

實(shí)際的測(cè)試環(huán)境:希望組裝完成一次HTTP請(qǐng)求之后,循環(huán)發(fā)送構(gòu)建的數(shù)據(jù)包,達(dá)到壓力測(cè)試的結(jié)果,但是在接收端只是接收到一次的數(shù)據(jù),初步懷疑是服務(wù)器的代碼有問(wèn)題,后面才發(fā)現(xiàn)是sgetn函數(shù)的使用方法有問(wèn)題

#include <iostream>

#include <fstream>

#include <string>

#include <boost/asio.hpp>

using namespace std;

using namespace boost::asio;

int Teststreambuf()

{

io_service iosev;

ip::tcp::socket socket(iosev);

ip::tcp::endpoint ep(ip::address_v4::from_string("127.0.0.1"), 7002);

boost::system::error_code ec;

socket.connect(ep, ec);

if (ec) return -1;

boost::asio::streambuf request;

std::ostream request_stream(&request);

request_stream << "POST /cs/restfull/operationRestfullApi/testPost HTTP/1.1\r\n";

request_stream << "Accept: application/x-ms-application, p_w_picpath/jpeg, application/xaml+xml, p_w_picpath/gif, p_w_picpath/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\r\n";

request_stream << "Accept-Language: zh-CN\r\n";

request_stream << "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3)\r\n";

request_stream << "Host: " << "192.168.0.88:8080" << "\r\n";

request_stream << "Connection: Keep-Alive\r\n\r\n";

while (1)

{

//第一次調(diào)用write之后,request的數(shù)據(jù)已經(jīng)發(fā)送完畢,作為一個(gè)流,已經(jīng)指向數(shù)據(jù)的末尾,所以

//當(dāng)再次循環(huán)的時(shí)候發(fā)送的數(shù)據(jù)len==0,本意是循環(huán)發(fā)送上面的HTTP數(shù)據(jù),對(duì)服務(wù)器進(jìn)行壓力測(cè)試

size_t len = boost::asio::write(socket, request);

std::cout << len << std::endl;

::Sleep(300);

}

return 0;

}

修改之后的代碼

#include <iostream>

#include <fstream>

#include <string>

#include <boost/asio.hpp>

using namespace std;

using namespace boost::asio;

int Teststreambuf()

{

io_service iosev;

ip::tcp::socket socket(iosev);

ip::tcp::endpoint ep(ip::address_v4::from_string("127.0.0.1"), 7002);

boost::system::error_code ec;

socket.connect(ep, ec);

if (ec) return -1;

boost::asio::streambuf request;

std::ostream request_stream(&request);

request_stream << "POST /cs/restfull/operationRestfullApi/testPost HTTP/1.1\r\n";

request_stream << "Accept: application/x-ms-application, p_w_picpath/jpeg, application/xaml+xml, p_w_picpath/gif, p_w_picpath/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\r\n";

request_stream << "Accept-Language: zh-CN\r\n";

request_stream << "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3)\r\n";

request_stream << "Host: " << "192.168.0.88:8080" << "\r\n";

request_stream << "Connection: Keep-Alive\r\n\r\n";

//跟上面的不一樣的做法,是將request的數(shù)據(jù)一次性讀取到buf數(shù)組中,然后循環(huán)發(fā)送buf的數(shù)據(jù)內(nèi)容

 char buf[1024] = { 0 };

 request.sgetn(buf, request.size());

while (1)

{

size_t len = boost::asio::write(socket, boost::asio::buffer(buf));

std::cout << len << std::endl;

::Sleep(300);

}

return 0;

}

網(wǎng)頁(yè)題目:boost::asio::streambuf基本用法和注意事項(xiàng)
網(wǎng)頁(yè)鏈接:http://vcdvsql.cn/article6/jhgoig.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站手機(jī)網(wǎng)站建設(shè)網(wǎng)站營(yíng)銷品牌網(wǎng)站制作標(biāo)簽優(yōu)化品牌網(wǎng)站設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營(yíng)