代码拉取完成,页面将自动刷新
#pragma once
#include <iostream>
#include <string>
#include <sys/types.h>
#include <sys/socket.h>
//工具类
class Util{
public:
static int ReadLine(int sock, std::string &out)
{
char ch = 'X';
while(ch != '\n'){
ssize_t s = recv(sock, &ch, 1, 0);
if(s > 0){
if(ch == '\r'){
recv(sock, &ch, 1, MSG_PEEK);
if(ch == '\n'){
//把\r\n->\n
//窥探成功,这个字符一定存在
recv(sock, &ch, 1, 0);
}
else{
ch = '\n';
}
}
//1. 普通字符
//2. \n
out.push_back(ch);
}
else if(s == 0){
return 0;
}
else{
return -1;
}
}
return out.size();
}
static bool CutString(const std::string &target, std::string &sub1_out, std::string &sub2_out, std::string sep)
{
size_t pos = target.find(sep);
if(pos != std::string::npos){
sub1_out = target.substr(0, pos);
sub2_out = target.substr(pos+sep.size());
return true;
}
return false;
}
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。