本文整理汇总了C++中Sock::GetBuf方法的典型用法代码示例。如果您正苦于以下问题:C++ Sock::GetBuf方法的具体用法?C++ Sock::GetBuf怎么用?C++ Sock::GetBuf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sock
的用法示例。
在下文中一共展示了Sock::GetBuf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EvalXTCPRecv
void EvalXTCPRecv(const void *obj, qCtx *ctx, qStr *out, qArgAry *args)
{
Sock *s = (Sock *) obj;
int len;
char *line = NULL;
if (args->Count() > 0) {
len = ParseInt((*args)[0]);
len = s->Read(len);
line = s->GetBuf();
} else {
len = s->ReadLine(&line);
}
if (len > 0)
out->PutS(line, len);
else if (len < 0 ) {
if (len == Sock::ERR_TIMEOUT) {
ctx->ThrowF(out, 702, "Timeout while waiting to read data from host %s:%d, %y", s->GetHost(), s->GetPort());
} else {
ctx->ThrowF(out, 702, "Error while reading data from host %s:%d, %y", s->GetHost(), s->GetPort(), GetLastError());
}
}
}
示例2: EvalWhois
void qObjProto::EvalWhois(qCtx *ctx, qStr *out, qArgAry *args)
{
if (args->Count() < 1) {
ctx->Throw(out, 655, "USAGE: %whois(host[;host;host...][,body[,server[,bindip]]])");
return;
}
CStrAry hosts;
CStr hostStr = (*args)[0];
CStr bodyStr = (*args)[1];
CStr serv = (*args)[2];
CStr bindip = (*args)[3];
ProtoParseHosts(hosts, hostStr);
if (hosts.Count() == 0)
return;
int port;
if(serv.IsEmpty())
serv = DEFAULT_WHOIS_HOST;
port = IPPORT_WHOIS;
int sock_rval, i;
Sock sock;
if(!bindip.IsEmpty())
sock.Bind(bindip);
CStr body, dom, ref, reg, url;
qCtxTmp tmpCtx(ctx);
if (!bodyStr.IsEmpty()) {
tmpCtx.MapObj(&body, "results");
tmpCtx.MapObj(&body, "body");
tmpCtx.MapObj(&dom, "domain");
tmpCtx.MapObj(&ref, "refer");
tmpCtx.MapObj(&dom, "domain-name");
tmpCtx.MapObj(®, "registrar");
tmpCtx.MapObj(&ref, "whois-server");
tmpCtx.MapObj(&url, "referral-url");
}
for (i = 0; i < hosts.Count(); ++i) {
PROTO_OPEN_SOCK();
body = CStr();
ref = CStr();
dom = hosts[i];
sock.Write(hosts[i]<<"\r\n", hosts[i].Length()+2);
do {
if ((sock_rval = sock.Read(SOCK_DEFAULT_BUF_SIZE)) < 0) {
if (sock_rval == Sock::ERR_TIMEOUT)
ctx->ThrowF(out, 705, "Time out while reading from host %s:%d, %y", (const char *) serv, port, GetLastError());
else if (sock_rval)
ctx->ThrowF(out, 706, "Error reading from host %s:%d, %y", (const char *) serv, port, GetLastError());
return;
}
if (!bodyStr.IsEmpty())
body << CStr(sock.GetBuf(), sock_rval);
else
out->PutS(sock.GetBuf(), sock_rval);
}
while( sock_rval > 0); // If something was received
if (!bodyStr.IsEmpty()) {
const char *p;
if ((p = stristr(body.GetBuffer(),"Whois Server:"))) {
p += 14;
while (isspace(*p)) ++p;
char *e = strchr(p, '\n');
ref = CStr(p, e-p);
}
if ((p = stristr(body.GetBuffer(),"Registrar:"))) {
p += 14;
while (isspace(*p)) ++p;
char *e = strchr(p, '\n');
reg = CStr(p, e-p);
}
if ((p = stristr(body.GetBuffer(),"Referral URL:"))) {
p += 14;
while (isspace(*p)) ++p;
char *e = strchr(p, '\n');
url = CStr(p, e-p);
}
tmpCtx.Parse(bodyStr, out);
}
sock.Close();
}
return;
}