mirror of
https://gitee.com/openharmony/xts_dcts
synced 2025-02-20 00:47:41 +00:00
意见修改
Signed-off-by: songdawei <songdawei1@huawei.com>
This commit is contained in:
parent
7c13caaf85
commit
c1711a9096
@ -16,11 +16,10 @@
|
||||
#include "shm_utils.h"
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
const int MAX_DATA_LENGTH = 1024;
|
||||
const int PERMISSION = 0666;
|
||||
const int CODE_HEAD = 4;
|
||||
const int STR_KEY = 5;
|
||||
const int CODE_LEN = 5;
|
||||
const int SHARED_DATA_LEN = 5;
|
||||
const int WAITTIME = 2;
|
||||
const int DECIM_TEN = 10;
|
||||
@ -34,14 +33,14 @@ static int shmid; //共享内存标识符
|
||||
int createShm(int key)
|
||||
{
|
||||
//创建共享内存
|
||||
shmid = shmget(static_cast(key_t)key, sizeof(struct shared_use_st), PERMISSION|IPC_CREAT);
|
||||
shmid = shmget(static_cast<key_t>(key), sizeof(struct shared_use_st), PERMISSION|IPC_CREAT);
|
||||
if(shmid == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
//将共享内存连接到当前进程的地址空间
|
||||
shm = shmat(shmid,nullptr,0);
|
||||
if(shm == reinterpret_cast(void*)-1)
|
||||
if(shm == reinterpret_cast<void*>(-1))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@ -88,9 +87,7 @@ int waitDataWithCode(char* code, char* data)
|
||||
{
|
||||
int i = 0;
|
||||
int timeout = 10;
|
||||
char str[1024] = {0};
|
||||
memset_s(str, MAX_DATA_LENGTH, 0, MAX_DATA_LENGTH);
|
||||
|
||||
char str[MAX_DATA_LENGTH] = {0};
|
||||
if (code == nullptr || data == nullptr)
|
||||
{
|
||||
return -1;
|
||||
@ -116,9 +113,7 @@ int waitDataWithCode(char* code, char* data)
|
||||
int writeCodeDataToShm(int code, char*buf)
|
||||
{
|
||||
char str[1024] = {0};
|
||||
memset_s(str, MAX_DATA_LENGTH, 0, MAX_DATA_LENGTH);
|
||||
char codeStr[5] = {0};
|
||||
memset_s(codeStr, CODE_LEN, 0, CODE_LEN);
|
||||
char* str2 = Int2String(code, codeStr);
|
||||
if (str2 == nullptr)
|
||||
{
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include <sys/time.h>
|
||||
#include <sys/shm.h>
|
||||
|
||||
const int MAX_DATA_LENGTH =1024;
|
||||
#define MAX_WAIT_TIMEOUT 10
|
||||
#define SHM_SEND_KEY 123456
|
||||
#define SHM_RECV_KEY 123466
|
||||
@ -35,7 +34,7 @@ const int MAX_DATA_LENGTH =1024;
|
||||
struct shared_use_st
|
||||
{
|
||||
int written;//作为一个标志,非0:表示可读,0表示可写
|
||||
char data[MAX_DATA_LENGTH];//记录写入和读取的文本
|
||||
char data[1024];//记录写入和读取的文本
|
||||
};
|
||||
|
||||
#define LOG(format, ...) \
|
||||
|
@ -48,8 +48,8 @@ typedef enum{
|
||||
} CtrlCodeType;
|
||||
|
||||
const int MAX_DATA_LENGTH = 1024;
|
||||
const int DEFDELTA = 0.00001;
|
||||
const int ERRNOT_OK = 0;
|
||||
const double DEFDELTA = 0.00001;
|
||||
const int CODE_LEN_TEN = 10;
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::DistributedKv;
|
||||
@ -133,8 +133,13 @@ void DistributedKvDataManagerTest::SetUp(void)
|
||||
RemoveAllStore(DisKvTest::manager);
|
||||
// 2.远端删除数据库
|
||||
char* str =(char *)malloc(MAX_DATA_LENGTH);
|
||||
memset_s(str,MAX_DATA_LENGTH,0,MAX_DATA_LENGTH);
|
||||
strcpy_s(str, strlen("")+1,"");
|
||||
if (str==nullptr)
|
||||
{
|
||||
std::cout <<"ERROR: str malloc failed"<< std::endl;
|
||||
return;
|
||||
}
|
||||
memset_s(str, MAX_DATA_LENGTH, 0, MAX_DATA_LENGTH);
|
||||
strcpy_s(str, strlen("") + 1, "");
|
||||
writeCodeDataToShm(CTRL_CODE_DATAMGR_DELETE_KV, str);
|
||||
|
||||
char code[CODE_LEN_TEN] = {"9999"};
|
||||
@ -145,9 +150,11 @@ void DistributedKvDataManagerTest::SetUp(void)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
errno_t errRes = strcpy_s(code, strlen(str)+1, str);
|
||||
if (errRes != ERRNOT_OK){
|
||||
return
|
||||
errno_t eret = strcpy_s(code, strlen(str)+1, str);
|
||||
if (eret!=EOK)
|
||||
{
|
||||
std::cout <<"ERROR: memcpy_s failed, eret = "<< eret << std::endl;
|
||||
return;
|
||||
}
|
||||
memset_s(str,MAX_DATA_LENGTH,0,MAX_DATA_LENGTH);
|
||||
waitDataWithCode(code, str);
|
||||
@ -161,7 +168,7 @@ void DistributedKvDataManagerTest::SetUp(void)
|
||||
// 2. 远端创建数据库
|
||||
str =(char *)malloc(MAX_DATA_LENGTH);
|
||||
memset_s(str,MAX_DATA_LENGTH,0,MAX_DATA_LENGTH);
|
||||
strcpy_s(str, strlen("")+1,"");
|
||||
strcpy_s(str, strlen("") + 1, "");
|
||||
writeCodeDataToShm(CTRL_CODE_DATAMGR_CREATE_KV, str);
|
||||
|
||||
memset_s(str,MAX_DATA_LENGTH,0,MAX_DATA_LENGTH);
|
||||
@ -171,9 +178,11 @@ void DistributedKvDataManagerTest::SetUp(void)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
errno_t errRes = strcpy_s(code, strlen(str)+1, str);
|
||||
if (errRes != ERRNOT_OK){
|
||||
return
|
||||
eret = strcpy_s(code, strlen(str)+1, str);
|
||||
if (eret!=EOK)
|
||||
{
|
||||
std::cout << "ERROR: memcpy_s failed, eret = " << eret << std::endl;
|
||||
return;
|
||||
}
|
||||
waitDataWithCode(code, str);
|
||||
free(str);
|
||||
|
@ -28,12 +28,13 @@
|
||||
using namespace OHOS::DistributedKv;
|
||||
using namespace std;
|
||||
|
||||
const int DEFDELTA = 0.00001;
|
||||
const double DEFDELTA = 0.00001;
|
||||
const int MAX_DATA_LENGTH = 1024;
|
||||
const int NUMTHREE = 3;
|
||||
const int STR_VALUE = 23;
|
||||
const int RESULR_TWO = 2;
|
||||
const int CODE_LEN_TEN = 10;
|
||||
const int RESULT_OK = 0;
|
||||
const int RESULT_ERR = 1;
|
||||
|
||||
class DisKvTest {
|
||||
public:
|
||||
@ -94,8 +95,7 @@ char* getRealData(char* str, char* delims)
|
||||
|
||||
void getParam(char* putData, char ret[] [MAX_DATA_LENGTH])
|
||||
{
|
||||
char str[MAX_DATA_LENGTH] = {":"};
|
||||
memset_s(str, MAX_DATA_LENGTH, 0, MAX_DATA_LENGTH);
|
||||
char str[MAX_DATA_LENGTH] = {0};
|
||||
if (putData == nullptr)
|
||||
{
|
||||
return;
|
||||
@ -286,7 +286,7 @@ int processGetData(char* putData)
|
||||
char result[NUMTHREE][MAX_DATA_LENGTH] = {{0}, {0}, {0}};
|
||||
memset_s(result, NUMTHREE*MAX_DATA_LENGTH, 0, NUMTHREE*MAX_DATA_LENGTH);
|
||||
getParam(putData, result);
|
||||
for (int i=0; i<NUMTHREE; i++)
|
||||
for (int i = 0; i<NUMTHREE; i++)
|
||||
{
|
||||
LOG("for result[i] %s", result[i]);
|
||||
}
|
||||
|
@ -27,10 +27,6 @@
|
||||
#include "distributed_kv_data_manager.h"
|
||||
#include <sys/time.h>
|
||||
|
||||
const int MAX_DATA_LENGTH = 1024;
|
||||
const int RESULT_OK = 0;
|
||||
const int RESULT_ERR = 1;
|
||||
|
||||
typedef enum{
|
||||
CTRL_CODE_SOFTBUS_TYPE = 1000,
|
||||
CTRL_CODE_SOFTBUS_OPEN_SESSION,
|
||||
@ -77,6 +73,6 @@ int processPutData(char* putData);
|
||||
int processCreateKv(char* putData);
|
||||
int processDeleteKv(char* putData);
|
||||
char* getRealData(char* str, char* delims);
|
||||
void getParam(char* str, char ret[] [MAX_DATA_LENGTH]);
|
||||
void getParam(char* str, char ret[] [1024]);
|
||||
void initKvstoreId(void);
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user