* 变更stream系列文件的名称为ssl_stream, tcp_stream等; * 变更stream.h为platform.h,因该文件为平台整体公用; * 修正了ssl_stream, ssl_sess_cache文件中的编译错误,部分实现的bug。 * 调整了tfe_future的路径,由平台实现改为公用组件。
67 lines
2.2 KiB
C
67 lines
2.2 KiB
C
/*
|
|
* @file tfe_utils.h
|
|
* This file provides common usage marcos and helper functions.
|
|
*/
|
|
|
|
#pragma once
|
|
#include <MESA/MESA_handle_logger.h>
|
|
|
|
#define TFE_STRING_MAX 2048
|
|
#define TFE_SYMBOL_MAX 64
|
|
|
|
#ifndef TFE_CONFIG_BACKLOG_DEFAULT
|
|
#define TFE_CONFIG_BACKLOG_DEFAULT 20
|
|
#endif
|
|
|
|
#define ALLOC(type, number) ((type *)calloc(sizeof(type), number))
|
|
|
|
#define TFE_STRUCT_ALLOC(struct_type) __extension__ \
|
|
({ \
|
|
((struct_type) * ) __struct_ptr; \
|
|
__struct_ptr = ((struct_type) *)malloc(sizeof((struct_type))); \
|
|
__struct_ptr; \
|
|
})
|
|
|
|
#define likely(expr) __builtin_expect((expr), 1)
|
|
#define unlikely(expr) __builtin_expect((expr), 0)
|
|
|
|
#define TFE_LOG_ERROR(handler, fmt, ...) \
|
|
do { MESA_handle_runtime_log(handler, RLOG_LV_FATAL, NULL, fmt, ##__VA_ARGS__); } while(0) \
|
|
|
|
#define TFE_LOG_INFO(handler, fmt, ...) \
|
|
do { MESA_handle_runtime_log(handler, RLOG_LV_INFO, NULL, fmt, ##__VA_ARGS__); } while(0) \
|
|
|
|
#define TFE_LOG_DEBUG(handler, fmt, ...) \
|
|
do { MESA_handle_runtime_log(handler, RLOG_LV_DEBUG, NULL, fmt, ##__VA_ARGS__); } while(0) \
|
|
|
|
#ifndef offsetof
|
|
/** Return the offset of a field in a structure. */
|
|
#define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
|
|
#endif
|
|
|
|
/**
|
|
* Return pointer to the wrapping struct instance.
|
|
*
|
|
* Example:
|
|
*
|
|
* struct wrapper {
|
|
* ...
|
|
* struct child c;
|
|
* ...
|
|
* };
|
|
*
|
|
* struct child *x = obtain(...);
|
|
* struct wrapper *w = container_of(x, struct wrapper, c);
|
|
*/
|
|
#ifndef container_of
|
|
#define container_of(ptr, type, member) __extension__ ({ \
|
|
const typeof(((type *)0)->member) *_ptr = (ptr); \
|
|
__attribute__((unused)) type *_target_ptr = (type *)(ptr); \
|
|
(type *)(((uintptr_t)_ptr) - offsetof(type, member)); \
|
|
})
|
|
#endif
|
|
|
|
int addr_sock_to_layer(struct sockaddr * sock_addr, int sockaddrlen, struct layer_addr * layer_addr);
|
|
int addr_layer_to_sock(struct layer_addr * layer_addr, struct sockaddr * sock_addr);
|
|
char* tfe_strdup(const char* s);
|