#StackBounty: #c++ #boost #boost-python How to create a numpy array of boost::python::object types

Bounty: 200

I’m trying to create a 2×2 numpy array of python objects:

#include <boost/python.hpp>
#include <boost/python/numpy.hpp>
int main()
{
    Py_Initialize();
    boost::python::numpy::initialize();
    boost::python::tuple shape = boost::python::make_tuple(2, 2);
    boost::python::object obj;
    boost::python::numpy::dtype dt = boost::python::numpy::dtype(obj);
    boost::python::numpy::ndarray array = boost::python::numpy::empty(shape, dt);
    std::cout << "Datatype is: " << boost::python::extract<char const *> boost::python::str(array.get_dtype())) << std::endl;
}

But the output is "Datatype is: float64" rather than a python object type.

What am I doing wrong?

I suspect I’m misusing the dtype constructor.


Get this bounty!!!

#StackBounty: #apt #c++ #cmake #g++ #boost Trying to build with boost filesystem: relocation … can not be used when making a shared o…

Bounty: 100

Ubuntu 18.04, boost 1.65, g++ 7.5.0, cmake 3.10.2, GNU make 4.1. Pretty much everything at the default version for ubuntu 18.04.

I’m trying to port software that uses a number of different boost components to an NVidia Jetson TX2 board… which uses the aforementioned version of ubuntu on it’s dev board and host machine.

The hurdle I’m trying to clear at the moment is that linking the first shared lib in cmake: add_library(<name> SHARED ...) fails in g++ with the error from the title. The ‘blah blah blah’ portion mentions a specific entry point within boost filesystem.

I conclude that I need to rebuild boost filesystem with the requested build flags, -fPIC.

Do I need to download the boost source directly and rebuild it, or can I do something with the apt installed -dev boost module[s]?

I’ll also need to cross compile them for arm (currently on amd64) so any advice there would be welcome too, but mostly just trying to get boost to link here.


Get this bounty!!!

#StackBounty: #c++ #asynchronous #boost #tcp #asio Async sending and receiving custom data packets with boost?

Bounty: 50

I am trying to asynchronously send and receive custom data packets with boost and I have some questions, based on my current implementation:

tcpclient.cpp

#include "tcpclient.h"
#include <boost/chrono.hpp>
#include "../utils/logger.h"

tcpclient::tcpclient(std::string host, int port) :
        _endpoint(boost::asio::ip::address::from_string(host), port), _socket(_ioservice) {

    logger::log_info("Initiating client ...");
}

void tcpclient::start() {
    connect();
    _ioservice.run();
}

void tcpclient::connect() {
    _socket.async_connect(_endpoint, std::bind(&tcpclient::connect_handler, this, std::placeholders::_1));
}

void tcpclient::receive() {
    boost::asio::async_read(_socket, boost::asio::buffer(data, HEADER_LEN), std::bind(&tcpclient::read_handler, this, std::placeholders::_1));
}

void tcpclient::connect_handler(const boost::system::error_code &error) {
    if (!error) {
        _status = CONNECTED;
        logger::log_info("Connected to " + get_remote_address_string());
        receive();
    } else {
        _status = NOT_CONNECTED;
        _socket.close();
        _timer.expires_from_now(boost::asio::chrono::seconds{2});
        _timer.async_wait(std::bind(&tcpclient::reconnect_handler, this, std::placeholders::_1));
        logger::log_info("Failed to connect");
    }
}

void tcpclient::reconnect_handler(const boost::system::error_code &error) {
    connect();
}

void tcpclient::read_handler(const boost::system::error_code& error, std::size_t bytes_transferred)
{
    logger::log_info("reading some data?");
}


std::string tcpclient::get_remote_address_string() {
    return _socket.remote_endpoint().address().to_string() + ":" + std::to_string(_socket.remote_endpoint().port());
}

tcpclient.h

#include <string>
#include <boost/asio.hpp>


enum ConnectionStatus{
    NOT_CONNECTED,
    CONNECTED
};


class tcpclient {

public:

    tcpclient(std::string host, int port);

    void start();

    void connect();

private:

    ConnectionStatus _status = NOT_CONNECTED;

    const int HEADER_LEN = 0x01;

    void receive();

    void connect_handler(const boost::system::error_code& error);

    void reconnect_handler(const boost::system::error_code &error);

    void read_handler(const boost::system::error_code& error);

    std::string get_remote_address_string();


    boost::asio::io_service _ioservice;
    boost::asio::ip::tcp::endpoint _endpoint;
    boost::asio::ip::tcp::socket _socket;
    boost::asio::steady_timer _timer{_ioservice, boost::asio::chrono::seconds{2}};

};

1) Would it make sense to add two seperate handlers for reading and writing, one for the header one for the body?

2) How can I ensure that I can send and receive data at the same time without running into any issues? Does this require multiple sockets? How is such functionality usually implemented?

3) How would I go sending custom data structures? I want to implement a custom packet structure. How would I sent such objects, does boost have an inbuilt serializer? How or custom data structures sent and received?

4) What happens if the connection drops during sending or receiving data? Are such exceptions handled directly in the receive/send handlers by checking the errorcode object for eof?

A basic example for that would help a lot!


Get this bounty!!!