当前位置: 首页>>代码示例>>C++>>正文


C++ SharedMemory::size方法代码示例

本文整理汇总了C++中SharedMemory::size方法的典型用法代码示例。如果您正苦于以下问题:C++ SharedMemory::size方法的具体用法?C++ SharedMemory::size怎么用?C++ SharedMemory::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SharedMemory的用法示例。


在下文中一共展示了SharedMemory::size方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test_fatfs_write_file_overwrite_expand

static void test_fatfs_write_file_overwrite_expand()
{
    TestFatFS fs;
    FatFileSystem* fat = fs.get();
    Vnode* root = fat->getRoot();
    const char* FILENAME = "MY1.TXT";

    Vnode* found;
    ASSERT_EQ(M_OK, fat->lookup(root, FILENAME, &found, Vnode::REGULAR));

    const int BUFFER_SIZE = 1540;

    SharedMemory* buffer = new SharedMemory(BUFFER_SIZE);
    ASSERT_EQ(M_OK, buffer->map());
    memset(buffer->data(), 0xce, BUFFER_SIZE);
    buffer->data()[0] = 0xca;
    buffer->data()[buffer->size() - 1] = 0xfe;

    io::Context c;
    c.offset = 513;
    c.size   = BUFFER_SIZE;
    c.memory = buffer;

    ASSERT_EQ(BUFFER_SIZE, fat->write(found, &c));

    io::Context readContext;
    SharedMemory* cmi = readAll(fat, readContext, root, FILENAME);
    ASSERT_TRUE(cmi != NULL);
    ASSERT_TRUE(cmi->data() != NULL);
    ASSERT_EQ(2053, cmi->size());
    EXPECT_EQ(0xde, cmi->data()[0]);
    EXPECT_EQ(0xca, cmi->data()[513]);
    EXPECT_EQ(0xfe, cmi->data()[513 + BUFFER_SIZE - 1]);
}
开发者ID:ShotaroTsuji,项目名称:mona,代码行数:34,代码来源:file.cpp

示例2: monapi_clipboard_get

SharedMemory* monapi_clipboard_get()
{
    uint32_t tid ;
    if (monapi_name_whereis("/servers/clipboard", tid) != M_OK) {
        return NULL;
    }

    MessageInfo msg;
    if (Message::sendReceive(&msg, tid, MSG_CLIPBOARD_GET) != M_OK) {
        return NULL;
    }
    if ((intptr_t)msg.arg2 < M_OK) { return NULL;}
    SharedMemory* ret = new SharedMemory(msg.arg2, msg.arg3);
    if (ret->size() == 0) {
        return ret;
    }
    intptr_t mapResult = ret->map(true);
    if (mapResult != M_OK) {
        delete ret;
        monapi_warn("%s map error = %d\n", __func__, mapResult);
        return NULL;
    } else {
        return ret;
    }
}
开发者ID:Nirlendu,项目名称:mona,代码行数:25,代码来源:messages.cpp

示例3: alloc_buffer_size

static SharedMemory* alloc_buffer_size(const char* message, int size)
{
    SharedMemory* buffer = new SharedMemory(size);
    buffer->map();
    memcpy(buffer->data(), message, buffer->size());
    return buffer;
}
开发者ID:ckkashyap,项目名称:mona,代码行数:7,代码来源:clipboard.cpp

示例4: test_fatfs_write_file

static void test_fatfs_write_file()
{
    TestFatFS fs;
    FatFileSystem* fat = fs.get();
    Vnode* root = fat->getRoot();
    const char* FILENAME = "MY1.TXT";

    Vnode* found;
    ASSERT_EQ(M_OK, fat->lookup(root, FILENAME, &found, Vnode::REGULAR));

    const int BUFFER_SIZE = 1029;

    SharedMemory* buffer = new SharedMemory(BUFFER_SIZE);
    ASSERT_EQ(M_OK, buffer->map());
    memset(buffer->data(), 0, BUFFER_SIZE);
    buffer->data()[0] = 0xde;
    buffer->data()[BUFFER_SIZE - 1] = 0xad;

    io::Context c;
    c.offset = 0;
    c.size   = BUFFER_SIZE;
    c.memory = buffer;

    ASSERT_EQ(BUFFER_SIZE, fat->write(found, &c));

    io::Context readContext;
    SharedMemory* cmi = readAll(fat, readContext, root, FILENAME);
    ASSERT_TRUE(cmi != NULL);
    ASSERT_TRUE(cmi->data() != NULL);
    ASSERT_EQ(BUFFER_SIZE, cmi->size());
    EXPECT_TRUE(memcmp(buffer->data(), cmi->data(), BUFFER_SIZE) == 0);
}
开发者ID:ShotaroTsuji,项目名称:mona,代码行数:32,代码来源:file.cpp

