草庐IT

c++ - boost::asio 在 async_read 中复制输入数据

coder 2023-09-19 原文

最近从libevent转成boost::asio,一周后发现一个奇怪的现象:当我从客户端读取数据时,有些数据好像是重复的,好像库没有'不必将其标记为已读(或类似的东西)。 我的“读取”方法如下所示:

void client::doRead() {
    delete readBuffer; // getting rid of old data 
    readBuffer = new SerializedBuffer((uint) READ_BUFFER_SIZE);
    readBuffer->position(0);
    asio::async_read(socket, asio::buffer(readBuffer->bytes(), READ_BUFFER_SIZE),
            asio::transfer_at_least(1),
            boost::bind(&client::onRead, shared_from_this(), _1, _2));
}

std::mutex readMutex;
void client::onRead(const asio::error_code &err, size_t nbytes) {
    if (readMutex.try_lock()) {
        if (err) {
            stop();
            return;
        }

        readBuffer->rewind();
        uint limit = (uint) nbytes;
        readBuffer->limit(limit);

        // I've lost hope
        SerializedBuffer *sbuff = new SerializedBuffer(limit);
        memcpy(sbuff->bytes(), readBuffer->bytes(), limit);
        sbuff->limit(limit);

        // that's where I'm checking what I get
        Utils::print(sbuff->bytes(), limit);

        onReceivedData(shared_from_this(), sbuff);
        delete sbuff;
        readMutex.unlock();
    }
}

比如客户端发送的数据是这样的:

<< 38
<< FA 6F 73 ... BE BB

(二进制数据的两次写入)

但是服务器收到:

>> FA
>> FA 6F 73 ... BE BB

'字节'38'在哪里消失了? - 我问自己。
在成功传输 3-4 个数据包后,发生这种情况的概率为 10%。

最佳答案

