Skip to content
Snippets Groups Projects
Commit 03bc18a8 authored by dmitriy.gerasimov's avatar dmitriy.gerasimov
Browse files

Merge branch 'feature-2648' into 'master'

Feature 2648

See merge request !6
parents 73a86ef8 4b255db6
No related branches found
No related tags found
1 merge request!6Feature 2648
...@@ -22,8 +22,6 @@ file(GLOB DAP_SERVER_CORE_HEADERS include/*.h) ...@@ -22,8 +22,6 @@ file(GLOB DAP_SERVER_CORE_HEADERS include/*.h)
if(WIN32) if(WIN32)
include_directories(../libdap/src/win32/) include_directories(../libdap/src/win32/)
include_directories(../3rdparty/libmemcached/)
include_directories(../3rdparty/libmemcached/win32/)
include_directories(../3rdparty/wepoll/include/) include_directories(../3rdparty/wepoll/include/)
include_directories(../3rdparty/uthash/src/) include_directories(../3rdparty/uthash/src/)
include_directories(../3rdparty/libjson-c/) include_directories(../3rdparty/libjson-c/)
...@@ -37,7 +35,12 @@ if(WIN32) ...@@ -37,7 +35,12 @@ if(WIN32)
endif() endif()
if(UNIX) if(UNIX)
target_link_libraries(${PROJECT_NAME} dap_core dap_crypto pthread memcached ev) target_link_libraries(${PROJECT_NAME} dap_core dap_crypto ev)
if(NOT ANDROID)
target_link_libraries(${PROJECT_NAME} pthread)
endif()
endif() endif()
target_include_directories(${PROJECT_NAME} PUBLIC include) target_include_directories(${PROJECT_NAME} PUBLIC include)
......
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include "dap_common.h"
/**
* @brief dap_memcached_init
* @param server_host
* @param port
* @return
*/
int dap_memcached_init(const char *server_host, uint16_t port);
/**
* @brief is_dap_memcache_enable
* @return
*/
bool dap_memcache_is_enable(void);
/**
* @brief dap_memcached_deinit
*/
void dap_memcached_deinit(void);
/**
* @brief dap_memcache_put
* @param key
* @param value
* @param value_size
* @param expiration if 0 value is never expire
* @return
*/
bool dap_memcache_put(const char* key, void *value, size_t value_size, time_t expiration);
/**
* @brief dap_memcache_get
* @param key
* @return true if key found
*/
bool dap_memcache_get(const char* key, size_t * value_size, void ** result);
/**
* @brief dap_memcache_delete
* @param key
* @return
*/
bool dap_memcache_delete(const char* key);
...@@ -280,19 +280,25 @@ static void *thread_worker_function( void *arg ) ...@@ -280,19 +280,25 @@ static void *thread_worker_function( void *arg )
time_t next_time_timeout_check = time( NULL ) + s_connection_timeout / 2; time_t next_time_timeout_check = time( NULL ) + s_connection_timeout / 2;
uint32_t tn = w->number_thread; uint32_t tn = w->number_thread;
#ifndef _WIN32 #ifndef _WIN32
#ifndef NO_POSIX_SHED #ifndef NO_POSIX_SHED
cpu_set_t mask; cpu_set_t mask;
CPU_ZERO( &mask ); CPU_ZERO( &mask );
CPU_SET( tn, &mask ); CPU_SET( tn, &mask );
if ( pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &mask) != 0 ) int err;
#ifndef __ANDROID__
err = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &mask);
#else
err = sched_setaffinity(pthread_self(), sizeof(cpu_set_t), &mask);
#endif
if (err)
{ {
log_it(L_CRITICAL, "Error pthread_setaffinity_np() You really have %d or more core in CPU?", *(int*)arg); log_it(L_CRITICAL, "Error pthread_setaffinity_np() You really have %d or more core in CPU?", *(int*)arg);
abort(); abort();
} }
#endif #endif
#else #else
if ( !SetThreadAffinityMask( GetCurrentThread(), (DWORD_PTR)(1 << tn) ) ) { if ( !SetThreadAffinityMask( GetCurrentThread(), (DWORD_PTR)(1 << tn) ) ) {
log_it( L_CRITICAL, "Error pthread_setaffinity_np() You really have %d or more core in CPU?", tn ); log_it( L_CRITICAL, "Error pthread_setaffinity_np() You really have %d or more core in CPU?", tn );
......
#ifdef _WIN32
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#include <winsock2.h>
#include <windows.h>
#include <mswsock.h>
#include <ws2tcpip.h>
#include <io.h>
#include <wepoll.h>
#include <pthread.h>
#endif
#include "dap_memcached.h"
#include <libmemcached/memcached.h>
#define LOG_TAG "dap_memcached"
static memcached_st *_memc;
static bool _is_module_enable = false;
int dap_memcached_init(const char *server_host, uint16_t port)
{
memcached_return rc;
memcached_server_st *servers = NULL;
char *test_key = "test_key";
char *test_value = "test_value";
_memc = memcached_create(NULL);
servers= memcached_server_list_append(servers, server_host, port, &rc);
rc= memcached_server_push(_memc, servers);
if (rc != MEMCACHED_SUCCESS) {
log_it(L_ERROR, "Couldn't add server: %s", memcached_strerror(_memc, rc));
return -1;
}
if(dap_memcache_put(test_key, test_value, strlen(test_value), 0) != true) {
return -2;
}
_is_module_enable = true;
return 0;
}
bool dap_memcache_is_enable()
{
return _is_module_enable;
}
bool dap_memcache_put(const char* key, void *value, size_t value_size, time_t expiration)
{
memcached_return rc;
rc = memcached_set(_memc, key, strlen(key), value, value_size, expiration, (uint32_t)0);
if (rc != MEMCACHED_SUCCESS) {
log_it(L_ERROR, "%s", memcached_strerror(_memc, rc));
return false;
}
return true;
}
bool dap_memcache_get(const char* key, size_t * value_size, void ** result)
{
memcached_return rc;
*result = memcached_get(_memc, key, strlen(key), value_size, NULL, &rc);
return rc == MEMCACHED_SUCCESS;
}
bool dap_memcache_delete(const char* key)
{
return memcached_delete(_memc, key, strlen(key), 0) == MEMCACHED_SUCCESS;
}
/**
* @brief dap_memcached_deinit
*/
void dap_memcached_deinit()
{
_is_module_enable = false;
}
...@@ -597,7 +597,13 @@ void *thread_loop( void *arg ) ...@@ -597,7 +597,13 @@ void *thread_loop( void *arg )
CPU_ZERO( &mask ); CPU_ZERO( &mask );
CPU_SET( tn, &mask ); CPU_SET( tn, &mask );
if ( pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &mask) != 0 ) { int err;
#ifndef ANDROID
err = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &mask);
#else
err = sched_setaffinity(pthread_self(), sizeof(cpu_set_t), &mask);
#endif
if (err) {
log_it( L_CRITICAL, "Error pthread_setaffinity_np() You really have %d or more core in CPU?", tn ); log_it( L_CRITICAL, "Error pthread_setaffinity_np() You really have %d or more core in CPU?", tn );
abort(); abort();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment