当前位置: 首页>>代码示例>>C++>>正文


C++ Sock::Write方法代码示例

本文整理汇总了C++中Sock::Write方法的典型用法代码示例。如果您正苦于以下问题:C++ Sock::Write方法的具体用法?C++ Sock::Write怎么用?C++ Sock::Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sock的用法示例。


在下文中一共展示了Sock::Write方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: EvalXTCPSend

void EvalXTCPSend(const void *obj, qCtx *ctx, qStr *out, qArgAry *args)
{
    Sock *s = (Sock *) obj;
    CStr str = (*args)[0];
    int len = s->Write(str, str.Length());
    if (len < 0 ) {
        if (len == Sock::ERR_TIMEOUT) {
            ctx->ThrowF(out, 702, "Timeout while waiting to write data from host %s:%d, %y", s->GetHost(), s->GetPort());
        } else {
            ctx->ThrowF(out, 702, "Error while writing data from host %s:%d, %y", s->GetHost(), s->GetPort(), GetLastError());
        }
    }
}
开发者ID:BackupTheBerlios,项目名称:smx-svn,代码行数:13,代码来源:proto.cpp

示例2: EvalRWhois

void qObjProto::EvalRWhois(qCtx *ctx, qStr *out, qArgAry *args)
{
    if (args->Count() < 1) {
        ctx->Throw(out, 655, "USAGE: %rwhois(host[;host;host...][,body[,server]])");
        return;
    }

    CStrAry hosts;
    CStr hostStr = (*args)[0];
    CStr bodyStr = (*args)[1];
    CStr serv = (*args)[2];

    ProtoParseHosts(hosts, hostStr);

    if (hosts.Count() == 0)
        return;

    int port;

    if (serv.IsEmpty())
        serv = DEFAULT_RWHOIS_HOST;

    port = IPPORT_RWHOIS;

    int sock_rval, i;
    Sock sock;

    qCtx *tmpCtx = NULL;
    CStr body;

    if (!bodyStr.IsEmpty()) {
        tmpCtx = new qCtxTmp(ctx);
        tmpCtx->MapObj(&body, "results");
    }

    PROTO_OPEN_SOCK();

    sock.Write("-holdconnect on\r\n");

    char *line = NULL;
    bool done;

    PROTO_READ_LINE();
    if (line && (*line != '%')) {
        ctx->ThrowF(out, 709, "RWhoIs not supported at host %s:%d", (const char *) serv, port);
        return;
    }

    PROTO_READ_LINE();
    if (line && stricmp(line,"%ok")) {
        CStr err;
        if (strnicmp(line,"%info",5)) {
            err = line;
        }
        PROTO_READ_LINE();
        while (line && (*line != '%')) {
            err << line;
            err << '\n';
            PROTO_READ_LINE();
        }
        ctx->ThrowF(out, 709, "RWhoIs at %s:%d failed (%s)", (const char *) serv, port, (const char *) err);
        return;
    }

    for (i = 0; i < hosts.Count(); ++i) {
        sock.Write("domain ", 7);
        sock.Write(hosts[i], hosts[i].Length());
        sock.Write("\r\n", 2);
        done = false;
        if (line && !stricmp(line,"%ok")) {
            PROTO_READ_LINE();
            while (line && (*line != '%')) {
                out->PutS(line);
                PROTO_READ_LINE();
                out->PutC('\n');
            }
        }
    }


    sock.Write("-quit\r\n",14);

    return;
}
开发者ID:BackupTheBerlios,项目名称:smx-svn,代码行数:84,代码来源:proto.cpp

示例3: 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(&reg,  "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;
}
开发者ID:BackupTheBerlios,项目名称:smx-svn,代码行数:100,代码来源:proto.cpp

示例4: qsmtp

int qsmtp(qMailOpts *popts)
{

	Sock *pSock = NULL;
	int rval = 0;

	try
	{
		if (popts->timeout == 0.0F)
			popts->timeout = QM_TIMEOUT;
		else if (popts->timeout < QM_TIMEOUT_MIN)
			popts->timeout = QM_TIMEOUT_MIN;

		if (!popts->port)
			popts->port = QM_SMTP_PORT;

		if (!popts->smtp)
			throw qEx(199, "Host was not specified");

		if (!popts->rcpt)
			throw qEx(198, "Must specify recipient.");

		if (!popts->to && !strchr((const char *)popts->rcpt,';'))
			popts->to = popts->rcpt;

		if (!popts->helo) 
			popts->helo = popts->smtp;

		const char *host = popts->smtp; 
		int port = popts->port;

		pSock = new Sock;
		pSock->SetTimeout(popts->timeout);

		int sock_err = pSock->Open(host, port);

		if (sock_err == Sock::ERR_GETHOST)
			throw qEx(QM_ERR_SOCK_GETHOST, QM_ERR_SOCK_GETHOST_RC, host);
		else if (sock_err == Sock::ERR_CONNECT)
			throw qEx(QM_ERR_SOCK_CONNECT, QM_ERR_SOCK_CONNECT_RC, host, port);
		else if (sock_err == Sock::ERR_TIMEOUT)
			throw qEx(QM_ERR_SOCK_CONNECT, QM_ERR_SOCK_CONNECT_RC, host, port);
		else if (sock_err)
			throw qEx(sock_err, "Connect to host %s, error #%d", host, sock_err);


		qMailState state;

		int   multi;
		char *line, *pcur;
		int   errs;
		CStr  request;

		state.opts = popts;
		state.proto = 1;
		state.code = 0;

		pSock->ReadLine(&line);

		do {
			errs = smtp_next(&state, request);
			if (errs > Q_ERRTHRESH) {
				char *p = request.Length() ? strrchr((const char *) request,'\r') : NULL;
				if (p) *p = '\0';
				throw qEx(QM_ERR_SMTP_THRESH, QM_ERR_SMTP_THRESH_RC, errs, (const char *) request);
			}

			if (pSock->Write(request, request.Length()) < 0)
				throw qEx(QM_ERR_SOCK_WRITE_REQ, QM_ERR_SOCK_WRITE_REQ_RC, host);

			if (state.proto != qsBlock && state.proto != qsQuit) {
				do {
					if (pSock->ReadLine(&line) < 0)
						throw qEx(QM_ERR_SOCK_READ_REQ, QM_ERR_SOCK_READ_REQ_RC, host);
					state.code = strtol(line, &pcur, 10);
					multi = (*pcur++ == '-');
					smtp_resp(&state, pcur);
				} while (multi);
			}
		} while (state.proto);
	} catch (CEx pEx) {
		if (pSock) delete pSock;
		pSock = NULL;
		throw pEx;
	} catch (...)	{
		rval = 999;
	}

	if (pSock) delete pSock;
	return rval;
}
开发者ID:BackupTheBerlios,项目名称:smx-svn,代码行数:91,代码来源:qmail.cpp


注:本文中的Sock::Write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。