Skip to content
Snippets Groups Projects
utils.c 25.9 KiB
Newer Older
  • Learn to ignore specific revisions
  • 	 * reallocate the buffer and return a message telling to retry.
    	 */
    
    Luigi Rizzo's avatar
    Luigi Rizzo committed
    	if (need > (*buf)->len && (max_len == 0 || (*buf)->len < max_len) ) {
    
    		if (max_len && max_len < need)	/* truncate as needed */
    
    Luigi Rizzo's avatar
    Luigi Rizzo committed
    			need = max_len;
    
    		/* We can only realloc malloc'ed space. */
    		if ((*buf)->type != DS_MALLOC)
    			return AST_DYNSTR_BUILD_FAILED;
    
    Luigi Rizzo's avatar
    Luigi Rizzo committed
    		*buf = ast_realloc(*buf, need + sizeof(struct ast_dynamic_str));
    
    		if (*buf == NULL) /* XXX watch out, we leak memory here */
    
    			return AST_DYNSTR_BUILD_FAILED;
    
    Luigi Rizzo's avatar
    Luigi Rizzo committed
    		(*buf)->len = need;
    
    		(*buf)->str[offset] = '\0';	/* Truncate the partial write. */
    
    		if (ts)
    			pthread_setspecific(ts->key, *buf);
    
    		/* va_end() and va_start() must be done before calling
    		 * vsnprintf() again. */
    		return AST_DYNSTR_BUILD_RETRY;
    	}
    
    	/* update space used, keep in mind the truncation */
    	(*buf)->used = (res + offset > (*buf)->len) ? (*buf)->len : res + offset;
    
    
    void ast_enable_packet_fragmentation(int sock)
    {
    
    #if defined(HAVE_IP_MTU_DISCOVER)
    
    	int val = IP_PMTUDISC_DONT;
    	
    	if (setsockopt(sock, IPPROTO_IP, IP_MTU_DISCOVER, &val, sizeof(val)))
    		ast_log(LOG_WARNING, "Unable to disable PMTU discovery. Large UDP packets may fail to be delivered when sent from this socket.\n");
    
    #endif /* HAVE_IP_MTU_DISCOVER */