c - zmq_getsockopt returns EINVAL on windows x64 when local address of ZMQ_FD option_val passed -


on windows x64 passing address of local variable zmq_getsockopt zmq_fd consistently results in einval. code below smallest possible reproduce problem.

#include <zmq.h>                                                                                                                                                                                                    #include <stdio.h>                                                                                                                                                                                                   void zmq_perror(const char*);                                                                                                                                                                                        int main(void)                                                                                                                                                                                                      {                                                                                                                                                                                                                       const char *endpoint = "tcp://127.0.0.1:7100";                                                                                                                                                                       void *ctx    = zmq_ctx_new();                                                                                                                                                                                       if (ctx == null) { zmq_perror("zmq_ctx_new"); }                                                                                                                                                                      void *socket = zmq_socket(ctx, zmq_dealer);                                                                                                                                                                         if (socket == null) { zmq_perror("zmq_socket"); }                                                                                                                                                                    int rc;                                                                                                                                                                                                              rc = zmq_connect(socket, endpoint);                                                                                                                                                                                 if ( rc == -1 ) { zmq_perror("zmq_connect"); }                                                                                                                                                                        /*** results in einval ***/                                                                                                                                                                                                                    int fd;                                                                                                                                                                                                           size_t fd_size = sizeof (fd);                                                                                                                                                                                     rc = zmq_getsockopt(socket, zmq_fd, &fd, &fd_size);                                                                                                                                                               if (rc == -1) { zmq_perror("zmq_getsockopt"); }                                                                                                                                                                     /*** works without issue ***/     /*                                                                                                                                                                                                                int *fd        = malloc(sizeof(int));                                                                                                                                                                               size_t fd_size = sizeof (fd);                                                                                                                                                                                       rc = zmq_getsockopt(socket, zmq_fd, fd, &fd_size);                                                                                                                                                                  if (rc == -1) { zmq_perror("zmq_getsockopt"); }       */                                                                                                                                                               }                                                                                                                                                                                                                    void zmq_perror(const char *f)                                                                                                                                                                                      {                                                                                                                                                                                                                       fprintf(stderr, "%s: %s\n", f, zmq_strerror(zmq_errno()));                                                                                                                                                          abort();                                                                                                                                                                                                        } 

running above using first (manpage) form produces:

zmq_getsockopt: invalid argument 

however second, commented out form using malloc has no issues. makes 0 sense me since passing address of local variable zmq_getsockopt legal.

this problem manifests 64 bit binaries on windows; 32 bit binaries on windows or 64 bit binaries on linux have no issue.

it seems issue zmq_fd socket option. zmq_type , zmq_sndhwm worked without issue.

is there weird behavior related zmq_fd on windows x64 i'm not aware of?

update

so noticed "working" code erroneous.

sizeof(fd) 

is taking sizeof pointer in second form. in fact, has nothing malloc, once change sizeof(int) should einval again:

/* fail */ int *fd        = malloc(sizeof(int));                                                                                                                                                                           size_t fd_size = sizeof(int);                                                                                                                                                                                   rc = zmq_getsockopt(socket, zmq_fd, fd, &fd_size);                                                                                                                                                              if (rc == -1) { zmq_perror("zmq_getsockopt"); } 

it turns out apparently need use 64bit integer type zmq_fd on windows x64

/* success! */ uint64_t fd;                                                                                                                                                                                                    size_t fd_size = sizeof(uint64_t);                                                                                                                                                                              rc = zmq_getsockopt(socket, zmq_fd, &fd, &fd_size);                                                                                                                                                             if (rc == -1) { zmq_perror("zmq_getsockopt"); } 

this confusing since api zmq_getsockopt int. bug? windows eccentricity? me being dense?

relevant addendum:

zmq version: 3.2.3

compiler: cross compiled using mingw-w64, rubenvb-4.8.0 build both 64bit , 32bit binaries

os: windows 7

the zmq_getsockopt man page says,

option value type int on posix systems, socket on windows


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -