Ejemplo n.º 1
0
/*@null@*/
char *stats_prefix_dump(int *length) {
    const char *format = "PREFIX %s get %llu hit %llu set %llu del %llu\r\n";
    PREFIX_STATS *pfs;
    char *buf;
    int i, pos;
    size_t size = 0, written = 0, total_written = 0;

    /*
     * Figure out how big the buffer needs to be. This is the sum of the
     * lengths of the prefixes themselves, plus the size of one copy of
     * the per-prefix output with 20-digit values for all the counts,
     * plus space for the "END" at the end.
     */
    // [branch 002] Replaced STATS_LOCK with relaxed transaction
    // [branch 012] With oncommit, this becomes atomic
    __transaction_atomic {
        // [branch 009] Switched to safe strlen functions
    size = tm_strlen(format) + total_prefix_size +
           num_prefixes * (tm_strlen(format) - 2 /* %s */
                           + 4 * (20 - 4)) /* %llu replaced by 20-digit num */
                           + sizeof("END\r\n");
    buf = malloc(size);
    if (NULL == buf) {
        // [branch 012] Move perror to oncommit handler
        registerOnCommitHandler(spd_perror1, (void*)(uintptr_t)errno);
        return NULL;
    }

    pos = 0;
    for (i = 0; i < PREFIX_HASH_SIZE; i++) {
        for (pfs = prefix_stats[i]; NULL != pfs; pfs = pfs->next) {
            // [branch 011] Marhsall pfs->prefix into a local, so we can use
            //              a pure snprintf variant
            char local[4096];
            tm_strncpy_to_local(local, pfs->prefix, 4096);
            written = tm_snprintf_s_llu_llu_llu_llu(buf + pos, size-pos, format,
                               local, // pfs->prefix,
                               pfs->num_gets, pfs->num_hits,
                               pfs->num_sets, pfs->num_deletes);
            pos += written;
            total_written += written;
            // [branch 008] Switch to safe assertions
            tm_assert(total_written < size);
        }
    }

    }
    memcpy(buf + pos, "END\r\n", 6);

    *length = pos + 5;
    return buf;
}
Ejemplo n.º 2
0
/* Append a null-terminated character array to the string in place. */
void tm_string_cat(tm_string *in_out_str, str_char *chars_to_append)
{
	str_char *old_contents;
	unsigned int len_of_chars_to_append;

	ASSERT(in_out_str);
	ASSERT(chars_to_append);
	ASSERT(in_out_str->contents);

	len_of_chars_to_append = tm_strlen(chars_to_append);

	if (is_enough_room(in_out_str, len_of_chars_to_append))
	{
		/* append chars to string */
		tm_strcat(in_out_str->contents + in_out_str->length, chars_to_append);
	}
	else /* make room, copy old string to new area, then append */
	{
		old_contents = in_out_str->contents;
		alloc_new_contents(in_out_str, len_of_chars_to_append + in_out_str->length);
		tm_strcpy(in_out_str->contents, old_contents);
		tm_strcat(in_out_str->contents + in_out_str->length, chars_to_append);
		tman_free(old_contents);
	}
	in_out_str->length += len_of_chars_to_append;
}
Ejemplo n.º 3
0
/* Create a new string from an existing character array that is null terminated. */
tm_string *tm_string_new(str_char *input_chars)
{
	tm_string *new_str;
	
	ASSERT(input_chars);
	new_str = tman_malloc (sizeof (tm_string));
	new_str->type = STRING_TYPE;
	new_str->length = tm_strlen(input_chars);
	new_str->contents_max_len = next_power_of_2_or_min_size(new_str->length);
	new_str->contents = tman_malloc(new_str->contents_max_len * sizeof (str_char));
	tm_strcpy(new_str->contents, input_chars);
	return(new_str);
}
Ejemplo n.º 4
0
VOID App_serviceDiscoveryCallback(void *pData, const GSN_MDNS_SRVC_INFO_T *srvinfo,
                                  UINT32 status)
{
    // call back funtion
    //gets called back with service discovery data and signal the semaphore
    PROXY_UPDATER_DATA *ctx;
    int i;
    APP_RTC_LATCH_MEM_INFO_T *pAppRtcLtchInfo = App_RtcLatchMemInfoPtrGet();
    AppDbg_Printf("App_serviceDiscoveryCallback +\r\n");
    ctx = (PROXY_UPDATER_DATA*)pData;
    if(status !=  GSN_MDNS_SD_NO_SRVC_INFO)
    {
        if(ctx != NULL && srvinfo->txtInfo != NULL)
        {
            if((memcmp(TEXT_RECORD_DATA,srvinfo->txtInfo,tm_strlen(TEXT_RECORD_DATA))) == 0)
            {
                printf("text record matched\r\n");
                printf("AppServiceDiscover_RrRegCb ip address = %d.%d.%d.%d\r\n",srvinfo->ipAddr[0],srvinfo->ipAddr[1],srvinfo->ipAddr[2],srvinfo->ipAddr[3]);

                printf("srvinfo->textRecord = %s\r\n",srvinfo->textRecord);

                // copy the IP address and port
                for(i = 0; i < 4; i++)
                {
                    ctx->IPAddress[i] = ( srvinfo->ipAddr >> (i*8) ) & 0xFF;
                    pAppRtcLtchInfo->IotGatewayIpAddress[i] = ctx->IPAddress[i];
                }
                ctx->portNo = srvinfo->port;
                AppDbg_Printf("srvinfo->port = %d\r\n",srvinfo->port);

                (pAppRtcLtchInfo->IotGatewayPort) = srvinfo->port;
                AppDbg_Printf("pAppRtcLtchInfo->IotGatewayPort = %d\r\n",pAppRtcLtchInfo->IotGatewayPort);
                AppDbg_Printf("sizeof(APP_RTC_LATCH_MEM_INFO_T) = %d\r\n",sizeof(APP_RTC_LATCH_MEM_INFO_T));
                serviceDiscovered = TRUE;

            }
        }
    }