Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7662011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:41:37+00:00 2026-05-31T13:41:37+00:00

I’m attempting to integrate zeromq into a glib main loop, but I can’t figure

  • 0

I’m attempting to integrate zeromq into a glib main loop, but I can’t figure out why my program is segfault’ing.

Here’s the function that guarantees a segfault after also running g_main_loop_run(loop):

/** set poll fn to operate on zmq or unix sockets */
g_main_context_set_poll_func( g_context, (GPollFunc) zmq_poll );

I thought this would work, considering that zmq_poll shares the same structure as poll, and calling this same function with s/zmq_poll/poll/ works fine.

Stripped version of my code with it still segfault’ing: http://paste.pocoo.org/show/568289/.

(untested) Full version: http://paste.pocoo.org/show/568292/.

Stacktrace:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6a2bd50 in ?? ()
   from /usr/lib/libzmq.so.1
(gdb) bt
#0  0x00007ffff6a2bd50 in ?? ()
   from /usr/lib/libzmq.so.1
#1  0x00007ffff6a34b4d in zmq_getsockopt ()
   from /usr/lib/libzmq.so.1
#2  0x00007ffff6a34e1b in zmq_poll ()
   from /usr/lib/libzmq.so.1
#3  0x00007ffff6c89dc8 in ?? ()
   from /usr/lib/libglib-2.0.so.0
#4  0x00007ffff6c8a5f2 in g_main_loop_run ()
  from /usr/lib/libglib-2.0.so.0
#5  0x0000000000402978 in main (argc=1, 
argv=0x7fffffffe5e8) at server.c:229

Compile the code (assuming you have gstreamer and zeromq installed) with:

gcc --debug `pkg-config gstreamer-0.10 --libs` -lzmq `pkg-config gstreamer-0.10 --cflags` -o test test.c

What am I doing wrong?

Any and all help is appreciated, thanks.

EDIT: Got it to work with what alexander suggested by using this function as my poll replacement:

gint zmq_poll_adapter(GPollFD *ufds, guint nfsd, gint timeout_)
{
    zmq_pollitem_t ufds0[nfsd];
    int i;
    for (i = 0; i < nfsd; i++)
    {
        ufds0[i].socket = NULL;
        ufds0[i].fd = ufds[i].fd;
        ufds0[i].events = ufds[i].events;
        ufds0[i].revents = ufds[i].revents;
    }
    zmq_poll(ufds0, nfsd, timeout_);
}

To be honest I’m not even sure how this worked as well as it did, but I’m a C newbie and have little idea how to make a more adaptive adapt().

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:41:38+00:00Added an answer on May 31, 2026 at 1:41 pm

    Expected data format for GPollFunc callback is

    struct GPollFD {
    #if defined (G_OS_WIN32) && GLIB_SIZEOF_VOID_P == 8
      gint64 fd;
    #else
      gint      fd;
    #endif
      gushort   events;
      gushort   revents;
    };
    

    Expected data format for zmq_poll is

    typedef struct
    {
        void //*socket//;
        int //fd//;
        short //events//;
        short //revents//;
    } zmq_pollitem_t;
    

    The solution is to write adapter and pass it to g_main_context_set_poll_func:

    gint zmq_poll_adapter(GPollFD *ufds, guint nfsd, gint timeout_)
    {
        zmq_pollitem_t *ufds0 = adapt(ufds, nfsd);
        zmq_poll(ufds0, nfsd, timeout_);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.