反模式太多了。

  • 不要使用new/delete
  • 不要使用非 RAII 锁(try_lock 是一种味道)
  • 如果你使用try_lock,处理所有的返回值! (并使用 std::adopt_lock/std::defer_lock)
  • 不要在异步操作中使用锁(asio::io_service::strand 是您所需要的)
  • 除非你需要,否则不要做你自己的缓冲区实现。特别是,当你有像 asio::const_buffer* 这样的很好的抽象时,为什么要键入 print 来获取原始指针 + 大小? Boost 有 string_ref,标准库有 string_view,Asio 有 asio::buffer 工具。
  • 如果您的类有 position()/position(uint) 成员,那么它就是一个准类,您应该只公开成员字段。
  • 只需使 READ_BUFFER_SIZE 无符号(例如 #define RBS 1024u)
  • 使SerializedBuffer正确初始化,而不是在构造后立即要求readBuffer->position(0);

中南合作中心

我知道您使用的是非 boost Asio,但请允许我(因为您确实使用了 boost/bind):

Live On Coliru

#include <boost/asio.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/make_shared.hpp>
#include <boost/bind.hpp>
#include <mutex>
#include <iostream>
#include <iomanip>

#define READ_BUFFER_SIZE 1024

namespace Utils {
    void print(char const* data, size_t n) {
        for (auto it=data; it <data+n; ++it) {
            int v = static_cast<uint8_t>(*it);
            std::cout << std::hex << std::setw(2) << std::setfill('0') << v << " ";
        }
        std::cout << "\n";
    }
}

struct SerializedBuffer {
    std::vector<char> _buf;
    size_t _pos = 0;

    size_t position() const { return _pos; }
    void position(size_t n) { _pos = n; }
    void rewind() { position(0); }
    char* bytes() { return _buf.data(); }

    size_t limit() { return _buf.size(); }
    void limit(size_t n) { _buf.resize(n); }

    SerializedBuffer(size_t n) : _buf(n) {}
};

struct client : boost::enable_shared_from_this<client> {
    client(boost::asio::io_service& svc) : _svc(svc), socket(_svc) {
        socket.connect({boost::asio::ip::address{}, 6767});
    }
    void doRead();

    SerializedBuffer* readBuffer = nullptr;
    void onRead(boost::system::error_code err, size_t nbytes);

    void stop() {
        socket.get_io_service().stop();
    }

    void onReceivedData(boost::shared_ptr<client> This, SerializedBuffer* sb) {
        std::cout << __PRETTY_FUNCTION__ << ": ";
        Utils::print(sb->bytes(), sb->limit());

        doRead();
    }

  private:
    boost::asio::io_service& _svc;
    boost::asio::ip::tcp::socket socket;
};

void client::doRead() {
    delete readBuffer; // getting rid of old data 
    readBuffer = new SerializedBuffer((uint) READ_BUFFER_SIZE);
    readBuffer->position(0);
    boost::asio::async_read(socket, boost::asio::buffer(readBuffer->bytes(), READ_BUFFER_SIZE),
            boost::asio::transfer_at_least(1),
            boost::bind(&client::onRead, shared_from_this(), _1, _2));
}

std::mutex readMutex;
void client::onRead(boost::system::error_code err, size_t nbytes) {
    if (readMutex.try_lock()) {
        if (err) {
            stop();
            return;
        }

        readBuffer->rewind();
        uint limit = (uint) nbytes;
        readBuffer->limit(limit);

        // I've lost hope
        SerializedBuffer *sbuff = new SerializedBuffer(limit);
        memcpy(sbuff->bytes(), readBuffer->bytes(), limit);
        sbuff->limit(limit);

        // that's where I'm checking what I get
        Utils::print(sbuff->bytes(), limit);

        onReceivedData(shared_from_this(), sbuff);
        delete sbuff;
        readMutex.unlock();
    }
}

int main() {
    boost::asio::io_service svc;

    auto c = boost::make_shared<client>(svc);
    c->doRead();

    svc.run();
}

当针对像这样的模拟服务器运行时

(printf '\x38\n'; sleep 3; printf '\xFA\x6F\x73....\xBE\xBB\n') | netcat -l -p 6767

打印

38 0a 
void client::onReceivedData(boost::shared_ptr<client>, SerializedBuffer*): 38 0a 
fa 6f 73 2e 2e 2e 2e be bb 0a 
void client::onReceivedData(boost::shared_ptr<client>, SerializedBuffer*): fa 6f 73 2e 2e 2e 2e be bb 0a 

当然我没有修复内存泄漏:

==31732==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7ff150beffb0 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc7fb0)
    #1 0x41fa58 in client::doRead() /home/sehe/Projects/stackoverflow/test.cpp:63
    #2 0x44150f in client::onReceivedData(boost::shared_ptr<client>, SerializedBuffer*) /home/sehe/Projects/stackoverflow/test.cpp:53
    #3 0x4200a6 in client::onRead(boost::system::error_code, unsigned long) /home/sehe/Projects/stackoverflow/test.cpp:90
    #4 0x454ff0 in void boost::_mfi::mf2<void, client, boost::system::error_code, unsigned long>::call<boost::shared_ptr<client>, boost::system::error_code, unsigned long>(boost::shared_ptr<client>&, void const*, boost::system::error_code&, unsigned long&) const /home/sehe/
    #5 0x4543bc in void boost::_mfi::mf2<void, client, boost::system::error_code, unsigned long>::operator()<boost::shared_ptr<client> >(boost::shared_ptr<client>&, boost::system::error_code, unsigned long) const /home/sehe/custom/boost/boost/bind/mem_fn_template.hpp:286
    #6 0x4532a4 in void boost::_bi::list3<boost::_bi::value<boost::shared_ptr<client> >, boost::arg<1>, boost::arg<2> >::operator()<boost::_mfi::mf2<void, client, boost::system::error_code, unsigned long>, boost::_bi::rrlist2<boost::system::error_code const&, unsigned long 
    #7 0x452465 in void boost::_bi::bind_t<void, boost::_mfi::mf2<void, client, boost::system::error_code, unsigned long>, boost::_bi::list3<boost::_bi::value<boost::shared_ptr<client> >, boost::arg<1>, boost::arg<2> > >::operator()<boost::system::error_code const&, unsigne
    #8 0x44f361 in boost::asio::detail::read_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::asio::mutable_buffers_1, boost::asio::detail::transfer_at_least_t, boost::_bi::bind_t<void, boost::_mfi:
    #9 0x456eb4 in boost::asio::detail::binder2<boost::asio::detail::read_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::asio::mutable_buffers_1, boost::asio::detail::transfer_at_least_t, boost::_
    #10 0x456dd6 in void boost::asio::asio_handler_invoke<boost::asio::detail::binder2<boost::asio::detail::read_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::asio::mutable_buffers_1, boost::asio
    #11 0x456d3a in void boost_asio_handler_invoke_helpers::invoke<boost::asio::detail::binder2<boost::asio::detail::read_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::asio::mutable_buffers_1, bo
    #12 0x456a6e in void boost::asio::detail::asio_handler_invoke<boost::asio::detail::binder2<boost::asio::detail::read_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::asio::mutable_buffers_1, boo
    #13 0x4565ed in void boost_asio_handler_invoke_helpers::invoke<boost::asio::detail::binder2<boost::asio::detail::read_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::asio::mutable_buffers_1, bo
    #14 0x455cdb in boost::asio::detail::reactive_socket_recv_op<boost::asio::mutable_buffers_1, boost::asio::detail::read_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::asio::mutable_buffers_1, b
    #15 0x426f4b in boost::asio::detail::task_io_service_operation::complete(boost::asio::detail::task_io_service&, boost::system::error_code const&, unsigned long) /home/sehe/custom/boost/boost/asio/detail/task_io_service_operation.hpp:38
    #16 0x432dd5 in boost::asio::detail::epoll_reactor::descriptor_state::do_complete(boost::asio::detail::task_io_service*, boost::asio::detail::task_io_service_operation*, boost::system::error_code const&, unsigned long) /home/sehe/custom/boost/boost/asio/detail/impl/epol
    #17 0x426f4b in boost::asio::detail::task_io_service_operation::complete(boost::asio::detail::task_io_service&, boost::system::error_code const&, unsigned long) /home/sehe/custom/boost/boost/asio/detail/task_io_service_operation.hpp:38
    #18 0x4373af in boost::asio::detail::task_io_service::do_run_one(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&, boost::asio::detail::task_io_service_thread_info&, boost::system::error_code const&) /home/sehe/custom/boost/boost/asio/detail/impl/task
    #19 0x435739 in boost::asio::detail::task_io_service::run(boost::system::error_code&) /home/sehe/custom/boost/boost/asio/detail/impl/task_io_service.ipp:149
    #20 0x438804 in boost::asio::io_service::run() /home/sehe/custom/boost/boost/asio/impl/io_service.ipp:59
    #21 0x42024e in main /home/sehe/Projects/stackoverflow/test.cpp:102
    #22 0x7ff14f09d82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Indirect leak of 1024 byte(s) in 1 object(s) allocated from:
    #0 0x7ff150beffb0 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc7fb0)
    #1 0x4537d4 in __gnu_cxx::new_allocator<char>::allocate(unsigned long, void const*) /usr/include/c++/6/ext/new_allocator.h:104
    #2 0x4527bb in std::allocator_traits<std::allocator<char> >::allocate(std::allocator<char>&, unsigned long) /usr/include/c++/6/bits/alloc_traits.h:436
    #3 0x451284 in std::_Vector_base<char, std::allocator<char> >::_M_allocate(unsigned long) /usr/include/c++/6/bits/stl_vector.h:170
    #4 0x4514ea in std::_Vector_base<char, std::allocator<char> >::_M_create_storage(unsigned long) /usr/include/c++/6/bits/stl_vector.h:185
    #5 0x44d8be in std::_Vector_base<char, std::allocator<char> >::_Vector_base(unsigned long, std::allocator<char> const&) /usr/include/c++/6/bits/stl_vector.h:136
    #6 0x4494fc in std::vector<char, std::allocator<char> >::vector(unsigned long, std::allocator<char> const&) /usr/include/c++/6/bits/stl_vector.h:280
    #7 0x440f09 in SerializedBuffer::SerializedBuffer(unsigned long) /home/sehe/Projects/stackoverflow/test.cpp:33
    #8 0x41fa88 in client::doRead() /home/sehe/Projects/stackoverflow/test.cpp:63
    #9 0x44150f in client::onReceivedData(boost::shared_ptr<client>, SerializedBuffer*) /home/sehe/Projects/stackoverflow/test.cpp:53
    #10 0x4200a6 in client::onRead(boost::system::error_code, unsigned long) /home/sehe/Projects/stackoverflow/test.cpp:90
    #11 0x454ff0 in void boost::_mfi::mf2<void, client, boost::system::error_code, unsigned long>::call<boost::shared_ptr<client>, boost::system::error_code, unsigned long>(boost::shared_ptr<client>&, void const*, boost::system::error_code&, unsigned long&) const /home/sehe
    #12 0x4543bc in void boost::_mfi::mf2<void, client, boost::system::error_code, unsigned long>::operator()<boost::shared_ptr<client> >(boost::shared_ptr<client>&, boost::system::error_code, unsigned long) const /home/sehe/custom/boost/boost/bind/mem_fn_template.hpp:286
    #13 0x4532a4 in void boost::_bi::list3<boost::_bi::value<boost::shared_ptr<client> >, boost::arg<1>, boost::arg<2> >::operator()<boost::_mfi::mf2<void, client, boost::system::error_code, unsigned long>, boost::_bi::rrlist2<boost::system::error_code const&, unsigned long
    #14 0x452465 in void boost::_bi::bind_t<void, boost::_mfi::mf2<void, client, boost::system::error_code, unsigned long>, boost::_bi::list3<boost::_bi::value<boost::shared_ptr<client> >, boost::arg<1>, boost::arg<2> > >::operator()<boost::system::error_code const&, unsign
    #15 0x44f361 in boost::asio::detail::read_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::asio::mutable_buffers_1, boost::asio::detail::transfer_at_least_t, boost::_bi::bind_t<void, boost::_mfi
    #16 0x456eb4 in boost::asio::detail::binder2<boost::asio::detail::read_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::asio::mutable_buffers_1, boost::asio::detail::transfer_at_least_t, boost::
    #17 0x456dd6 in void boost::asio::asio_handler_invoke<boost::asio::detail::binder2<boost::asio::detail::read_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::asio::mutable_buffers_1, boost::asio
    #18 0x456d3a in void boost_asio_handler_invoke_helpers::invoke<boost::asio::detail::binder2<boost::asio::detail::read_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::asio::mutable_buffers_1, bo
    #19 0x456a6e in void boost::asio::detail::asio_handler_invoke<boost::asio::detail::binder2<boost::asio::detail::read_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::asio::mutable_buffers_1, boo
    #20 0x4565ed in void boost_asio_handler_invoke_helpers::invoke<boost::asio::detail::binder2<boost::asio::detail::read_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::asio::mutable_buffers_1, bo
    #21 0x455cdb in boost::asio::detail::reactive_socket_recv_op<boost::asio::mutable_buffers_1, boost::asio::detail::read_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp> >, boost::asio::mutable_buffers_1, b
    #22 0x426f4b in boost::asio::detail::task_io_service_operation::complete(boost::asio::detail::task_io_service&, boost::system::error_code const&, unsigned long) /home/sehe/custom/boost/boost/asio/detail/task_io_service_operation.hpp:38
    #23 0x432dd5 in boost::asio::detail::epoll_reactor::descriptor_state::do_complete(boost::asio::detail::task_io_service*, boost::asio::detail::task_io_service_operation*, boost::system::error_code const&, unsigned long) /home/sehe/custom/boost/boost/asio/detail/impl/epol
    #24 0x426f4b in boost::asio::detail::task_io_service_operation::complete(boost::asio::detail::task_io_service&, boost::system::error_code const&, unsigned long) /home/sehe/custom/boost/boost/asio/detail/task_io_service_operation.hpp:38
    #25 0x4373af in boost::asio::detail::task_io_service::do_run_one(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&, boost::asio::detail::task_io_service_thread_info&, boost::system::error_code const&) /home/sehe/custom/boost/boost/asio/detail/impl/task
    #26 0x435739 in boost::asio::detail::task_io_service::run(boost::system::error_code&) /home/sehe/custom/boost/boost/asio/detail/impl/task_io_service.ipp:149
    #27 0x438804 in boost::asio::io_service::run() /home/sehe/custom/boost/boost/asio/impl/io_service.ipp:59
    #28 0x42024e in main /home/sehe/Projects/stackoverflow/test.cpp:102
    #29 0x7ff14f09d82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

SUMMARY: AddressSanitizer: 1056 byte(s) leaked in 2 allocation(s).

修复内存分配

只需使用 unique_ptr 并在需要时移动所有权:

#include <boost/asio.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/make_shared.hpp>
#include <boost/bind.hpp>
#include <mutex>
#include <iostream>
#include <iomanip>

#define READ_BUFFER_SIZE 1024u

namespace Utils {
    void print(char const* data, size_t n) {
        for (auto it=data; it <data+n; ++it) {
            int v = static_cast<uint8_t>(*it);
            std::cout << std::hex << std::setw(2) << std::setfill('0') << v << " ";
        }
        std::cout << "\n";
    }
}

struct SerializedBuffer {
    std::vector<char> _buf;
    size_t _pos = 0;

    size_t position() const { return _pos; }
    void position(size_t n) { _pos = n; }
    void rewind() { position(0); }
    char* bytes() { return _buf.data(); }

    size_t limit() { return _buf.size(); }
    void limit(size_t n) { _buf.resize(n); }

    SerializedBuffer(size_t n) : _buf(n) {}
};

struct client : boost::enable_shared_from_this<client> {
    client(boost::asio::io_service& svc) : _svc(svc), socket(_svc) {
        socket.connect({boost::asio::ip::address{}, 6767});
    }
    void doRead();