示例5: createFile

static void createFile(const char* path)
{
    EXPECT_TRUE(!fileExist(path));
    intptr_t id = monapi_file_open(path, FILE_CREATE);

    const char* message = "Hello World\n";
    SharedMemory shm = alloc_buffer(message);

    monapi_file_write(id, shm, shm.size());

    monapi_file_close(id);
}
开发者ID:ShotaroTsuji,项目名称:mona,代码行数:12,代码来源:ram_disk.cpp

示例6: monapi_clipboard_set

intptr_t monapi_clipboard_set(const SharedMemory& shm)
{
    MessageInfo msg;
    uint32_t tid ;
    if (monapi_name_whereis("/servers/clipboard", tid) != M_OK) {
        return M_NAME_NOT_FOUND;
    }
    intptr_t ret = Message::sendReceive(&msg, tid, MSG_CLIPBOARD_SET, shm.handle(), shm.size());
    if (ret != M_OK) {
        return ret;
    }
    return M_OK;
}
开发者ID:Nirlendu,项目名称:mona,代码行数:13,代码来源:messages.cpp

示例7: send_data

void TcpServer::send_data(SharedMemory& data) {

  try
  {
    write(
        socket_,
        boost::asio::buffer(data.data(), data.size()),
        boost::asio::transfer_at_least(data.size()));
  }
  catch (std::exception& e){
    printf("client disconnected\n");
    accept_connection();
  }
  //  async_write(
  //      socket_,
  //      boost::asio::buffer(data.data(), data.size()),
  //      boost::asio::transfer_at_least(data.size()),
  //      boost::bind(&TcpServer::handle_writer, this,
  //                  boost::asio::placeholders::error,
  //                  boost::asio::placeholders::bytes_transferred,
  //                  data));
}
开发者ID:PascalGohl,项目名称:network_experiments,代码行数:22,代码来源:tcp_server.cpp

示例8: test_fatfs_write_file_overwrite

static void test_fatfs_write_file_overwrite()
{
    TestFatFS fs;
    FatFileSystem* fat = fs.get();
    Vnode* root = fat->getRoot();
    const char* FILENAME = "MY1.TXT";

    Vnode* found;
    ASSERT_EQ(M_OK, fat->lookup(root, FILENAME, &found, Vnode::REGULAR));

    const int BUFFER_SIZE = 10;

    SharedMemory* buffer = new SharedMemory(BUFFER_SIZE);
    ASSERT_EQ(M_OK, buffer->map());
    memset(buffer->data(), 0, BUFFER_SIZE);
    for (int i = 0; i < BUFFER_SIZE; i++) {
        buffer->data()[i] = i;
    }

    io::Context c;
    c.offset = 513;
    c.size   = BUFFER_SIZE;
    c.memory = buffer;

    ASSERT_EQ(BUFFER_SIZE, fat->write(found, &c));

    io::Context readContext;
    SharedMemory* cmi = readAll(fat, readContext, root, FILENAME);
    ASSERT_TRUE(cmi != NULL);
    ASSERT_TRUE(cmi->data() != NULL);
    EXPECT_EQ(0xde, cmi->data()[0]);
    EXPECT_EQ(0xad, cmi->data()[cmi->size() -1]);
    for (int i = 0; i < BUFFER_SIZE; i++) {
        EXPECT_EQ(i, cmi->data()[513 + i]);
    }
}
开发者ID:ShotaroTsuji,项目名称:mona,代码行数:36,代码来源:file.cpp

