change int2buff, buff2int etc. functions to static inline
parent
9acc202481
commit
7fbb5c620b
1
HISTORY
1
HISTORY
|
|
@ -3,6 +3,7 @@ Version 1.78 2025-08-02
|
||||||
* getIpaddrByName: normalize ip addr when input addr is IPv4 or IPv6
|
* getIpaddrByName: normalize ip addr when input addr is IPv4 or IPv6
|
||||||
* add files: spinlock.[hc]
|
* add files: spinlock.[hc]
|
||||||
* connection_pool.[hc]: use CAS instead of pthread mutex lock
|
* connection_pool.[hc]: use CAS instead of pthread mutex lock
|
||||||
|
* shared_func.[hc]: change int2buff, buff2int etc. functions to static inline
|
||||||
|
|
||||||
Version 1.77 2025-03-18
|
Version 1.77 2025-03-18
|
||||||
* impl. shorten_path for /./ and /../
|
* impl. shorten_path for /./ and /../
|
||||||
|
|
|
||||||
|
|
@ -1565,66 +1565,6 @@ int fc_copy_to_path(const char *src_filename, const char *dest_path)
|
||||||
return fc_copy_file(src_filename, dest_filename);
|
return fc_copy_file(src_filename, dest_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
void short2buff(const short n, char *buff)
|
|
||||||
{
|
|
||||||
unsigned char *p;
|
|
||||||
p = (unsigned char *)buff;
|
|
||||||
*p++ = (n >> 8) & 0xFF;
|
|
||||||
*p++ = n & 0xFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
short buff2short(const char *buff)
|
|
||||||
{
|
|
||||||
return (short)((((unsigned char)(*(buff))) << 8) | \
|
|
||||||
((unsigned char)(*(buff+1))));
|
|
||||||
}
|
|
||||||
|
|
||||||
void int2buff(const int n, char *buff)
|
|
||||||
{
|
|
||||||
unsigned char *p;
|
|
||||||
p = (unsigned char *)buff;
|
|
||||||
*p++ = (n >> 24) & 0xFF;
|
|
||||||
*p++ = (n >> 16) & 0xFF;
|
|
||||||
*p++ = (n >> 8) & 0xFF;
|
|
||||||
*p++ = n & 0xFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
int buff2int(const char *buff)
|
|
||||||
{
|
|
||||||
return (((unsigned char)(*buff)) << 24) | \
|
|
||||||
(((unsigned char)(*(buff+1))) << 16) | \
|
|
||||||
(((unsigned char)(*(buff+2))) << 8) | \
|
|
||||||
((unsigned char)(*(buff+3)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void long2buff(int64_t n, char *buff)
|
|
||||||
{
|
|
||||||
unsigned char *p;
|
|
||||||
p = (unsigned char *)buff;
|
|
||||||
*p++ = (n >> 56) & 0xFF;
|
|
||||||
*p++ = (n >> 48) & 0xFF;
|
|
||||||
*p++ = (n >> 40) & 0xFF;
|
|
||||||
*p++ = (n >> 32) & 0xFF;
|
|
||||||
*p++ = (n >> 24) & 0xFF;
|
|
||||||
*p++ = (n >> 16) & 0xFF;
|
|
||||||
*p++ = (n >> 8) & 0xFF;
|
|
||||||
*p++ = n & 0xFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t buff2long(const char *buff)
|
|
||||||
{
|
|
||||||
unsigned char *p;
|
|
||||||
p = (unsigned char *)buff;
|
|
||||||
return (((int64_t)(*p)) << 56) | \
|
|
||||||
(((int64_t)(*(p+1))) << 48) | \
|
|
||||||
(((int64_t)(*(p+2))) << 40) | \
|
|
||||||
(((int64_t)(*(p+3))) << 32) | \
|
|
||||||
(((int64_t)(*(p+4))) << 24) | \
|
|
||||||
(((int64_t)(*(p+5))) << 16) | \
|
|
||||||
(((int64_t)(*(p+6))) << 8) | \
|
|
||||||
((int64_t)(*(p+7)));
|
|
||||||
}
|
|
||||||
|
|
||||||
int fd_gets(int fd, char *buff, const int size, int once_bytes)
|
int fd_gets(int fd, char *buff, const int size, int once_bytes)
|
||||||
{
|
{
|
||||||
char *pDest;
|
char *pDest;
|
||||||
|
|
|
||||||
|
|
@ -196,14 +196,24 @@ void printBuffHex(const char *s, const int len);
|
||||||
* buff: the buffer, at least 2 bytes space, no tail \0
|
* buff: the buffer, at least 2 bytes space, no tail \0
|
||||||
* return: none
|
* return: none
|
||||||
*/
|
*/
|
||||||
void short2buff(const short n, char *buff);
|
static inline void short2buff(const short n, char *buff)
|
||||||
|
{
|
||||||
|
unsigned char *p;
|
||||||
|
p = (unsigned char *)buff;
|
||||||
|
*p++ = (n >> 8) & 0xFF;
|
||||||
|
*p++ = n & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
/** buffer convert to 16 bits int
|
/** buffer convert to 16 bits int
|
||||||
* parameters:
|
* parameters:
|
||||||
* buff: big-endian 2 bytes buffer
|
* buff: big-endian 2 bytes buffer
|
||||||
* return: 16 bits int value
|
* return: 16 bits int value
|
||||||
*/
|
*/
|
||||||
short buff2short(const char *buff);
|
static inline short buff2short(const char *buff)
|
||||||
|
{
|
||||||
|
return (short)((((unsigned char)(*(buff))) << 8) |
|
||||||
|
((unsigned char)(*(buff+1))));
|
||||||
|
}
|
||||||
|
|
||||||
/** 32 bits int convert to buffer (big-endian)
|
/** 32 bits int convert to buffer (big-endian)
|
||||||
* parameters:
|
* parameters:
|
||||||
|
|
@ -211,14 +221,28 @@ short buff2short(const char *buff);
|
||||||
* buff: the buffer, at least 4 bytes space, no tail \0
|
* buff: the buffer, at least 4 bytes space, no tail \0
|
||||||
* return: none
|
* return: none
|
||||||
*/
|
*/
|
||||||
void int2buff(const int n, char *buff);
|
static inline void int2buff(const int n, char *buff)
|
||||||
|
{
|
||||||
|
unsigned char *p;
|
||||||
|
p = (unsigned char *)buff;
|
||||||
|
*p++ = (n >> 24) & 0xFF;
|
||||||
|
*p++ = (n >> 16) & 0xFF;
|
||||||
|
*p++ = (n >> 8) & 0xFF;
|
||||||
|
*p++ = n & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
/** buffer convert to 32 bits int
|
/** buffer convert to 32 bits int
|
||||||
* parameters:
|
* parameters:
|
||||||
* buff: big-endian 4 bytes buffer
|
* buff: big-endian 4 bytes buffer
|
||||||
* return: 32 bits int value
|
* return: 32 bits int value
|
||||||
*/
|
*/
|
||||||
int buff2int(const char *buff);
|
static inline int buff2int(const char *buff)
|
||||||
|
{
|
||||||
|
return (((unsigned char)(*buff)) << 24) |
|
||||||
|
(((unsigned char)(*(buff+1))) << 16) |
|
||||||
|
(((unsigned char)(*(buff+2))) << 8) |
|
||||||
|
((unsigned char)(*(buff+3)));
|
||||||
|
}
|
||||||
|
|
||||||
/** long (64 bits) convert to buffer (big-endian)
|
/** long (64 bits) convert to buffer (big-endian)
|
||||||
* parameters:
|
* parameters:
|
||||||
|
|
@ -226,15 +250,38 @@ int buff2int(const char *buff);
|
||||||
* buff: the buffer, at least 8 bytes space, no tail \0
|
* buff: the buffer, at least 8 bytes space, no tail \0
|
||||||
* return: none
|
* return: none
|
||||||
*/
|
*/
|
||||||
void long2buff(int64_t n, char *buff);
|
static inline void long2buff(int64_t n, char *buff)
|
||||||
|
{
|
||||||
|
unsigned char *p;
|
||||||
|
p = (unsigned char *)buff;
|
||||||
|
*p++ = (n >> 56) & 0xFF;
|
||||||
|
*p++ = (n >> 48) & 0xFF;
|
||||||
|
*p++ = (n >> 40) & 0xFF;
|
||||||
|
*p++ = (n >> 32) & 0xFF;
|
||||||
|
*p++ = (n >> 24) & 0xFF;
|
||||||
|
*p++ = (n >> 16) & 0xFF;
|
||||||
|
*p++ = (n >> 8) & 0xFF;
|
||||||
|
*p++ = n & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
/** buffer convert to 64 bits int
|
/** buffer convert to 64 bits int
|
||||||
* parameters:
|
* parameters:
|
||||||
* buff: big-endian 8 bytes buffer
|
* buff: big-endian 8 bytes buffer
|
||||||
* return: 64 bits int value
|
* return: 64 bits int value
|
||||||
*/
|
*/
|
||||||
int64_t buff2long(const char *buff);
|
static inline int64_t buff2long(const char *buff)
|
||||||
|
{
|
||||||
|
unsigned char *p;
|
||||||
|
p = (unsigned char *)buff;
|
||||||
|
return (((int64_t)(*p)) << 56) |
|
||||||
|
(((int64_t)(*(p+1))) << 48) |
|
||||||
|
(((int64_t)(*(p+2))) << 40) |
|
||||||
|
(((int64_t)(*(p+3))) << 32) |
|
||||||
|
(((int64_t)(*(p+4))) << 24) |
|
||||||
|
(((int64_t)(*(p+5))) << 16) |
|
||||||
|
(((int64_t)(*(p+6))) << 8) |
|
||||||
|
((int64_t)(*(p+7)));
|
||||||
|
}
|
||||||
|
|
||||||
/** 32 bits float convert to buffer (big-endian)
|
/** 32 bits float convert to buffer (big-endian)
|
||||||
* parameters:
|
* parameters:
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
#define USE_CONN_POOL 1
|
#define USE_CONN_POOL 1
|
||||||
//#define USE_CAS_LOCK 1
|
//#define USE_CAS_LOCK 1
|
||||||
|
|
||||||
static int thread_count = 24;
|
static int thread_count = 16;
|
||||||
static int64_t loop_count = 10000000;
|
static int64_t loop_count = 10000000;
|
||||||
static ConnectionPool cpool;
|
static ConnectionPool cpool;
|
||||||
static char buff[1024];
|
static char buff[1024];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue