Esempio n. 1
0
int
main(int argc, char *argv[])
{
    struct sigevent sev;
    mqd_t mqd;
    struct mq_attr attr;
    void *buffer;
    ssize_t numRead;
    sigset_t blockMask, emptyMask;
    struct sigaction sa;

    if (argc != 2 || strcmp(argv[1], "--help") == 0)
        usageErr("%s mq-name\n", argv[0]);

    mqd = mq_open(argv[1], O_RDONLY | O_NONBLOCK);
    if (mqd == (mqd_t) -1)
        errExit("mq_open");

    if (mq_getattr(mqd, &attr) == -1)
        errExit("mq_getattr");

    buffer = malloc(attr.mq_msgsize);
    if (buffer == NULL)
        errExit("malloc");

    sigemptyset(&blockMask);
    sigaddset(&blockMask, NOTIFY_SIG);
    if (sigprocmask(SIG_BLOCK, &blockMask, NULL) == -1)
        errExit("sigprocmask");

    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0;
    sa.sa_handler = handler;
    if (sigaction(NOTIFY_SIG, &sa, NULL) == -1)
        errExit("sigaction");

    sev.sigev_notify = SIGEV_SIGNAL;
    sev.sigev_signo = NOTIFY_SIG;
    if (mq_notify(mqd, &sev) == -1)
        errExit("mq_notify");

    sigemptyset(&emptyMask);

    for (;;) {
        sigsuspend(&emptyMask);         /* Wait for notification signal */

        if (mq_notify(mqd, &sev) == -1)
            errExit("mq_notify");

        while ((numRead = mq_receive(mqd, buffer, attr.mq_msgsize, NULL)) >= 0)
            printf("Read %ld bytes\n", (long) numRead);

        if (errno != EAGAIN)            /* Unexpected error */
            errExit("mq_receive");
    }
}
Esempio n. 2
0
int main()
{
    char mqname[NAMESIZE];
    mqd_t mqdes;
    struct sigevent notification;
    int pid;
    int status;

    sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid());

    mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0);
    if (mqdes == (mqd_t)-1) {
        perror(ERROR_PREFIX "mq_open");
        return PTS_UNRESOLVED;
    }

    notification.sigev_notify = SIGEV_SIGNAL;
    notification.sigev_signo = SIGUSR1;
    if (mq_notify(mqdes, &notification) != 0) {
        printf("Test FAILED \n");
        mqclean(mqdes, mqname);
        return PTS_FAIL;
    }
    pid = fork();
    if (pid == -1) {
        perror(ERROR_PREFIX "fork");
        mqclean(mqdes, mqname);
        return PTS_UNRESOLVED;
    }
    if (pid == 0) {
        //child process
        if (mq_notify(mqdes, &notification) == -1) {
            if (EBUSY == errno) {
                printf("Test PASSED \n");
                return PTS_PASS;
            }
            else {
                printf("errno != EBUSY \n");
                printf("Test FAILED \n");
                return PTS_FAIL;
            }
        }
        else {
            printf("Test FAILED \n");
            return PTS_FAIL;
        }
    }
    else {
        //parent process
        wait(&status);
        mqclean(mqdes, mqname);
        return status;
    }
}
Esempio n. 3
0
static void my_mq_notify(mqd_t des, struct sigevent *not)
{
	int rv = mq_notify(des, not);

	if (rv < 0) {
		if (errno == ENOMEM) {
			rb_gc();
			rv = mq_notify(des, not);
		}
		if (rv < 0)
			rb_sys_fail("mq_notify");
	}
}
Esempio n. 4
0
int main()
{
	char mqname[NAMESIZE];
        mqd_t mqdes;
        const char s_msg_ptr[MSG_SIZE] = "test message \n";
        struct sigevent notification;
        struct sigaction sa;
        unsigned int prio = 1;

        sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid());
        mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0);
        if (mqdes == (mqd_t)-1) {
                perror(ERROR_PREFIX "mq_open");
                return PTS_UNRESOLVED;
        }
	notification.sigev_notify = SIGEV_SIGNAL;
        notification.sigev_signo = SIGUSR1;
        sa.sa_handler = msg_handler;
        sa.sa_flags = 0;
        sigaction(SIGUSR1, &sa, NULL);
        if (mq_notify(mqdes, &notification) != 0) {
                perror(ERROR_PREFIX "mq_notify");
		mqclean(mqdes, mqname);
                return PTS_UNRESOLVED;
        }
	if (mq_notify(mqdes, NULL) != 0 ) {
		printf("Test FAILED \n");
		mqclean(mqdes, mqname);
		return PTS_FAIL;
	}
        if (mq_send(mqdes, s_msg_ptr, MSG_SIZE, prio) == -1) {
        	perror(ERROR_PREFIX "mq_send");
		mqclean(mqdes, mqname);
        	return PTS_UNRESOLVED;
        }
	sleep(1);
	if (mq_unlink(mqname) != 0) {
               perror(ERROR_PREFIX "mq_unlink");
               return PTS_UNRESOLVED;
	}
        if (!enter_handler) {
		printf("Test PASSED \n");
		mqclean(mqdes, mqname);
		return PTS_PASS;
	}
	else {
		printf("Test FAILED \n");
		mqclean(mqdes, mqname);
		return PTS_FAIL;
	}
}
Esempio n. 5
0
int privateMessageQueueNotificationBySignal(const MessageQueue* messageQueue,
                                            const struct sigevent* sevp)
{
    if (mq_notify(messageQueue->mq_des, sevp) == -1)
    {
        perror("\n\rmq_notify failed !!!\n");

        switch(errno)
        {
            case EBADF:
                perror("The descriptor specified in mqdes is invalid.\n");
                break;
            case EBUSY:
                perror("Another process has already registered to receive notification for this message queue.\n");
                break;
            case EINVAL:
                perror("sevp->sigev_notify is not one of the permitted values; or sevp->sigev_notify is SIGEV_SIGNAL and sevp->sigev_signo is not a valid signal number.\n");
                break;
            case ENOMEM:
                perror("Insufficient memory.\n");
                break;
            default :
                perror("Unknown error\n");
                break;
        }

        return -1;
    }

    return 0;
}
Esempio n. 6
0
int main(void)
{
  mqd_t mqdes;
  struct sigevent sig;
  mq_notify(mqdes, &sig);
  return 0;
}
Esempio n. 7
0
void * th_Robot_alimentation()
{
	printf("Robot alimentation : start\n");
	//struct sigaction act;

	//memset (&act, '\0', sizeof(act));

	/* Use the sa_sigaction field because the handles has two additional parameters */
	//act.sa_sigaction = &receive_sig;

	/* the SA_SIGINFO flag tells sigaction() to use the sa_sigaction field, not sa_handler. */
	//act.sa_flags = SA_SIGINFO;

	//if (sigaction(SIGUSR1, &act, NULL) < 0)
	//	erreur("sigaction robot alim", 1);
	
	//mqd_t mqdes;
	struct sigevent not;

	not.sigev_notify = SIGEV_THREAD;
	not.sigev_notify_function = receive_sig;
	not.sigev_notify_attributes = NULL;
	not.sigev_value.sival_ptr = &messageQueueRobotAl;
	if (mq_notify(messageQueueRobotAl, &not) == -1) {
		perror("robot_al : mq_notify");
		exit(EXIT_FAILURE);
	}
	

	while (1);
}
void prvPosixIPCInterruptHandler( int signal, siginfo_t * data, void * pvParam )
{
union sigval xParameters = data->si_value;
xPipeAndFunction *pxPipes = ( xPipeAndFunction *)xParameters.sival_ptr;
mqd_t hPipeHandle = 0;
void (*vMessageInterruptHandler)(xMessageObject,void*) = NULL;
xMessageObject xRxMessage;
portLONG lMessagesReceived = 0;

	if ( NULL != pxPipes )
	{
		hPipeHandle = pxPipes->hPipe;
		vMessageInterruptHandler = pxPipes->pvFunction;

		memset( &xRxMessage, 0, sizeof( xMessageObject ) );

		if ( NULL != vMessageInterruptHandler )
		{
			while ( ( pdTRUE == lPosixIPCReceiveMessage( hPipeHandle, &xRxMessage ) ) && ( lMessagesReceived++ < MAX_NUMBER_OF_MESSAGES ) )
			{
				vMessageInterruptHandler( xRxMessage, pxPipes->pvContext );
			}
		}

		/* Re-register the notification. */
		if ( 0 != mq_notify( hPipeHandle, &xMessageEvent ) )
		{
			printf( "Failed to install Rx interrupt handler: %d.\n", errno );
		}
	}
	else
	{
		printf( "NULL parameter: Failed to install Rx interrupt handler: %d.\n", errno );
	}
}
Esempio n. 9
0
void test_mq_notify_prototype(void)
{
	mqd_t mqdes;
	struct sigevent *notification;
	int err;

	err = mq_notify(mqdes, notification);

}
Esempio n. 10
0
static void NotifySetup(mqd_t *mqdp) {
    struct sigevent sev;
    sev.sigev_notify = SIGEV_THREAD; /* Notify via thread */
    sev.sigev_notify_function = receive_cb;
    sev.sigev_notify_attributes = NULL;
    sev.sigev_value.sival_ptr = mqdp; /* Argument to threadFunc() */
    if (mq_notify(*mqdp, &sev) == -1){
        LOG_MESSG("%s", "mq_notify");
    }
}
Esempio n. 11
0
int
main(int argc, char **argv)
{
	mqd_t	mqd;
	void	*buff;
	ssize_t	n;
	sigset_t	zeromask, newmask, oldmask;
	struct mq_attr	attr;
	struct sigevent	sigev;

	if (argc != 2)
		err_quit("usage: mqnotifysig2 <name>");

		/* 4open queue, get attributes, allocate read buffer */
	mqd = mq_open(argv[1], O_RDONLY); // 打开message queue
	mq_getattr(mqd, &attr); // 获得queue的属性
	buff = malloc(attr.mq_msgsize); // 分配缓冲区

	sigemptyset(&zeromask);		/* no signals blocked */
	sigemptyset(&newmask);
	sigemptyset(&oldmask);
	sigaddset(&newmask, SIGUSR1); // 增加SIGUSR1 到newmask中

		/* 4establish signal handler, enable notification */
	signal(SIGUSR1, sig_usr1); // 注册SIGUSR1的处理函数
	sigev.sigev_notify = SIGEV_SIGNAL; // 当queue由空变成非空的时候,产生SIGUSR1信号
	sigev.sigev_signo = SIGUSR1;
	mq_notify(mqd, &sigev);

	for ( ; ; ) {
		sigprocmask(SIG_BLOCK, &newmask, &oldmask);	/* block SIGUSR1 *///即不处理SIGUSR1信号
		while (mqflag == 0) // 一直等待mqflag变成非0,否则,解除对SIGUSR1的阻塞,等待它到来。
			sigsuspend(&zeromask); // 临时改变mask,当SIGUSR1的handler返回是,sigsuspend也返回
		mqflag = 0;		/* reset flag */ // 重新设置为0

		mq_notify(mqd, &sigev);			/* reregister first */
		n = mq_receive(mqd, buff, attr.mq_msgsize, NULL);
		printf("read %ld bytes\n", (long) n);
		sigprocmask(SIG_UNBLOCK, &newmask, NULL);	/* unblock SIGUSR1 */
	}
	exit(0);
}
Esempio n. 12
0
int nx_eventnotify(NXHANDLE handle, int signo)
{
  FAR struct nxfe_conn_s *conn = (FAR struct nxfe_conn_s *)handle;
  struct sigevent se;

  se.sigev_notify          = SIGEV_SIGNAL;
  se.sigev_signo           = signo;
  se.sigev_value.sival_ptr = (FAR void *)handle;

  return mq_notify(conn->crdmq, &se);
}
Esempio n. 13
0
int main()
{
	struct mq_attr attr, attr2;
	struct sigevent sigev;
	mqd_t mq;
	int status;

	attr.mq_maxmsg  = 2;
	attr.mq_msgsize = 100;
	mq = mq_open(MQNAME, O_CREAT | O_RDWR | O_EXCL, 0666, &attr);
	if (mq == (mqd_t)-1)
		err(1, "mq_open");
	status = mq_unlink(MQNAME);
	if (status)
		err(1, "mq_unlink");
	status = mq_getattr(mq, &attr2);
	if (status)
		err(1, "mq_getattr");
	if (attr.mq_maxmsg != attr2.mq_maxmsg)
		err(1, "mq_maxmsg changed");
	if (attr.mq_msgsize != attr2.mq_msgsize)
		err(1, "mq_msgsize changed");

	sigev.sigev_notify = SIGEV_SIGNAL;
	sigev.sigev_signo = SIGRTMIN;
	status = mq_notify(mq, &sigev);
	if (status)
		err(1, "mq_notify");
	status = mq_notify(mq, &sigev);
	if (status == 0)
		err(1, "mq_notify 2");
	else if (errno != EBUSY)
		err(1, "mq_notify 3");
	status = mq_notify(mq, NULL);
	if (status)
		err(1, "mq_notify 4");
	status = mq_close(mq);
	if (status)
		err(1, "mq_close");
	return (0);
}
mqd_t xPosixIPCOpen( const portCHAR *pcPipeName, void (*vMessageInterruptHandler)(xMessageObject,void*), void *pvContext )
{
mqd_t hPipeHandle;
struct sigaction sigrt;

	hPipeHandle = mq_open( pcPipeName, O_RDWR | O_CREAT | O_NONBLOCK, S_IRUSR | S_IWUSR, NULL );
	if ( -1 == hPipeHandle )
	{
		hPipeHandle = mq_unlink( pcPipeName );
		hPipeHandle = 0;
		printf( "Problem opening message pipe.\n" );
	}
	else
	{
		printf( "Pipe Open: %s\n", pcPipeName );
	}

	/* If this is a receive pipe then we set-up the interrupt handler. */
	if ( ( 0 != hPipeHandle ) && ( NULL != vMessageInterruptHandler ) )
	{
		/* Establish the signal handler. */
		sigrt.sa_flags = SA_SIGINFO;						/* Need some information to be passed. */
		sigrt.sa_handler = (__sighandler_t)prvPosixIPCInterruptHandler;		/* This is the function to call. */
		sigfillset( &sigrt.sa_mask );
		sigdelset( &sigrt.sa_mask, SIG_MSG_RX );
		sigdelset( &sigrt.sa_mask, SIG_TICK );

		if ( 0 != sigaction( SIG_MSG_RX, &sigrt, NULL ) )	/* Register the Signal Handler. */
		{
			printf( "Problem installing SIG_MSG_RT\n" );
		}		/* Parameters to the signal handler. */

		/* No establish the notify parameters. */
		xActualParameters.hPipe = hPipeHandle;
		xActualParameters.pvFunction = vMessageInterruptHandler;
		xActualParameters.pvContext = pvContext;
		xParameters.sival_ptr = &xActualParameters;

		/* Set-up the notifcation. */
		xMessageEvent.sigev_notify = SIGEV_SIGNAL;				/* How to signal. */
		xMessageEvent.sigev_signo = SIG_MSG_RX;					/* Signal number to use. */
		xMessageEvent.sigev_value = xParameters;				/* Parameters to pass to the signal handler. */
		xMessageEvent.sigev_notify_function = NULL;				/* Signal handler function. */
		xMessageEvent.sigev_notify_attributes = NULL;			/* Parameters if a new thread is created to execute the signal handler. */

		/* Register the notification. */
		if ( 0 != mq_notify( hPipeHandle, &xMessageEvent ) )
		{
			printf( "Failed to install Rx interrupt handler: %d.\n", errno );
		}
	}
	return hPipeHandle;
}
Esempio n. 15
0
void handle_sigusr1(int sig)
{
	mq_notify(mqid, &sigev);
        STU stu;

        unsigned prio;
        if (mq_receive(mqid, (char*)&stu, size, &prio) == (mqd_t)-1)
                ERR_EXIT("mq_receive");

        printf("name=%s age=%d prio=%u\n", stu.name, stu.age, prio);

}
Esempio n. 16
0
static void NotifySetup(mqd_t *mqdp)
{
	struct sigevent sev;
	sev.sigev_notify = SIGEV_THREAD; /* Notify via thread */
	sev.sigev_notify_function = receive_cb_image;
	sev.sigev_notify_attributes = NULL;
	sev.sigev_value.sival_ptr = mqdp; /* Argument to threadFunc() */
	if (mq_notify(*mqdp, &sev) == -1){
		perror("mq_notify");
	}else {
		APP_INFO("NotifySetup Done!\n");
	}
}
Esempio n. 17
0
void mqueue_check_functions(mqd_t m)
{
    (void)mq_close(m);
    (void)mq_getattr(m, (struct mq_attr *)0);
    (void)mq_notify(m, (const struct sigevent *)0);
    (void)mq_open((const char *)0, 0, 0);
    (void)mq_receive(m, (char*)0, (size_t)0, (unsigned*)0);
    (void)mq_send(m, (const char *)0, (size_t)0, (unsigned)0);
    (void)mq_setattr(m, (const struct mq_attr *)0, (struct mq_attr *)0);
    (void)mq_timedreceive(m, (char*)0, (size_t)0, (unsigned*)0, (const struct timespec*)0);
    (void)mq_timedsend(m, (const char *)0, (size_t)0, (unsigned)0, (const struct timespec*)0);
    (void)mq_unlink((const char *)0);
}
Esempio n. 18
0
static void
notifySetup(mqd_t *mqdp)
{
    struct sigevent sev;

    sev.sigev_notify = SIGEV_THREAD;
    sev.sigev_notify_function = threadFunc;
    sev.sigev_notify_attributes = NULL;
    sev.sigev_value.sival_ptr = mqdp;

    if (mq_notify(*mqdp, &sev) == -1)
        errExit("mq_notify");
}
Esempio n. 19
0
int setup_handler(void (*func)(union sigval sv), mqd_t* message_que_descriptor){
  struct sigevent signal_event;

  signal_event.sigev_notify = SIGEV_THREAD;
  signal_event.sigev_notify_function = func;
  signal_event.sigev_notify_attributes = NULL;
  signal_event.sigev_value.sival_ptr = message_que_descriptor;

  if(mq_notify(*message_que_descriptor, &signal_event)==-1){
     handle_error("mq_notify");
  }
  return 0;
}
Esempio n. 20
0
static void notifySetup(mqd_t *mqdp)
{
    struct sigevent sev;

    sev.sigev_notify = SIGEV_THREAD;
    sev.sigev_notify_function = threadFunc;
    sev.sigev_notify_attributes = NULL; // could be a pointer to pthread_attr_t structure
    sev.sigev_value.sival_ptr = mqdp; // argument to threadFunc(). Need to do this so it can reestablish the handler

    if (mq_notify(*mqdp, &sev) == -1) {
        errExit("mq_notify");
    }
}
Esempio n. 21
0
static int _mq_notify_update(struct mq_ctx *ctx, mq_notify_cb cb)
{
    struct sigevent sv;
    memset(&sv, 0, sizeof(sv));
    sv.sigev_notify = SIGEV_THREAD;
    sv.sigev_notify_function = cb;
    sv.sigev_notify_attributes = NULL;
    sv.sigev_value.sival_ptr = ctx;
    if (mq_notify(ctx->mq_rd, &sv) == -1) {//vagrind
        loge("mq_notify failed %d: %s\n", errno, strerror(errno));
        return -1;
    }
    return 0;
}
Esempio n. 22
0
static void
notifySetup(mqd_t *mqdp)
{
    struct sigevent sev;

    sev.sigev_notify = SIGEV_THREAD;            /* Notify via thread */
    sev.sigev_notify_function = threadFunc;
    sev.sigev_notify_attributes = NULL;
            /* Could be pointer to pthread_attr_t structure */
    sev.sigev_value.sival_ptr = mqdp;           /* Argument to threadFunc() */

    if (mq_notify(*mqdp, &sev) == -1)
        errExit("mq_notify");
}
Esempio n. 23
0
void notify_thread(union sigval arg)
{
  int n, prio;

  if (mq_notify(mqd, &sigev) == -1)
  {
    perror("mq notify error");
    exit(1);
  }
  if ((n = mq_receive(mqd, buffer, len, &prio)) == -1)
  {
    perror("receive mq error");
    exit(1);
  }

  printf("SIGUSR1 received, read %d bytes, buffer: %s\n", n, buffer);
}
Esempio n. 24
0
int main()
{
	char qname[NAMESIZE];
	mqd_t queue;
	struct sigevent ev;
	struct sigaction act;
	int failure = 0;

	sprintf(qname, "/mq_open_20-1_%d", getpid());

	queue = mq_open(qname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL);
	if (queue == (mqd_t) -1) {
		perror("mq_open() did not return success");
		printf("Test FAILED\n");
		return PTS_FAIL;
	}

	/* set up notification */
	ev.sigev_notify = SIGEV_SIGNAL;
	ev.sigev_signo = SIGUSR1;
	act.sa_handler = handler;
	act.sa_flags = 0;
	sigemptyset(&act.sa_mask);
	sigaction(SIGUSR1, &act, NULL);
	if (mq_notify(queue, &ev) != 0) {
		perror("mq_notify() did not return success");
		failure = 1;
	}

	mq_close(queue);
	mq_unlink(qname);

	if (failure == 1) {
		printf("Test FAILED\n");
		return PTS_FAIL;
	}

	printf("Test PASSED\n");
	return PTS_PASS;
}
Esempio n. 25
0
static void benchmark_mq_notify(void)
{
  benchmark_timer_t end_time;
  int             status;
  struct sigevent event;

  event.sigev_notify = SIGEV_SIGNAL;
  event.sigev_signo  = SIGUSR1;

  benchmark_timer_initialize();
    status = mq_notify( queue2, &event );
  end_time = benchmark_timer_read();
  rtems_test_assert( status == 0 );

  put_time(
    "mq_notify: only case",
    end_time,
    1,        /* Only executed once */
    0,
    0
  );
}
Esempio n. 26
0
int main()
{
	mqd_t mqdes;
	struct sigevent notification;

	mqdes = (mqd_t) -1;

	notification.sigev_notify = SIGEV_SIGNAL;
	notification.sigev_signo = SIGUSR1;

	if (mq_notify(mqdes, &notification) == -1) {
		if (EBADF == errno) {
			printf("Test PASSED \n");
			return PTS_PASS;
		} else {
			printf("Test FAILED (errno != EBADF)\n");
			return PTS_FAIL;
		}
	}	
	printf("Test FAILED\n");
	return PTS_FAIL;
}
Esempio n. 27
0
int main(int argc, char *argv[])
{
	mqid = mq_open("/abc", O_RDONLY);
	if (mqid == (mqd_t)-1)
		ERR_EXIT("mq_open");	

	struct mq_attr attr;
        mq_getattr(mqid, &attr);
	size = attr.mq_msgsize;

	signal(SIGUSR1, handle_sigusr1);

	sigev.sigev_notify = SIGEV_SIGNAL;
	sigev.sigev_signo = SIGUSR1;

	mq_notify(mqid, &sigev);
	
	for (;;)
		pause();

	mq_close(mqid);
	return 0;
}
Esempio n. 28
0
int main(int argc, char const *argv[])
{
  if (argc != 2)
  {
    fprintf(stderr, "usage: mqnotifysig1 <name>");
    exit(1);
  }

  struct mq_attr attr;

  if ((mqd = mq_open(argv[1], O_RDONLY)) == -1)
  {
    perror("mq open error");
    exit(1);
  }

  mq_getattr(mqd, &attr);
  len = attr.mq_msgsize;
  buffer = malloc(len);
  memset(buffer, 0, len);

  sigev.sigev_notify = SIGEV_THREAD;
  sigev.sigev_value.sival_ptr = NULL;
  sigev.sigev_notify_function = notify_thread;
  sigev.sigev_notify_attributes = NULL;

  if (mq_notify(mqd, &sigev) == -1)
  {
    perror("mq notify error");
    exit(1);
  }

  while (1)
    pause();

  return 0;
}
Esempio n. 29
0
static void notify_function (union sigval sv)
{
        EncoderOutput *encoder_output;
        struct sigevent sev;
        GstClockTime last_timestamp;
        GstClockTime segment_duration;
        gsize size;
        gchar *url, buf[128];

        encoder_output = (EncoderOutput *)sv.sival_ptr;

        /* mq_notify first */
        sev.sigev_notify = SIGEV_THREAD;
        sev.sigev_notify_function = notify_function;
        sev.sigev_notify_attributes = NULL;
        sev.sigev_value.sival_ptr = sv.sival_ptr;
        if (mq_notify (encoder_output->mqdes, &sev) == -1) {
                GST_ERROR ("mq_notify error : %s", g_strerror (errno));
        }

        size = mq_receive (encoder_output->mqdes, buf, 128, NULL);
        if (size == -1) {
                GST_ERROR ("mq_receive error : %s", g_strerror (errno));
                return;
        }
        buf[size] = '\0';
        sscanf (buf, "%lu", &segment_duration);
        last_timestamp = encoder_output_rap_timestamp (encoder_output, *(encoder_output->last_rap_addr));
        url = g_strdup_printf ("%lu.ts", encoder_output->last_timestamp);
        m3u8playlist_add_entry (encoder_output->m3u8_playlist, url, segment_duration);
        if (encoder_output->dvr_duration != 0) {
                dvr_record_segment (encoder_output, segment_duration);
        }
        encoder_output->last_timestamp = last_timestamp;
        g_free (url);
}
Esempio n. 30
0
int main(int argc, char *argv[])
{
	if (argc != 2){
		printf("Usage: mqnotifysig1 <name>\n");
		exit(1);
	}

	if(-1 == (mqd = mq_open(argv[1], O_RDONLY))){
		printf("Can't open mq %s\n", argv[1]);
		exit(1);
	}

	if (-1 == mq_getattr(mqd, &attr)){
		printf("Get mq_attr failed\n");
		exit(1);
	}

	if (NULL == (buff = malloc(attr.mq_msgsize))){
		printf("Alloc buff failed\n");
		exit(1);
	}
	
	signal(SIGUSR1, sig_usr1);
	sigev.sigev_notify = SIGEV_SIGNAL;
	sigev.sigev_signo = SIGUSR1;
	if (-1 == mq_notify(mqd, &sigev)){
		printf("mq_notify failed\n");
		exit(1);
	}

	for (;;){
		pause();
	}

	exit(0);
}