Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
BroadcastCommunity.qnx.com will be offline from May 31 6:00pm until June 2 12:00AM for upcoming system upgrades. For more information please go to https://community.qnx.com/sf/discussion/do/listPosts/projects.bazaar/discussion.bazaar.topc28418
Forum Topic - mq_notify seems only notify once: Page 1 of 3 (3 Items)
   
mq_notify seems only notify once  
#define QUEUE_NAME "/testqueue"

mqd_t queue;

int PulseHandler (message_context_t *ctp, int code, unsigned flags, void *handle)
{
    fprintf(stderr, "Plulse excuted ! \n");
    static char message[256];
    struct mq_attr attr;
   // mqd_t queue = mq_open (QUEUE_NAME, O_RDONLY , S_IRUSR | S_IWUSR, NULL);
    memset(message, 0 , 256);
    memset(&attr, 0, sizeof(attr));
    mq_getattr(queue,&attr);
    
    mq_receive( queue, message, attr.mq_msgsize, NULL );
    fprintf(stderr, "%s \n", message);
    fprintf(stderr, "Plulse excuted finished! \n");
    
    return 0;
}


int main(int argc, char *argv[]) {
    
    struct mq_attr attr;
    dispatch_context_t        *ctp;
    memset(&attr, 0, sizeof(attr));
    attr.mq_maxmsg = 10;
    attr.mq_msgsize = 255;
    queue = mq_open (QUEUE_NAME, O_CREAT |O_EXCL | O_RDONLY , S_IRUSR | S_IWUSR, &attr);
    struct      sigevent event;

    dispatch_t * dpp = dispatch_create();
   
    
    /* Attach a handler function to a pulse code */
    int TimerPulseCode = pulse_attach (dpp, MSG_FLAG_ALLOC_PULSE, 0, PulseHandler, NULL);

    /* Create a connection to a channel that our resource manager is receiving on */
    int SelfCoid = message_connect (dpp, MSG_FLAG_SIDE_CHANNEL);

    /* This macro fills in the event structure */
    SIGEV_PULSE_INIT(&event, SelfCoid, 24, TimerPulseCode, 0);
    mq_notify(  queue, &event );

    /* allocate a context structure */
    ctp = dispatch_context_alloc(dpp);
    while(1) {
        printf("sleep now 11111\n");
        if ( NULL != (ctp = dispatch_block(ctp)) )
        {
            printf("sleep now \n");
            dispatch_handler( ctp );
        }
        else
        {
            printf("errno \n");
            return -1;
        }
            
    }

    
	return EXIT_SUCCESS;
}

See the test code above, it is fine to notify when recive the first message, but after ward notify do not really work.

am i missing anything?