[zeromq-dev] ZMQ vs SPI: FD shenanigans

Olaf Mandel o.mandel at menlosystems.com
Tue Jan 20 14:35:38 CET 2015


I was trying to use ZMQ in a C++ program that also uses the STL to open
regular files and that uses the open(2) and ioctl(2) syscalls of the
Linux kernel for SPI communication (on an ARM platform). For certain
combinations of opening and closing a regular file and binding to a TCP
or Inproc socket, a subsequent ioctl call fails with either "No such
device" or "Resource temporarily unavailable".

My first guess is that somehow ZMQ is messing up the file descriptors it
uses, but I am certainly not ready to rule out bugs in the STL, Kernel
or (least probably): my own code  :-)

Could anyone give me a suggestion on how continue debugging this?

This is my demo code of the problem. The code uses the C++ binding for
ZMQ (cppzmq) for brevity, but it should work the same for the native C

#include <sys/ioctl.h>
#include <zmq.hpp>

//#define ADDR "tcp://"
#define ADDR "inproc://addr"

 *  The program works fine if D is present and it shows the problem if
 *  D is commented out for the following permutations of the blocks:
 *  - A B C D
 *  - A C B D
 *  - C A B D
 *  The program always shows the problem (independent of the presence
 *  of D) for the following permutations of the blocks:
 *  - A C D B
 *  - C A D B
 *  - C D A B
 *  With the constraint that A must be before B and C before D, there
 *  are no further valid permutations.
 *  For the TCP address, the error message is: No such device
 *  For the inproc address, it is: Resource temporarily unavailable
int main()
    zmq::context_t ctx;                    /* A */

    zmq::socket_t skt(ctx, ZMQ_PUB);       /* B */

    std::fstream fs("log", std::ios::out); /* C */

    fs.close();                            /* D */

    /* The following always last */
    int fd = open("/dev/spidev32766.0", O_RDWR);
    struct spi_ioc_transfer pcks;
    memset(&pcks, 0, sizeof(struct spi_ioc_transfer));
    ioctl(fd, SPI_IOC_MESSAGE(1), &pcks);
    std::cout << "errno: " << strerror(errno) << std::endl;

    return 0;

Thank you for any suggestion,
Olaf Mandel
Olaf Mandel
phone: +49-89-189166-250
fax:   +49-89-189166-111
Menlo Systems GmbH
Am Klopferspitz 19a, D-82152 Martinsried
Amtsgericht München HRB 138145
Geschäftsführung: Dr Michael Mei, Dr Ronald Holzwarth
USt-IdNr. DE217772017, St.-Nr. 14316170324

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20150120/7fb35583/attachment.sig>

More information about the zeromq-dev mailing list