示例9: Load

    bool Load()
    {
        uint32_t imageSize = 0;
        uint32_t bootstrapSize = getBootstrapSize();
        PEDataList::size_type len = this->list.size();
        for (PEDataList::size_type i = 0; i < len; i++)
        {
            imageSize += this->list[i]->Parser.get_ImageSize();
        }

        imageSize += bootstrapSize;

        SharedMemory* dst = new SharedMemory(imageSize);
        if (dst->map(true) != M_OK)
        {
            delete dst;
            this->Result = 3;
            return false;
        }
        uint32_t addr = 0;
        for (PEDataList::size_type i = 0; i < len; i++)
        {
            PEData* data = this->list[i];
            uint8_t* ptr = &dst->data()[addr];
            if (!data->Parser.Load(ptr))
            {
                if (this->prompt) _printf("%s: can not load: %s\n", SVR, (const char*)data->Name);
#ifdef NO_CACHE
                delete dst;
#endif
                this->Result = 3;
                return false;
            }
            if (i > 0 && !data->Parser.Relocate(ptr, ORG + addr))
            {
                if (this->prompt) _printf("%s: can not relocate: %s\n", SVR, (const char*)data->Name);
#ifdef NO_CACHE
                delete dst;
#endif
                this->Result = 3;
                return false;
            }
            addr += data->Parser.get_ImageSize();
        }
        addr = 0;
        for (PEDataList::size_type i = 0; i < len; i++)
        {
            PEData* data = this->list[i];
            int its = data->Parser.get_ImportTableCount();
            for (int j = 0; j < its; j++)
            {
                CString dll = CString(data->Parser.GetImportTableName(j)).toUpper();
                PEData* target = this->Find(dll);
                if (target == NULL || !data->Parser.Link(&dst->data()[addr], j, &target->Parser))
                {
                    if (this->prompt)
                    {
                        _printf("NG\n");
                        _printf("%s: can not link %s to %s!\n", SVR, (const char*)dll, (const char*)data->Name);
                    }
#ifdef NO_CACHE
                    delete dst;
#endif
                    this->Result = 3;
                    return false;
                }
            }
            addr += data->Parser.get_ImageSize();
        }
        // make bootstrap code
        uint8_t* bootstrap = &dst->data()[dst->size() - bootstrapSize];
        uint8_t* start = &bootstrap[3];
        bootstrap[0] = 0x55; // push ebp
        bootstrap[1] = 0x89; // mov ebp
        bootstrap[2] = 0xE5; // ,esp
        PEDataList::size_type i;
        //char buf[128];
        const uint32_t CALL_CODE_SIZE = 13;

        // dllmain construct
        for (i = 0; i < dlls.size(); i++)
        {
            PEData* dll = dlls[i];
            start[i * CALL_CODE_SIZE] = 0xB8; // mov eax
            *(uint32_t*)(&start[i * CALL_CODE_SIZE + 1]) = dll->Parser.get_EntryPoint(); // ,address
            start[i * CALL_CODE_SIZE + 5] = 0x68; // push
            *(uint32_t*)(&start[i * CALL_CODE_SIZE + 6]) = 0; // 0x00000000 = argument of dllmain
            start[i * CALL_CODE_SIZE + 10] = 0xFF; // call eax
            start[i * CALL_CODE_SIZE + 11] = 0xD0; // call eax
            start[i * CALL_CODE_SIZE + 12] = 0x58; // pop eax
        }
        PEData* exe = list[0];
        start[i * CALL_CODE_SIZE + 0] = 0xB8; // mov eax
        *(uint32_t*)(&start[i * CALL_CODE_SIZE + 1]) = exe->Parser.get_EntryPoint();
        start[i * CALL_CODE_SIZE + 5] = 0xFF;
        start[i * CALL_CODE_SIZE + 6] = 0xD0;
        start = &start[i * CALL_CODE_SIZE + 7];

        // destruct
        for (i = 0; i < dlls.size(); i++)
//.........这里部分代码省略.........
开发者ID:ShotaroTsuji,项目名称:mona,代码行数:101,代码来源:main.cpp


注:本文中的SharedMemory::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。