Ejemplo n.º 1
0
/*----------------------------------------------------------------------------
  Thread 1 'phaseA': Phase A output
 *---------------------------------------------------------------------------*/
void phaseA (void const *argument) {
  for (;;) {
    osSignalWait(0x0001, osWaitForever);    /* wait for an event flag 0x0001 */
    LED_on (LED_A);
    signal_func (tid_phaseB);               /* call common signal function   */
    LED_off(LED_A);
  }
}
Ejemplo n.º 2
0
Archivo: Blinky.c Proyecto: mad-et/ex
/*----------------------------------------------------------------------------
 *      Thread 4 'phaseD': Phase D output
 *---------------------------------------------------------------------------*/
void phaseD (void  const *argument) {
  for (;;) {
    osSignalWait(0x0001, osWaitForever);    /* wait for an event flag 0x0001 */
    Switch_On (LED_D);
    signal_func(tid_phaseA);                /* call common signal function   */
    Switch_Off(LED_D);
  }
}
Ejemplo n.º 3
0
/*----------------------------------------------------------------------------
 *        Task 3 'phaseC': Phase C output
 *---------------------------------------------------------------------------*/
__task void phaseC (void) {
  for (;;) {
    os_evt_wait_and (0x0001, 0xffff);    /* wait for an event flag 0x0001    */
    LED_On (LED_C);
    signal_func (t_phaseD);              /* call common signal function      */
    LED_Off(LED_C);
  }
}
Ejemplo n.º 4
0
int main(int argc, char const *argv[])
{
    if (argc < 2) {
        printf("Usage: %s <port>\n", argv[0]);
        return 1;
    }

    int port = atoi(argv[1]);

    struct sockaddr_in addr;
    memset(&addr, 0, sizeof(addr));
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = htonl(INADDR_ANY);
    addr.sin_port = htons(port);

    int ret;
    int sock = socket(AF_INET, SOCK_STREAM, 0);
    ASSERT(sock > 0);
    ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr));
    ASSERT(ret == 0);
    ret = listen(sock, 5);
    ASSERT(ret == 0);

    signal(SIGINT, signal_func);

    gettimeofday(&g_bgn, NULL);

    socklen_t addr_len = sizeof(addr);
    ret = accept(sock, (struct sockaddr*)&addr, &addr_len);
    ASSERT(ret > 0);
    sock = ret;

    gettimeofday(&g_bgn, NULL);

    char msg[65536];
    for (;;) {
        ret = recv(sock, msg, sizeof(msg), 0);
        ASSERT(ret >= 0);
        if (ret == 0)
            signal_func(0);
        g_bytes += ret;
        g_call ++;
    }

    return 0;
}
Ejemplo n.º 5
0
Double_t SPEFunc(Double_t* x, Double_t* params)
{
  return signal_func(x, params) + background_func(x,params);
}
int main(int argc, char *argv[])
{
	/* conbine socket and bind and listen */
	int lisfd;
	lisfd = create_lisfd();
/* choise select or siganl for operation */
#define SELECT_SIGNAL_FLAG	1
#if SELECT_SIGNAL_FLAG
	/* set nonbloc for listen file descriptor */
	int opt;
	opt = fcntl_func(lisfd, F_GETFL, 0);
	fcntl_func(lisfd, F_SETFL, opt | O_NONBLOCK);
	/* set received buffer size */
	int recvbufsize = 1024;
	setsockopt_func(lisfd, SOL_SOCKET, SO_RCVBUF, &recvbufsize, sizeof(recvbufsize));
	/* waiting for connect of client */
	fd_set accset;
	FD_ZERO(&accset);
	FD_SET(lisfd, &accset);
	select_func(lisfd + 1, &accset, NULL, NULL, NULL);
#endif
	/* accept */
	confd = accept(lisfd, NULL, NULL);
/* choise select or siganl for operation */
#if SELECT_SIGNAL_FLAG
	int en = 1;
	signal_func(SIGURG, sig_urg);
	fcntl_func(confd, F_SETOWN, getpid());
	char buf[1024];
	int i = 0;
	for ( ; ; )
	{
		bzero(buf, sizeof(buf));
		if ((recv_func(confd, buf, sizeof(buf), 0)) == 0)
		{
			fprintf(stdout, "client close \n");
			close(confd);
			confd = -1;
			break;
		}
		fprintf(stdout, "%d :normal data buf :%s\n", ++i, buf);
		sleep(1);
	}
#else
	char buf[1024];
	fd_set rset;
	fd_set xset;
	FD_ZERO(&rset);
	FD_ZERO(&xset);
	int i = 0;
	int n = 0;
	for ( ; ; )
	{
		FD_SET(confd, &rset);
		FD_SET(confd, &xset);
		select_func(confd + 1, &rset, NULL, &xset, NULL);
		if (FD_ISSET(confd, &rset))
		{
			bzero(buf, sizeof(buf));
			if ((recv_func(confd, buf, sizeof(buf), 0)) == 0)
			{
				fprintf(stdout, "client close\n");
				close(confd);
				confd = -1;
				break;
			}
			fprintf(stdout, "this select operated %d :buf: %s\n", ++i, buf);
		}
		if (FD_ISSET(confd, &xset))
		{
			bzero(buf, sizeof(buf));
			/* enforce set not in first byte of buffer */
			buf[0] = 'x';
			n = recv_func(confd, buf, sizeof(buf), MSG_OOB);
			/* not urgent data also return 1 */
			fprintf(stdout, "n:%d\n", n);
			/* show recv buf content, already buf[0] rewritten */
			fprintf(stdout, "is urgent data :%s\n", buf);
		}
		sleep(1);
	}
#endif
	close(confd);
	close(lisfd);
	
	
	return 0;
}