• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ CTXMALLOC函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中CTXMALLOC函数的典型用法代码示例。如果您正苦于以下问题:C++ CTXMALLOC函数的具体用法?C++ CTXMALLOC怎么用?C++ CTXMALLOC使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: lwres_gnbarequest_render

/*% Uses resolver context ctx to convert getnamebyaddr request structure req to canonical format. */
lwres_result_t
lwres_gnbarequest_render (lwres_context_t * ctx, lwres_gnbarequest_t * req, lwres_lwpacket_t * pkt, lwres_buffer_t * b)
{
    unsigned char *buf;

    size_t buflen;

    int ret;

    size_t payload_length;

    REQUIRE (ctx != NULL);
    REQUIRE (req != NULL);
    REQUIRE (req->addr.family != 0);
    REQUIRE (req->addr.length != 0);
    REQUIRE (pkt != NULL);
    REQUIRE (b != NULL);

    payload_length = 4 + 4 + 2 + +req->addr.length;

    buflen = LWRES_LWPACKET_LENGTH + payload_length;
    buf = CTXMALLOC (buflen);
    if (buf == NULL)
        return (LWRES_R_NOMEMORY);
    lwres_buffer_init (b, buf, buflen);

    pkt->length = buflen;
    pkt->version = LWRES_LWPACKETVERSION_0;
    pkt->pktflags &= ~LWRES_LWPACKETFLAG_RESPONSE;
    pkt->opcode = LWRES_OPCODE_GETNAMEBYADDR;
    pkt->result = 0;
    pkt->authtype = 0;
    pkt->authlength = 0;

    ret = lwres_lwpacket_renderheader (b, pkt);
    if (ret != LWRES_R_SUCCESS)
    {
        lwres_buffer_invalidate (b);
        CTXFREE (buf, buflen);
        return (ret);
    }

    INSIST (SPACE_OK (b, payload_length));

    /*
     * Put the length and the data.  We know this will fit because we
     * just checked for it.
     */
    lwres_buffer_putuint32 (b, req->flags);
    lwres_buffer_putuint32 (b, req->addr.family);
    lwres_buffer_putuint16 (b, req->addr.length);
    lwres_buffer_putmem (b, (unsigned char *) req->addr.address, req->addr.length);

    INSIST (LWRES_BUFFER_AVAILABLECOUNT (b) == 0);

    return (LWRES_R_SUCCESS);
}
开发者ID:274914765,项目名称:C,代码行数:58,代码来源:lwres_gnba.c


示例2: lwres_noopresponse_render

lwres_result_t
lwres_noopresponse_render(lwres_context_t *ctx, lwres_noopresponse_t *req,
			  lwres_lwpacket_t *pkt, lwres_buffer_t *b)
{
	unsigned char *buf;
	size_t buflen;
	int ret;
	size_t payload_length;

	REQUIRE(ctx != NULL);
	REQUIRE(req != NULL);
	REQUIRE(pkt != NULL);
	REQUIRE(b != NULL);

	payload_length = sizeof(lwres_uint16_t) + req->datalength;

	buflen = LWRES_LWPACKET_LENGTH + payload_length;
	buf = CTXMALLOC(buflen);
	if (buf == NULL)
		return (LWRES_R_NOMEMORY);
	lwres_buffer_init(b, buf, (unsigned int)buflen);

	pkt->length = (lwres_uint32_t)buflen;
	pkt->version = LWRES_LWPACKETVERSION_0;
	pkt->pktflags |= LWRES_LWPACKETFLAG_RESPONSE;
	pkt->opcode = LWRES_OPCODE_NOOP;
	pkt->authtype = 0;
	pkt->authlength = 0;

	ret = lwres_lwpacket_renderheader(b, pkt);
	if (ret != LWRES_R_SUCCESS) {
		lwres_buffer_invalidate(b);
		CTXFREE(buf, buflen);
		return (ret);
	}

	INSIST(SPACE_OK(b, payload_length));

	/*
	 * Put the length and the data.  We know this will fit because we
	 * just checked for it.
	 */
	lwres_buffer_putuint16(b, req->datalength);
	lwres_buffer_putmem(b, req->data, req->datalength);

	INSIST(LWRES_BUFFER_AVAILABLECOUNT(b) == 0);

	return (LWRES_R_SUCCESS);
}
开发者ID:Stichting-MINIX-Research-Foundation,项目名称:minix,代码行数:49,代码来源:lwres_noop.c


