Skip to content

Commit

Permalink
Merge pull request zeromq#4148 from bluca/vmci
Browse files Browse the repository at this point in the history
Problem: VMCI build broken
  • Loading branch information
bluca authored Feb 23, 2021
2 parents 4ecb045 + 4bb9a4c commit bd5f5a1
Show file tree
Hide file tree
Showing 13 changed files with 256 additions and 310 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ matrix:
packages:
- valgrind
- libgnutls-dev
- env: BUILD_TYPE=default CURVE=libsodium GSSAPI=enabled PGM=enabled NORM=enabled
- env: BUILD_TYPE=default CURVE=libsodium GSSAPI=enabled PGM=enabled NORM=enabled VMCI=enabled
os: linux
addons:
apt:
Expand Down
26 changes: 13 additions & 13 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -1024,19 +1024,19 @@ endif
endif

if HAVE_VMCI
test_apps += test_pair_vmci test_reqrep_vmci

test_pair_vmci_SOURCES = tests/test_pair_vmci.cpp
test_pair_vmci_LDADD = ${TESTUTIL_LIBS} src/libzmq.la
test_pair_vmci_CPPFLAGS = ${TESTUTIL_CPPFLAGS}
test_pair_vmci_LDFLAGS = @LIBZMQ_VMCI_LDFLAGS@
test_pair_vmci_CXXFLAGS = @LIBZMQ_VMCI_CXXFLAGS@

test_reqrep_vmci_SOURCES = tests/test_reqrep_vmci.cpp
test_reqrep_vmci_LDADD = ${TESTUTIL_LIBS} src/libzmq.la
test_reqrep_vmci_CPPFLAGS = ${TESTUTIL_CPPFLAGS}
test_reqrep_vmci_LDFLAGS = @LIBZMQ_VMCI_LDFLAGS@
test_reqrep_vmci_CXXFLAGS = @LIBZMQ_VMCI_CXXFLAGS@
test_apps += tests/test_pair_vmci tests/test_reqrep_vmci

tests_test_pair_vmci_SOURCES = tests/test_pair_vmci.cpp
tests_test_pair_vmci_LDADD = ${TESTUTIL_LIBS} src/libzmq.la
tests_test_pair_vmci_CPPFLAGS = ${TESTUTIL_CPPFLAGS}
tests_test_pair_vmci_LDFLAGS = @LIBZMQ_VMCI_LDFLAGS@
tests_test_pair_vmci_CXXFLAGS = @LIBZMQ_VMCI_CXXFLAGS@

tests_test_reqrep_vmci_SOURCES = tests/test_reqrep_vmci.cpp
tests_test_reqrep_vmci_LDADD = ${TESTUTIL_LIBS} src/libzmq.la
tests_test_reqrep_vmci_CPPFLAGS = ${TESTUTIL_CPPFLAGS}
tests_test_reqrep_vmci_LDFLAGS = @LIBZMQ_VMCI_LDFLAGS@
tests_test_reqrep_vmci_CXXFLAGS = @LIBZMQ_VMCI_CXXFLAGS@

endif

Expand Down
10 changes: 10 additions & 0 deletions config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,14 @@ function set_config_opts() {
if [ -n "$FORCE_98" ] && [ "$FORCE_98" = "enabled" ]; then
CONFIG_OPTS+=("--enable-force-CXX98-compat=yes")
fi

if [ -n "$VMCI" ] && [ "$VMCI" = "enabled" ]; then
CONFIG_OPTS+=("--with-vmci=$PWD/vmci")
# VMWare headeers are not ISO C++ compliant
CONFIG_OPTS+=("--disable-pedantic")
git clone --depth 1 https://github.com/vmware/open-vm-tools.git
mkdir -p vmci
# Linux headers are redefined, so we can't just add -I to the whole dir
cp open-vm-tools/open-vm-tools/lib/include/vmci_* vmci/
fi
}
21 changes: 21 additions & 0 deletions src/vmci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
*/
#include "precompiled.hpp"

#include "ip.hpp"
#include "vmci.hpp"
#include "vmci_address.hpp"

#if defined ZMQ_HAVE_VMCI

Expand Down Expand Up @@ -97,4 +99,23 @@ void zmq::tune_vmci_connect_timeout (ctx_t *context_,
#endif
}

zmq::fd_t zmq::vmci_open_socket (const char *address_,
const zmq::options_t &options_,
zmq::vmci_address_t *out_vmci_addr_)
{
// Convert the textual address into address structure.
int rc = out_vmci_addr_->resolve (address_);
if (rc != 0)
return retired_fd;

// Create the socket.
fd_t s = open_socket (out_vmci_addr_->family (), SOCK_STREAM, 0);

if (s == retired_fd) {
return retired_fd;
}

return s;
}

#endif
4 changes: 4 additions & 0 deletions src/vmci.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ void tune_vmci_connect_timeout (ctx_t *context_,
fd_t sockfd_,
struct timeval timeout_);
#endif

fd_t vmci_open_socket (const char *address_,
const options_t &options_,
vmci_address_t *out_vmci_addr_);
}

#endif
Expand Down
20 changes: 15 additions & 5 deletions src/vmci_address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@

#include "err.hpp"

zmq::vmci_address_t::vmci_address_t ()
{
memset (&address, 0, sizeof address);
}

zmq::vmci_address_t::vmci_address_t (ctx_t *parent_) : parent (parent_)
{
memset (&address, 0, sizeof address);
Expand All @@ -56,10 +61,6 @@ zmq::vmci_address_t::vmci_address_t (const sockaddr *sa,
memcpy (&address, sa, sa_len);
}

zmq::vmci_address_t::~vmci_address_t ()
{
}

int zmq::vmci_address_t::resolve (const char *path_)
{
// Find the ':' at end that separates address from the port number.
Expand Down Expand Up @@ -125,7 +126,7 @@ int zmq::vmci_address_t::resolve (const char *path_)
return 0;
}

int zmq::vmci_address_t::to_string (std::string &addr_)
int zmq::vmci_address_t::to_string (std::string &addr_) const
{
if (address.svm_family != parent->get_vmci_socket_family ()) {
addr_.clear ();
Expand Down Expand Up @@ -164,4 +165,13 @@ socklen_t zmq::vmci_address_t::addrlen () const
return static_cast<socklen_t> (sizeof address);
}

#if defined ZMQ_HAVE_WINDOWS
unsigned short zmq::vmci_address_t::family () const
#else
sa_family_t zmq::vmci_address_t::family () const
#endif
{
return parent->get_vmci_socket_family ();
}

#endif
11 changes: 7 additions & 4 deletions src/vmci_address.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,28 @@ namespace zmq
class vmci_address_t
{
public:
vmci_address_t ();
vmci_address_t (ctx_t *parent_);
vmci_address_t (const sockaddr *sa, socklen_t sa_len, ctx_t *parent_);
~vmci_address_t ();

// This function sets up the address for VMCI transport.
int resolve (const char *path_);

// The opposite to resolve()
int to_string (std::string &addr_);
int to_string (std::string &addr_) const;

#if defined ZMQ_HAVE_WINDOWS
unsigned short family () const;
#else
sa_family_t family () const;
#endif
const sockaddr *addr () const;
socklen_t addrlen () const;

private:
struct sockaddr_vm address;
ctx_t *parent;

vmci_address_t ();

ZMQ_NON_COPYABLE_NOR_MOVABLE (vmci_address_t)
};
}
Expand Down
Loading

0 comments on commit bd5f5a1

Please sign in to comment.