    void onRead(boost::system::error_code err, size_t nbytes);

    void stop() {
        socket.get_io_service().stop();
    }

    void onReceivedData(boost::shared_ptr<client> This, std::unique_ptr<SerializedBuffer> sb) {
        std::cout << __PRETTY_FUNCTION__ << ": ";
        Utils::print(sb->bytes(), sb->limit());

        doRead();
    }

  private:
    std::unique_ptr<SerializedBuffer> readBuffer;
    boost::asio::io_service& _svc;
    boost::asio::ip::tcp::socket socket;
};

void client::doRead() {
    readBuffer.reset(new SerializedBuffer(READ_BUFFER_SIZE));
    boost::asio::async_read(socket, boost::asio::buffer(readBuffer->bytes(), READ_BUFFER_SIZE),
            boost::asio::transfer_at_least(1),
            boost::bind(&client::onRead, shared_from_this(), _1, _2));
}

void client::onRead(boost::system::error_code err, size_t nbytes) {
    if (err) {
        stop();
        return;
    }

    readBuffer->rewind();
    readBuffer->limit(nbytes);

    onReceivedData(shared_from_this(), std::move(readBuffer));
}

int main() {
    boost::asio::io_service svc;

    auto c = boost::make_shared<client>(svc);
    c->doRead();

    svc.run();
}