示例3: lwres_noopresponse_parse

/*% Offers the same semantics as lwres_nooprequest_parse() except it yields a lwres_noopresponse_t structure. */
lwres_result_t
lwres_noopresponse_parse(lwres_context_t *ctx, lwres_buffer_t *b,
			 lwres_lwpacket_t *pkt, lwres_noopresponse_t **structp)
{
	int ret;
	lwres_noopresponse_t *req;

	REQUIRE(ctx != NULL);
	REQUIRE(b != NULL);
	REQUIRE(pkt != NULL);
	REQUIRE(structp != NULL && *structp == NULL);

	if ((pkt->pktflags & LWRES_LWPACKETFLAG_RESPONSE) == 0)
		return (LWRES_R_FAILURE);

	req = CTXMALLOC(sizeof(lwres_noopresponse_t));
	if (req == NULL)
		return (LWRES_R_NOMEMORY);

	if (!SPACE_REMAINING(b, sizeof(lwres_uint16_t))) {
		ret = LWRES_R_UNEXPECTEDEND;
		goto out;
	}
	req->datalength = lwres_buffer_getuint16(b);

	if (!SPACE_REMAINING(b, req->datalength)) {
		ret = LWRES_R_UNEXPECTEDEND;
		goto out;
	}
	req->data = b->base + b->current;

	lwres_buffer_forward(b, req->datalength);
	if (LWRES_BUFFER_REMAINING(b) != 0) {
		ret = LWRES_R_TRAILINGDATA;
		goto out;
	}

	/* success! */
	*structp = req;
	return (LWRES_R_SUCCESS);

	/* Error return */
 out:
	CTXFREE(req, sizeof(lwres_noopresponse_t));
	return (ret);
}
开发者ID:Stichting-MINIX-Research-Foundation,项目名称:minix,代码行数:47,代码来源:lwres_noop.c


示例4: lwres_gnbarequest_parse

/*% Uses context ctx to convert the contents of packet pkt to a lwres_gnbarequest_t structure. */
lwres_result_t
lwres_gnbarequest_parse (lwres_context_t * ctx, lwres_buffer_t * b,
                         lwres_lwpacket_t * pkt, lwres_gnbarequest_t ** structp)
{
    int ret;

    lwres_gnbarequest_t *gnba;

    REQUIRE (ctx != NULL);
    REQUIRE (pkt != NULL);
    REQUIRE (b != NULL);
    REQUIRE (structp != NULL && *structp == NULL);

    if ((pkt->pktflags & LWRES_LWPACKETFLAG_RESPONSE) != 0)
        return (LWRES_R_FAILURE);

    if (!SPACE_REMAINING (b, 4))
        return (LWRES_R_UNEXPECTEDEND);

    gnba = CTXMALLOC (sizeof (lwres_gnbarequest_t));
    if (gnba == NULL)
        return (LWRES_R_NOMEMORY);

    gnba->flags = lwres_buffer_getuint32 (b);

    ret = lwres_addr_parse (b, &gnba->addr);
    if (ret != LWRES_R_SUCCESS)
        goto out;

    if (LWRES_BUFFER_REMAINING (b) != 0)
    {
        ret = LWRES_R_TRAILINGDATA;
        goto out;
    }

    *structp = gnba;
    return (LWRES_R_SUCCESS);

  out:
    if (gnba != NULL)
        lwres_gnbarequest_free (ctx, &gnba);

    return (ret);
}
开发者ID:274914765,项目名称:C,代码行数:45,代码来源:lwres_gnba.c


示例5: tlDateToString

