소스 검색

#define HV_INLINE static inline

hewei.it 4 년 전
부모
커밋
341336a74d
8개의 변경된 파일32개의 추가작업 그리고 29개의 파일을 삭제
  1. 1 1
      base/hbase.h
  2. 11 11
      base/hsocket.h
  3. 3 3
      base/htime.h
  4. 1 1
      base/hversion.h
  5. 2 2
      cpputil/hstring.h
  6. 3 0
      hexport.h
  7. 9 9
      http/client/requests.h
  8. 2 2
      http/wsdef.h

+ 1 - 1
base/hbase.h

@@ -33,7 +33,7 @@ HV_EXPORT void  safe_free(void* ptr);
 
 HV_EXPORT long hv_alloc_cnt();
 HV_EXPORT long hv_free_cnt();
-static inline void hv_memcheck() {
+HV_INLINE void hv_memcheck() {
     printf("Memcheck => alloc:%ld free:%ld\n", hv_alloc_cnt(), hv_free_cnt());
 }
 #define HV_MEMCHECK    atexit(hv_memcheck);

+ 11 - 11
base/hsocket.h

@@ -17,7 +17,7 @@
 
 BEGIN_EXTERN_C
 
-static inline int socket_errno() {
+HV_INLINE int socket_errno() {
 #ifdef OS_WIN
     return WSAGetLastError();
 #else
@@ -28,11 +28,11 @@ HV_EXPORT const char* socket_strerror(int err);
 
 #ifdef OS_WIN
 typedef int socklen_t;
-static inline int blocking(int sockfd) {
+HV_INLINE int blocking(int sockfd) {
     unsigned long nb = 0;
     return ioctlsocket(sockfd, FIONBIO, &nb);
 }
-static inline int nonblocking(int sockfd) {
+HV_INLINE int nonblocking(int sockfd) {
     unsigned long nb = 1;
     return ioctlsocket(sockfd, FIONBIO, &nb);
 }
@@ -77,7 +77,7 @@ HV_EXPORT const char* sockaddr_str(sockaddr_u* addr, char* buf, int len);
 //#define INET6_ADDRSTRLEN  46
 #ifdef ENABLE_UDS
 #define SOCKADDR_STRLEN     sizeof(((struct sockaddr_un*)(NULL))->sun_path)
-static inline void sockaddr_set_path(sockaddr_u* addr, const char* path) {
+HV_INLINE void sockaddr_set_path(sockaddr_u* addr, const char* path) {
     addr->sa.sa_family = AF_UNIX;
     strncpy(addr->sun.sun_path, path, sizeof(addr->sun.sun_path));
 }
@@ -85,7 +85,7 @@ static inline void sockaddr_set_path(sockaddr_u* addr, const char* path) {
 #define SOCKADDR_STRLEN     64 // ipv4:port | [ipv6]:port
 #endif
 
-static inline void sockaddr_print(sockaddr_u* addr) {
+HV_INLINE void sockaddr_print(sockaddr_u* addr) {
     char buf[SOCKADDR_STRLEN] = {0};
     sockaddr_str(addr, buf, sizeof(buf));
     puts(buf);
@@ -125,11 +125,11 @@ HV_EXPORT int ConnectUnixTimeout(const char* path, int ms DEFAULT(DEFAULT_CONNEC
 // Just implement Socketpair(AF_INET, SOCK_STREAM, 0, sv);
 HV_EXPORT int Socketpair(int family, int type, int protocol, int sv[2]);
 
-static inline int tcp_nodelay(int sockfd, int on DEFAULT(1)) {
+HV_INLINE int tcp_nodelay(int sockfd, int on DEFAULT(1)) {
     return setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (const char*)&on, sizeof(int));
 }
 
-static inline int tcp_nopush(int sockfd, int on DEFAULT(1)) {
+HV_INLINE int tcp_nopush(int sockfd, int on DEFAULT(1)) {
 #ifdef TCP_NOPUSH
     return setsockopt(sockfd, IPPROTO_TCP, TCP_NOPUSH, (const char*)&on, sizeof(int));
 #elif defined(TCP_CORK)
@@ -139,7 +139,7 @@ static inline int tcp_nopush(int sockfd, int on DEFAULT(1)) {
 #endif
 }
 
-static inline int tcp_keepalive(int sockfd, int on DEFAULT(1), int delay DEFAULT(60)) {
+HV_INLINE int tcp_keepalive(int sockfd, int on DEFAULT(1), int delay DEFAULT(60)) {
     if (setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE, (const char*)&on, sizeof(int)) != 0) {
         return socket_errno();
     }
@@ -156,12 +156,12 @@ static inline int tcp_keepalive(int sockfd, int on DEFAULT(1), int delay DEFAULT
 #endif
 }
 
-static inline int udp_broadcast(int sockfd, int on DEFAULT(1)) {
+HV_INLINE int udp_broadcast(int sockfd, int on DEFAULT(1)) {
     return setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, (const char*)&on, sizeof(int));
 }
 
 // send timeout
-static inline int so_sndtimeo(int sockfd, int timeout) {
+HV_INLINE int so_sndtimeo(int sockfd, int timeout) {
 #ifdef OS_WIN
     return setsockopt(sockfd, SOL_SOCKET, SO_SNDTIMEO, (const char*)&timeout, sizeof(int));
 #else
@@ -171,7 +171,7 @@ static inline int so_sndtimeo(int sockfd, int timeout) {
 }
 
 // recv timeout
-static inline int so_rcvtimeo(int sockfd, int timeout) {
+HV_INLINE int so_rcvtimeo(int sockfd, int timeout) {
 #ifdef OS_WIN
     return setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(int));
 #else

+ 3 - 3
base/htime.h

@@ -37,7 +37,7 @@ struct timezone {
 };
 
 #include <sys/timeb.h>
-static inline int gettimeofday(struct timeval *tv, struct timezone *tz) {
+HV_INLINE int gettimeofday(struct timeval *tv, struct timezone *tz) {
     struct _timeb tb;
     _ftime(&tb);
     if (tv) {
@@ -53,12 +53,12 @@ static inline int gettimeofday(struct timeval *tv, struct timezone *tz) {
 #endif
 
 HV_EXPORT unsigned int gettick_ms();
-static inline unsigned long long gettimeofday_ms() {
+HV_INLINE unsigned long long gettimeofday_ms() {
     struct timeval tv;
     gettimeofday(&tv, NULL);
     return tv.tv_sec * (unsigned long long)1000 + tv.tv_usec/1000;
 }
-static inline unsigned long long gettimeofday_us() {
+HV_INLINE unsigned long long gettimeofday_us() {
     struct timeval tv;
     gettimeofday(&tv, NULL);
     return tv.tv_sec * (unsigned long long)1000000 + tv.tv_usec;

+ 1 - 1
base/hversion.h

@@ -17,7 +17,7 @@ BEGIN_EXTERN_C
 #define HV_VERSION_NUMBER   ((HV_VERSION_MAJOR << 16) | (HV_VERSION_MINOR << 8) | HV_VERSION_PATCH)
 
 
-static inline const char* hv_version() {
+HV_INLINE const char* hv_version() {
     return HV_VERSION_STRING;
 }
 

+ 2 - 2
cpputil/hstring.h

@@ -23,14 +23,14 @@ public:
 namespace hv {
 // NOTE: low-version NDK not provide std::to_string
 template<typename T>
-static inline std::string to_string(const T& t) {
+HV_INLINE std::string to_string(const T& t) {
     std::ostringstream oss;
     oss << t;
     return oss.str();
 }
 
 template<typename T>
-static inline T from_string(const std::string& str) {
+HV_INLINE T from_string(const std::string& str) {
     T t;
     std::istringstream iss(str);
     iss >> t;

+ 3 - 0
hexport.h

@@ -16,6 +16,9 @@
     #define HV_EXPORT
 #endif
 
+// HV_INLINE
+#define HV_INLINE static inline
+
 // HV_DEPRECATED
 #if defined(HV_NO_DEPRECATED)
 #define HV_DEPRECATED

+ 9 - 9
http/client/requests.h

@@ -41,13 +41,13 @@ typedef std::shared_ptr<HttpResponse> Response;
 static http_headers DefaultHeaders;
 static http_body    NoBody;
 
-static inline Response request(Request req) {
+HV_INLINE Response request(Request req) {
     Response resp(new HttpResponse);
     int ret = http_client_send(req.get(), resp.get());
     return ret ? NULL : resp;
 }
 
-static inline Response request(http_method method, const char* url, const http_body& body = NoBody, const http_headers& headers = DefaultHeaders) {
+HV_INLINE Response request(http_method method, const char* url, const http_body& body = NoBody, const http_headers& headers = DefaultHeaders) {
     Request req(new HttpRequest);
     req->method = method;
     req->url = url;
@@ -60,32 +60,32 @@ static inline Response request(http_method method, const char* url, const http_b
     return request(req);
 }
 
-static inline Response get(const char* url, const http_headers& headers = DefaultHeaders) {
+HV_INLINE Response get(const char* url, const http_headers& headers = DefaultHeaders) {
     return request(HTTP_GET, url, NoBody, headers);
 }
 
-static inline Response options(const char* url, const http_headers& headers = DefaultHeaders) {
+HV_INLINE Response options(const char* url, const http_headers& headers = DefaultHeaders) {
     return request(HTTP_OPTIONS, url, NoBody, headers);
 }
 
-static inline Response head(const char* url, const http_headers& headers = DefaultHeaders) {
+HV_INLINE Response head(const char* url, const http_headers& headers = DefaultHeaders) {
     return request(HTTP_HEAD, url, NoBody, headers);
 }
 
-static inline Response post(const char* url, const http_body& body = NoBody, const http_headers& headers = DefaultHeaders) {
+HV_INLINE Response post(const char* url, const http_body& body = NoBody, const http_headers& headers = DefaultHeaders) {
     return request(HTTP_POST, url, body, headers);
 }
 
-static inline Response put(const char* url, const http_body& body = NoBody, const http_headers& headers = DefaultHeaders) {
+HV_INLINE Response put(const char* url, const http_body& body = NoBody, const http_headers& headers = DefaultHeaders) {
     return request(HTTP_PUT, url, body, headers);
 }
 
-static inline Response patch(const char* url, const http_body& body = NoBody, const http_headers& headers = DefaultHeaders) {
+HV_INLINE Response patch(const char* url, const http_body& body = NoBody, const http_headers& headers = DefaultHeaders) {
     return request(HTTP_PATCH, url, body, headers);
 }
 
 // delete is c++ keyword, we have to replace delete with Delete.
-static inline Response Delete(const char* url, const http_body& body = NoBody, const http_headers& headers = DefaultHeaders) {
+HV_INLINE Response Delete(const char* url, const http_body& body = NoBody, const http_headers& headers = DefaultHeaders) {
     return request(HTTP_DELETE, url, body, headers);
 }
 

+ 2 - 2
http/wsdef.h

@@ -53,7 +53,7 @@ HV_EXPORT int ws_build_frame(
     enum ws_opcode opcode DEFAULT(WS_OPCODE_TEXT),
     bool fin DEFAULT(true));
 
-static inline int ws_client_build_frame(
+HV_INLINE int ws_client_build_frame(
     char* out,
     const char* data,
     int data_len,
@@ -66,7 +66,7 @@ static inline int ws_client_build_frame(
     return ws_build_frame(out, data, data_len, mask, true, opcode, fin);
 }
 
-static inline int ws_server_build_frame(
+HV_INLINE int ws_server_build_frame(
     char* out,
     const char* data,
     int data_len,