Browse Source

fix build on alpine

pull/1357/head
MengqiWu 6 years ago
parent
commit
5a595159e4
  1. 12
      modules/mod_dubbo/utils/objects.cc
  2. 44
      modules/mod_dubbo/utils/utils.cc
  3. 12
      modules/mod_dubbo/utils/utils.h

12
modules/mod_dubbo/utils/objects.cc

@ -35,19 +35,19 @@ pair<Object*, bool> ObjectValue::get_object() const {
* maybe need delete, need check pair.second
*/
switch (_type) {
case OBJ: return pair<Object*, bool>(_value.obj, false); // 不需要链式释放
case C_OBJ: return pair<Object*, bool>(_value.obj, false); // 不需要链式释放
case OBJ: return pair<Object*, bool>(_value.obj, false);
case C_OBJ: return pair<Object*, bool>(_value.obj, false);
case IVAL: return pair<Object*, bool>(new Integer(_value.ival), true);
case LVAL: return pair<Object*, bool>(new Long(_value.lval), true);
case BVAL: return pair<Object*, bool>(new Boolean(_value.bval), true);
case C_CHAR_PTR: return pair<Object*, bool>(new String(_value.c_char_ptr), true); // 拷贝
case C_CHAR_PTR: return pair<Object*, bool>(new String(_value.c_char_ptr), true);
case C_STR_REF: return pair<Object*, bool>(new String(_value.c_str_ptr->c_str(), _value.c_str_ptr->size()), true); // 拷贝
case C_STR_PTR: return pair<Object*, bool>(new String(_value.c_str_ptr), true); // 不拷贝,也不负责删除
case STR_PTR: return pair<Object*, bool>(new String(_value.str_ptr, false), true); // 不拷贝,也不负责删除
case C_STR_PTR: return pair<Object*, bool>(new String(_value.c_str_ptr), true);
case STR_PTR: return pair<Object*, bool>(new String(_value.str_ptr, false), true);
case CVAL: return pair<Object*, bool>(new String(new string(1, _value.cval), true, "char"), true);
case SVAL: return pair<Object*, bool>(new Integer(_value.sval), true);
case DVAL: return pair<Object*, bool>(new Double(_value.dval), true);
default: return pair<Object*, bool>(NULL, false); // 不需要链式释放
default: return pair<Object*, bool>(NULL, false);
}
}

44
modules/mod_dubbo/utils/utils.cc

@ -9,12 +9,9 @@
#include <cstring>
#include <cstdlib>
#include <inttypes.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <linux/if.h>
#include <langinfo.h>
#include <iconv.h>
#include <sstream>
@ -162,47 +159,6 @@ void hexdump(const char* caption, const void* ptr, unsigned int len) {
printf("%08x\n", len);
}
uint64_t milli_time() {
struct timeval tv;
gettimeofday(&tv , NULL);
return (tv.tv_sec * __UINT64_C(1000)) + tv.tv_usec / __UINT64_C(1000);
}
uint64_t micro_time() {
struct timeval tv;
gettimeofday(&tv , NULL);
return (tv.tv_sec * __UINT64_C(1000000)) + tv.tv_usec;
}
void asleep(double sec) {
struct timespec ts;
ts.tv_sec = (long)sec; ts.tv_nsec = (long)((sec - ts.tv_sec) * 1e9);
nanosleep(&ts, 0);
}
uint64_t get_ifaddr_ipv4() {
int MAX_INTERFACES = 16;
uint64_t ip = 0;
int fd, intrface = 0;
struct ifreq buf[MAX_INTERFACES];
struct ifconf ifc;
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) >= 0) {
ifc.ifc_len = sizeof(buf);
ifc.ifc_buf = (caddr_t) buf;
if (!ioctl(fd, SIOCGIFCONF, (char*)&ifc)) {
intrface = ifc.ifc_len / sizeof(struct ifreq);
while (intrface-- > 0) {
if (!(ioctl(fd, SIOCGIFADDR, (char*)&buf[intrface]))) {
ip = *((uint64_t*)&(buf[intrface].ifr_addr));
break;
}
}
}
close(fd);
}
return ip;
}
string system_charset() {
// locale charmap
setlocale(LC_CTYPE, "");

12
modules/mod_dubbo/utils/utils.h

@ -67,18 +67,6 @@ inline std::string &trim(std::string &s) {
return ltrim(rtrim(s));
}
/*
* time
*/
uint64_t micro_time();
uint64_t milli_time();
void asleep(double sec);
/*
* local ip
*/
uint64_t get_ifaddr_ipv4();
/*
* charset
*/

Loading…
Cancel
Save