打印:

$ ./sotest 
void client::onReceivedData(boost::shared_ptr<client>, std::unique_ptr<SerializedBuffer>): 38 0a fa 6f 73 2e 2e 2e 2e be bb 0a 

或者

$ ./sotest 
void client::onReceivedData(boost::shared_ptr<client>, std::unique_ptr<SerializedBuffer>): 38 0a 
void client::onReceivedData(boost::shared_ptr<client>, std::unique_ptr<SerializedBuffer>): fa 6f 73 2e 2e 2e 2e be bb 0a 

取决于时间。

关于c++ - boost::asio 在 async_read 中复制输入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45212576/

有关c++ - boost::asio 在 async_read 中复制输入数据的更多相关文章

  1. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

  2. ruby-on-rails - 如何优雅地重启 thin + nginx? - 2

    我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server

  3. ruby CSV : How can I read a tab-delimited file? - 2

    CSV.open(name,"r").eachdo|row|putsrowend我得到以下错误:CSV::MalformedCSVErrorUnquotedfieldsdonotallow\ror\n文件名是一个.txt制表符分隔文件。我是专门做的。我有一个.csv文件,我转到excel,并将文件保存为.txt制表符分隔的文件。所以它是制表符分隔的。CSV.open不应该能够读取制表符分隔的文件吗? 最佳答案 尝试像这样指定字段分隔符:CSV.open("name","r",{:col_sep=>"\t"}).eachdo|row|

  4. ruby - Ruby 有 `Pair` 数据类型吗? - 2

    有时我需要处理键/值数据。我不喜欢使用数组,因为它们在大小上没有限制(很容易不小心添加超过2个项目,而且您最终需要稍后验证大小)。此外,0和1的索引变成了魔数(MagicNumber),并且在传达含义方面做得很差(“当我说0时,我的意思是head...”)。散列也不合适,因为可能会不小心添加额外的条目。我写了下面的类来解决这个问题:classPairattr_accessor:head,:taildefinitialize(h,t)@head,@tail=h,tendend它工作得很好并且解决了问题,但我很想知道:Ruby标准库是否已经带有这样一个类? 最佳

  5. ruby - 我如何添加二进制数据来遏制 POST - 2

    我正在尝试使用Curbgem执行以下POST以解析云curl-XPOST\-H"X-Parse-Application-Id:PARSE_APP_ID"\-H"X-Parse-REST-API-Key:PARSE_API_KEY"\-H"Content-Type:image/jpeg"\--data-binary'@myPicture.jpg'\https://api.parse.com/1/files/pic.jpg用这个:curl=Curl::Easy.new("https://api.parse.com/1/files/lion.jpg")curl.multipart_form_

  6. 世界前沿3D开发引擎HOOPS全面讲解——集3D数据读取、3D图形渲染、3D数据发布于一体的全新3D应用开发工具 - 2

    无论您是想搭建桌面端、WEB端或者移动端APP应用,HOOPSPlatform组件都可以为您提供弹性的3D集成架构,同时,由工业领域3D技术专家组成的HOOPS技术团队也能为您提供技术支持服务。如果您的客户期望有一种在多个平台(桌面/WEB/APP,而且某些客户端是“瘦”客户端)快速、方便地将数据接入到3D应用系统的解决方案,并且当访问数据时,在各个平台上的性能和用户体验保持一致,HOOPSPlatform将帮助您完成。利用HOOPSPlatform,您可以开发在任何环境下的3D基础应用架构。HOOPSPlatform可以帮您打造3D创新型产品,HOOPSSDK包含的技术有:快速且准确的CAD

  7. ruby - 使用 `+=` 和 `send` 方法 - 2

    如何将send与+=一起使用?a=20;a.send"+=",10undefinedmethod`+='for20:Fixnuma=20;a+=10=>30 最佳答案 恐怕你不能。+=不是方法,而是语法糖。参见http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html它说Incommonwithmanyotherlanguages,Rubyhasasyntacticshortcut:a=a+2maybewrittenasa+=2.你能做的最好的事情是:

  8. FOHEART H1数据手套驱动Optitrack光学动捕双手运动(Unity3D) - 2

    本教程将在Unity3D中混合Optitrack与数据手套的数据流,在人体运动的基础上,添加双手手指部分的运动。双手手背的角度仍由Optitrack提供,数据手套提供双手手指的角度。 01  客户端软件分别安装MotiveBody与MotionVenus并校准人体与数据手套。MotiveBodyMotionVenus数据手套使用、校准流程参照:https://gitee.com/foheart_1/foheart-h1-data-summary.git02  数据转发打开MotiveBody软件的Streaming,开始向Unity3D广播数据;MotionVenus中设置->选项选择Unit

  9. 使用canal同步MySQL数据到ES - 2

    文章目录一、概述简介原理模块二、配置Mysql使用版本环境要求1.操作系统2.mysql要求三、配置canal-server离线下载在线下载上传解压修改配置单机配置集群配置分库分表配置1.修改全局配置2.实例配置垂直分库水平分库3.修改group-instance.xml4.启动监听四、配置canal-adapter1修改启动配置2配置映射文件3启动ES数据同步查询所有订阅同步数据同步开关启动4.验证五、配置canal-admin一、概述简介canal是Alibaba旗下的一款开源项目,Java开发。基于数据库增量日志解析,提供增量数据订阅&消费。Git地址:https://github.co

  10. ruby-on-rails - 创建 ruby​​ 数据库时惰性符号绑定(bind)失败 - 2

    我正在尝试在Rails上安装ruby​​,到目前为止一切都已安装,但是当我尝试使用rakedb:create创建数据库时,我收到一个奇怪的错误:dyld:lazysymbolbindingfailed:Symbolnotfound:_mysql_get_client_infoReferencedfrom:/Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundleExpectedin:flatnamespacedyld:Symbolnotfound:_mysql_get_client_infoReferencedf

随机推荐