TIMELIB_API void TIMELIB_CALL tlDateToString(size32_t &__lenResult, char* &__result, unsigned int date, const char* format)
{
    struct tm       timeInfo;
    const size_t    kBufferSize = 256;
    char            buffer[kBufferSize];

    memset(&timeInfo, 0, sizeof(timeInfo));
    tlInsertDateIntoTimeStruct(&timeInfo, date);
    tlMKTime(&timeInfo);

    __lenResult = strftime(buffer, kBufferSize, format, &timeInfo);
    __result = NULL;

    if (__lenResult > 0)
    {
        __result = reinterpret_cast<char*>(CTXMALLOC(parentCtx, __lenResult));
        memcpy(__result, buffer, __lenResult);
    }
}
开发者ID:Josh-Googler,项目名称:HPCC-Platform,代码行数:19,代码来源:timelib.cpp


示例6: lwres_getnamebyaddr

/*% Used to perform reverse lookups. */
lwres_result_t
lwres_getnamebyaddr(lwres_context_t *ctx, lwres_uint32_t addrtype,
		    lwres_uint16_t addrlen, const unsigned char *addr,
		    lwres_gnbaresponse_t **structp)
{
	lwres_gnbarequest_t request;
	lwres_gnbaresponse_t *response;
	int ret;
	int recvlen;
	lwres_buffer_t b_in, b_out;
	lwres_lwpacket_t pkt;
	lwres_uint32_t serial;
	char *buffer;

	REQUIRE(ctx != NULL);
	REQUIRE(addrtype != 0);
	REQUIRE(addrlen != 0);
	REQUIRE(addr != NULL);
	REQUIRE(structp != NULL && *structp == NULL);

	b_in.base = NULL;
	b_out.base = NULL;
	response = NULL;
	buffer = NULL;
	serial = lwres_context_nextserial(ctx);

	buffer = CTXMALLOC(LWRES_RECVLENGTH);
	if (buffer == NULL) {
		ret = LWRES_R_NOMEMORY;
		goto out;
	}

	/*
	 * Set up our request and render it to a buffer.
	 */
	request.flags = 0;
	request.addr.family = addrtype;
	request.addr.length = addrlen;
	memmove(request.addr.address, addr, addrlen);
	pkt.pktflags = 0;
	pkt.serial = serial;
	pkt.result = 0;
	pkt.recvlength = LWRES_RECVLENGTH;

 again:
	ret = lwres_gnbarequest_render(ctx, &request, &pkt, &b_out);
	if (ret != LWRES_R_SUCCESS)
		goto out;

	ret = lwres_context_sendrecv(ctx, b_out.base, b_out.length, buffer,
				     LWRES_RECVLENGTH, &recvlen);
	if (ret != LWRES_R_SUCCESS)
		goto out;

	lwres_buffer_init(&b_in, buffer, recvlen);
	b_in.used = recvlen;

	/*
	 * Parse the packet header.
	 */
	ret = lwres_lwpacket_parseheader(&b_in, &pkt);
	if (ret != LWRES_R_SUCCESS)
		goto out;

	/*
	 * Sanity check.
	 */
	if (pkt.serial != serial)
		goto again;
	if (pkt.opcode != LWRES_OPCODE_GETNAMEBYADDR)
		goto again;

	/*
	 * Free what we've transmitted
	 */
	CTXFREE(b_out.base, b_out.length);
	b_out.base = NULL;
	b_out.length = 0;

	if (pkt.result != LWRES_R_SUCCESS) {
		ret = pkt.result;
		goto out;
	}

	/*
	 * Parse the response.
	 */
	ret = lwres_gnbaresponse_parse(ctx, &b_in, &pkt, &response);
	if (ret != LWRES_R_SUCCESS)
		goto out;
	response->base = buffer;
	response->baselen = LWRES_RECVLENGTH;
	buffer = NULL; /* don't free this below */

	*structp = response;
	return (LWRES_R_SUCCESS);

 out:
	if (b_out.base != NULL)
//.........这里部分代码省略.........
开发者ID:crossbuild,项目名称:bind,代码行数:101,代码来源:lwresutil.c


示例7: lwres_gabnresponse_render

/*% converts a getaddrbyname response structure lwres_gabnresponse_t to the lightweight resolver's canonical format. */
lwres_result_t
lwres_gabnresponse_render(lwres_context_t *ctx, lwres_gabnresponse_t *req,
			  lwres_lwpacket_t *pkt, lwres_buffer_t *b)
{
	unsigned char *buf;
	size_t buflen;
	int ret;
	size_t payload_length;
	lwres_uint16_t datalen;
	lwres_addr_t *addr;
	int x;

	REQUIRE(ctx != NULL);
	REQUIRE(req != NULL);
	REQUIRE(pkt != NULL);
	REQUIRE(b != NULL);

	/* naliases, naddrs */
	payload_length = 4 + 2 + 2;
	/* real name encoding */
	payload_length += 2 + req->realnamelen + 1;
	/* each alias */
	for (x = 0; x < req->naliases; x++)
		payload_length += 2 + req->aliaslen[x] + 1;
	/* each address */
	x = 0;
	addr = LWRES_LIST_HEAD(req->addrs);
	while (addr != NULL) {
		payload_length += 4 + 2;
		payload_length += addr->length;
		addr = LWRES_LIST_NEXT(addr, link);
		x++;
	}
	INSIST(x == req->naddrs);

	buflen = LWRES_LWPACKET_LENGTH + payload_length;
	buf = CTXMALLOC(buflen);
	if (buf == NULL)
		return (LWRES_R_NOMEMORY);
	lwres_buffer_init(b, buf, (unsigned int)buflen);

	pkt->length = (lwres_uint32_t)buflen;
	pkt->version = LWRES_LWPACKETVERSION_0;
	pkt->pktflags |= LWRES_LWPACKETFLAG_RESPONSE;
	pkt->opcode = LWRES_OPCODE_GETADDRSBYNAME;
	pkt->authtype = 0;
	pkt->authlength = 0;

	ret = lwres_lwpacket_renderheader(b, pkt);
	if (ret != LWRES_R_SUCCESS) {
		lwres_buffer_invalidate(b);
		CTXFREE(buf, buflen);
		return (ret);
	}

	/*
	 * Check space needed here.
	 */
	INSIST(SPACE_OK(b, payload_length));

	/* Flags. */
	lwres_buffer_putuint32(b, req->flags);

	/* encode naliases and naddrs */
	lwres_buffer_putuint16(b, req->naliases);
	lwres_buffer_putuint16(b, req->naddrs);

	/* encode the real name */
	datalen = req->realnamelen;
	lwres_buffer_putuint16(b, datalen);
	lwres_buffer_putmem(b, (unsigned char *)req->realname, datalen);
	lwres_buffer_putuint8(b, 0);

	/* encode the aliases */
	for (x = 0; x < req->naliases; x++) {
		datalen = req->aliaslen[x];
		lwres_buffer_putuint16(b, datalen);
		lwres_buffer_putmem(b, (unsigned char *)req->aliases[x],
				    datalen);
		lwres_buffer_putuint8(b, 0);
	}

	/* encode the addresses */
	addr = LWRES_LIST_HEAD(req->addrs);
	while (addr != NULL) {
		lwres_buffer_putuint32(b, addr->family);
		lwres_buffer_putuint16(b, addr->length);
		lwres_buffer_putmem(b, addr->address, addr->length);
		addr = LWRES_LIST_NEXT(addr, link);
	}

	INSIST(LWRES_BUFFER_AVAILABLECOUNT(b) == 0);
	INSIST(LWRES_BUFFER_USEDCOUNT(b) == pkt->length);

	return (LWRES_R_SUCCESS);
}
开发者ID:crossbuild,项目名称:bind,代码行数:97,代码来源:lwres_gabn.c


示例8: lwres_gnbaresponse_parse

lwres_result_t
lwres_gnbaresponse_parse (lwres_context_t * ctx, lwres_buffer_t * b,
                          lwres_lwpacket_t * pkt, lwres_gnbaresponse_t ** structp)
{
    int ret;

    unsigned int x;

    lwres_uint32_t flags;

    lwres_uint16_t naliases;

    lwres_gnbaresponse_t *gnba;

    REQUIRE (ctx != NULL);
    REQUIRE (pkt != NULL);
    REQUIRE (b != NULL);
    REQUIRE (structp != NULL && *structp == NULL);

    gnba = NULL;

    if ((pkt->pktflags & LWRES_LWPACKETFLAG_RESPONSE) == 0)
        return (LWRES_R_FAILURE);

    /*
     * Pull off flags & naliases
     */
    if (!SPACE_REMAINING (b, 4 + 2))
        return (LWRES_R_UNEXPECTEDEND);
    flags = lwres_buffer_getuint32 (b);
    naliases = lwres_buffer_getuint16 (b);

    gnba = CTXMALLOC (sizeof (lwres_gnbaresponse_t));
    if (gnba == NULL)
        return (LWRES_R_NOMEMORY);
    gnba->base = NULL;
    gnba->aliases = NULL;
    gnba->aliaslen = NULL;

    gnba->flags = flags;
    gnba->naliases = naliases;

    if (naliases > 0)
    {
        gnba->aliases = CTXMALLOC (sizeof (char *) * naliases);
        if (gnba->aliases == NULL)
        {
            ret = LWRES_R_NOMEMORY;
            goto out;
        }

        gnba->aliaslen = CTXMALLOC (sizeof (lwres_uint16_t) * naliases);
        if (gnba->aliaslen == NULL)
        {
            ret = LWRES_R_NOMEMORY;
            goto out;
        }
    }

    /*
     * Now, pull off the real name.
     */
    ret = lwres_string_parse (b, &gnba->realname, &gnba->realnamelen);
    if (ret != LWRES_R_SUCCESS)
        goto out;

    /*
     * Parse off the aliases.
     */
    for (x = 0; x < gnba->naliases; x++)
    {
        ret = lwres_string_parse (b, &gnba->aliases[x], &gnba->aliaslen[x]);
        if (ret != LWRES_R_SUCCESS)
            goto out;
    }

    if (LWRES_BUFFER_REMAINING (b) != 0)
    {
        ret = LWRES_R_TRAILINGDATA;
        goto out;
    }

    *structp = gnba;
    return (LWRES_R_SUCCESS);

  out:
    if (gnba != NULL)
    {
        if (gnba->aliases != NULL)
            CTXFREE (gnba->aliases, sizeof (char *) * naliases);
        if (gnba->aliaslen != NULL)
            CTXFREE (gnba->aliaslen, sizeof (lwres_uint16_t) * naliases);
        CTXFREE (gnba, sizeof (lwres_gnbaresponse_t));
    }

    return (ret);
}
开发者ID:274914765,项目名称:C,代码行数:97,代码来源:lwres_gnba.c


示例9: lwres_gnbaresponse_render

/*% Converts a getnamebyaddr response structure lwres_gnbaresponse_t to the lightweight resolver's canonical format. */
lwres_result_t
lwres_gnbaresponse_render (lwres_context_t * ctx, lwres_gnbaresponse_t * req,
                           lwres_lwpacket_t * pkt, lwres_buffer_t * b)
{
    unsigned char *buf;

    size_t buflen;

    int ret;

    size_t payload_length;

    lwres_uint16_t datalen;

    int x;

    REQUIRE (ctx != NULL);
    REQUIRE (req != NULL);
    REQUIRE (pkt != NULL);
    REQUIRE (b != NULL);

    /*
     * Calculate packet size.
     */
    payload_length = 4;            /* flags */
    payload_length += 2;        /* naliases */
    payload_length += 2 + req->realnamelen + 1;    /* real name encoding */
    for (x = 0; x < req->naliases; x++)    /* each alias */
        payload_length += 2 + req->aliaslen[x] + 1;

    buflen = LWRES_LWPACKET_LENGTH + payload_length;
    buf = CTXMALLOC (buflen);
    if (buf == NULL)
        return (LWRES_R_NOMEMORY);
    lwres_buffer_init (b, buf, buflen);

    pkt->length = buflen;
    pkt->version = LWRES_LWPACKETVERSION_0;
    pkt->pktflags |= LWRES_LWPACKETFLAG_RESPONSE;
    pkt->opcode = LWRES_OPCODE_GETNAMEBYADDR;
    pkt->authtype = 0;
    pkt->authlength = 0;

    ret = lwres_lwpacket_renderheader (b, pkt);
    if (ret != LWRES_R_SUCCESS)
    {
        lwres_buffer_invalidate (b);
        CTXFREE (buf, buflen);
        return (ret);
    }

    INSIST (SPACE_OK (b, payload_length));
    lwres_buffer_putuint32 (b, req->flags);

    /* encode naliases */
    lwres_buffer_putuint16 (b, req->naliases);

    /* encode the real name */
    datalen = req->realnamelen;
    lwres_buffer_putuint16 (b, datalen);
    lwres_buffer_putmem (b, (unsigned char *) req->realname, datalen);
    lwres_buffer_putuint8 (b, 0);

    /* encode the aliases */
    for (x = 0; x < req->naliases; x++)
    {
        datalen = req->aliaslen[x];
        lwres_buffer_putuint16 (b, datalen);
        lwres_buffer_putmem (b, (unsigned char *) req->aliases[x], datalen);
        lwres_buffer_putuint8 (b, 0);
    }

    INSIST (LWRES_BUFFER_AVAILABLECOUNT (b) == 0);

    return (LWRES_R_SUCCESS);
}
开发者ID:274914765,项目名称:C,代码行数:77,代码来源:lwres_gnba.c


示例10: lwres_gabnresponse_parse

lwres_result_t
lwres_gabnresponse_parse(lwres_context_t *ctx, lwres_buffer_t *b,
			lwres_lwpacket_t *pkt, lwres_gabnresponse_t **structp)
{
	lwres_result_t ret;
	unsigned int x;
	lwres_uint32_t flags;
	lwres_uint16_t naliases;
	lwres_uint16_t naddrs;
	lwres_gabnresponse_t *gabn;
	lwres_addrlist_t addrlist;
	lwres_addr_t *addr;

	REQUIRE(ctx != NULL);
	REQUIRE(pkt != NULL);
	REQUIRE(b != NULL);
	REQUIRE(structp != NULL && *structp == NULL);

	gabn = NULL;

	if ((pkt->pktflags & LWRES_LWPACKETFLAG_RESPONSE) == 0)
		return (LWRES_R_FAILURE);

	/*
	 * Pull off the name itself
	 */
	if (!SPACE_REMAINING(b, 4 + 2 + 2))
		return (LWRES_R_UNEXPECTEDEND);
	flags = lwres_buffer_getuint32(b);
	naliases = lwres_buffer_getuint16(b);
	naddrs = lwres_buffer_getuint16(b);

	gabn = CTXMALLOC(sizeof(lwres_gabnresponse_t));
	if (gabn == NULL)
		return (LWRES_R_NOMEMORY);
	gabn->aliases = NULL;
	gabn->aliaslen = NULL;
	LWRES_LIST_INIT(gabn->addrs);
	gabn->base = NULL;

	gabn->flags = flags;
	gabn->naliases = naliases;
	gabn->naddrs = naddrs;

	LWRES_LIST_INIT(addrlist);

	if (naliases > 0) {
		gabn->aliases = CTXMALLOC(sizeof(char *) * naliases);
		if (gabn->aliases == NULL) {
			ret = LWRES_R_NOMEMORY;
			goto out;
		}

		gabn->aliaslen = CTXMALLOC(sizeof(lwres_uint16_t) * naliases);
		if (gabn->aliaslen == NULL) {
			ret = LWRES_R_NOMEMORY;
			goto out;
		}
	}

	for (x = 0; x < naddrs; x++) {
		addr = CTXMALLOC(sizeof(lwres_addr_t));
		if (addr == NULL) {
			ret = LWRES_R_NOMEMORY;
			goto out;
		}
		LWRES_LINK_INIT(addr, link);
		LWRES_LIST_APPEND(addrlist, addr, link);
	}

	/*
	 * Now, pull off the real name.
	 */
	ret = lwres_string_parse(b, &gabn->realname, &gabn->realnamelen);
	if (ret != LWRES_R_SUCCESS)
		goto out;

	/*
	 * Parse off the aliases.
	 */
	for (x = 0; x < gabn->naliases; x++) {
		ret = lwres_string_parse(b, &gabn->aliases[x],
					 &gabn->aliaslen[x]);
		if (ret != LWRES_R_SUCCESS)
			goto out;
	}

	/*
	 * Pull off the addresses.  We already strung the linked list
	 * up above.
	 */
	addr = LWRES_LIST_HEAD(addrlist);
	for (x = 0; x < gabn->naddrs; x++) {
		INSIST(addr != NULL);
		ret = lwres_addr_parse(b, addr);
		if (ret != LWRES_R_SUCCESS)
			goto out;
		addr = LWRES_LIST_NEXT(addr, link);
	}

//.........这里部分代码省略.........
开发者ID:crossbuild,项目名称:bind,代码行数:101,代码来源:lwres_gabn.c


示例11: lwres_getrdatabyname

/*% Get rdata by name. */
lwres_result_t
lwres_getrdatabyname(lwres_context_t *ctx, const char *name,
		     lwres_uint16_t rdclass, lwres_uint16_t rdtype,
		     lwres_uint32_t flags, lwres_grbnresponse_t **structp)
{
	int ret;
	int recvlen;
	lwres_buffer_t b_in, b_out;
	lwres_lwpacket_t pkt;
	lwres_uint32_t serial;
	char *buffer;
	lwres_grbnrequest_t request;
	lwres_grbnresponse_t *response;
	char target_name[1024];
	unsigned int target_length;

	REQUIRE(ctx != NULL);
	REQUIRE(name != NULL);
	REQUIRE(structp != NULL && *structp == NULL);

	b_in.base = NULL;
	b_out.base = NULL;
	response = NULL;
	buffer = NULL;
	serial = lwres_context_nextserial(ctx);

	buffer = CTXMALLOC(LWRES_RECVLENGTH);
	if (buffer == NULL) {
		ret = LWRES_R_NOMEMORY;
		goto out;
	}

	target_length = strlen(name);
	if (target_length >= sizeof(target_name))
		return (LWRES_R_FAILURE);
	strcpy(target_name, name); /* strcpy is safe */

	/*
	 * Set up our request and render it to a buffer.
	 */
	request.rdclass = rdclass;
	request.rdtype = rdtype;
	request.flags = flags;
	request.name = target_name;
	request.namelen = target_length;
	pkt.pktflags = 0;
	pkt.serial = serial;
	pkt.result = 0;
	pkt.recvlength = LWRES_RECVLENGTH;

 again:
	ret = lwres_grbnrequest_render(ctx, &request, &pkt, &b_out);
	if (ret != LWRES_R_SUCCESS)
		goto out;

	ret = lwres_context_sendrecv(ctx, b_out.base, b_out.length, buffer,
				     LWRES_RECVLENGTH, &recvlen);
	if (ret != LWRES_R_SUCCESS)
		goto out;

	lwres_buffer_init(&b_in, buffer, recvlen);
	b_in.used = recvlen;

	/*
	 * Parse the packet header.
	 */
	ret = lwres_lwpacket_parseheader(&b_in, &pkt);
	if (ret != LWRES_R_SUCCESS)
		goto out;

	/*
	 * Sanity check.
	 */
	if (pkt.serial != serial)
		goto again;
	if (pkt.opcode != LWRES_OPCODE_GETRDATABYNAME)
		goto again;

	/*
	 * Free what we've transmitted
	 */
	CTXFREE(b_out.base, b_out.length);
	b_out.base = NULL;
	b_out.length = 0;

	if (pkt.result != LWRES_R_SUCCESS) {
		ret = pkt.result;
		goto out;
	}

	/*
	 * Parse the response.
	 */
	ret = lwres_grbnresponse_parse(ctx, &b_in, &pkt, &response);
	if (ret != LWRES_R_SUCCESS)
		goto out;
	response->base = buffer;
	response->baselen = LWRES_RECVLENGTH;
	buffer = NULL; /* don't free this below */
//.........这里部分代码省略.........
开发者ID:crossbuild,项目名称:bind,代码行数:101,代码来源:lwresutil.c


示例12: lwres_getrrsetbyname_read

int
lwres_getrrsetbyname_read(struct lwres_async_state **plas,
			  lwres_context_t *ctx,
			  struct rrsetinfo **res)
{
	lwres_result_t lwresult;
	lwres_grbnresponse_t *response = NULL;
	char *buffer;
	struct rrsetinfo *rrset = NULL;
	int recvlen;
	int ret, result;
	unsigned int i;
	lwres_buffer_t            b_in;
	struct lwres_async_state *las;
	struct lwres_async_state **las_prev;
	lwres_lwpacket_t pkt;

	buffer = NULL;
	buffer = CTXMALLOC(LWRES_RECVLENGTH);
	if (buffer == NULL) {
		return ERRSET_NOMEMORY;
	}

	ret = LWRES_R_SUCCESS;
	lwresult = lwres_context_recv(ctx, buffer, LWRES_RECVLENGTH, &recvlen);
	if (lwresult == LWRES_R_RETRY) {
		ret = LWRES_R_RETRY;
		goto out;
	}
	
	if (ret != LWRES_R_SUCCESS) 
		goto out;

	lwres_buffer_init(&b_in, buffer, recvlen);
	b_in.used = recvlen;

	/*
	 * Parse the packet header.
	 */
	ret = lwres_lwpacket_parseheader(&b_in, &pkt);
	if (ret != LWRES_R_SUCCESS)
		goto out;

	/*
	 * find an appropriate waiting las entry. This is a linear search.
	 * we can do MUCH better, since we control the serial number!
	 * do that later.
	 */
	las_prev = &ctx->pending;
	las = ctx->pending;
	while(las && las->serial != pkt.serial) {
		las_prev=&las->next;
		las=las->next;
	}

	if(las == NULL) {
		/* no matching serial number! */
		return(LWRES_R_RETRY);
	}

	/* okay, remove it from the receive queue */
	*las_prev = las->next;
	las->next = NULL;
	las->inqueue = 0;

	*plas = las;

	/*
	 * Free what we've transmitted, long ago.
	 */
	CTXFREE(las->b_out.base, las->b_out.length);
	las->b_out.base = NULL;
	las->b_out.length = 0;

	if (pkt.result != LWRES_R_SUCCESS) {
		ret = pkt.result;
		goto out;
	}

	/*
	 * Parse the response.
	 */
	ret = lwres_grbnresponse_parse(ctx, &b_in, &pkt, &response);
	if (ret != LWRES_R_SUCCESS) {
	out:
		if (buffer != NULL)
			CTXFREE(buffer, LWRES_RECVLENGTH);
		if (response != NULL)
			lwres_grbnresponse_free(ctx, &response);
		result = lwresult_to_result(ret);
		goto fail;
	}

	response->base = buffer;
	response->baselen = LWRES_RECVLENGTH;
	buffer = NULL; /* don't free this below */

	lwresult = LWRES_R_SUCCESS;

	rrset = sane_malloc(sizeof(struct rrsetinfo));
//.........这里部分代码省略.........
开发者ID:nakedible,项目名称:vpnease-l2tp,代码行数:101,代码来源:async.c


示例13: lwres_context_allocmem

/*% Allocates len bytes of memory and if successful returns a pointer to the allocated storage. */
void *
lwres_context_allocmem(lwres_context_t *ctx, size_t len) {
	REQUIRE(len != 0U);

	return (CTXMALLOC(len));
}
开发者ID:enukane,项目名称:netbsd-src,代码行数:7,代码来源:context.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ CTX_INITIALIZED函数代码示例发布时间:2022-05-30
下一篇:
C++ CTXFREE函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap