Пример #1
0
void set_multiple_mask (STREAM *h, HANDLE mask[NOFILE])
{
	int i;

	for (i = 0; mask[i] != 0 && i < nfds; i++) {
		if (mask[i] == readev(h)) {
			return ;
		}
	}

	for (i = 0; i < nfds; i++) {
		if (mask[i] == 0) {
			mask [i] = readev(h);
			break;
		}
	}
	if (i == nfds) {
		mask [i-1] = readev(h);
	}
}
Пример #2
0
void unset_multiple_mask (STREAM *h, HANDLE mask[NOFILE])
{
	int i, j;

	for (i = 0; mask[i] != 0 && i < nfds; i++) {
		if (mask [i] == readev(h)) {
			for (j = i+1; mask[j] != 0 && j < NOFILE-1; j++) {
				mask [j-1] = mask[j];
			}
			mask [j - 1] = 0;
			break;
		}
	}
}
Пример #3
0
void
loop() {
	char key[64];
	int value;
	const char *exec = NULL;

	while(run) {
		readev();
		switch(ev.type) {
		case JS_EVENT_BUTTON:
			value = ev.value;
			snprintf(key, sizeof(key),
				"button%d", ev.number);
			break;
		case JS_EVENT_AXIS:
			value = axisvalue(ev.number, ev.value);
			snprintf(key, sizeof(key),
				"axis%d_%s",
				ev.number,
				ev.value < 0 ? "up" : "down");
			break;
		case JS_EVENT_INIT:
		default:
			continue;
		}
		if(value == 0)
			continue;
		else if(mode == DUMP) {
			printf("%s\n", key);
			continue;
		}
		else if(commands && config_setting_lookup_string(commands, key, &exec) == CONFIG_TRUE) {
			system(exec);
		}
	}
}
Пример #4
0
rt_public int net_recv(EIF_PSTREAM cs, char *buf, size_t size
#ifdef EIF_WINDOWS
                       ,BOOL reset
#endif
                      )
/* The connected socket descriptor */
/* Where data are to be stored */
/* Amount of data to be read */
/* Reset event associated with cs reader? */
/* The connected socket descriptor */
/* Where data are to be stored */
/* Amount of data to be read */
{
    /* Read from network */

    volatile size_t len = 0;		/* Total amount of bytes read */

#ifdef EIF_WINDOWS
    DWORD length;			/* Amount read by last system call */
    UINT_PTR timer = 0;
    BOOL fSuccess;
#ifdef USE_ADD_LOG
    add_log(2, "in net_recv");
#endif
#else
    Signal_t (*oldalrm)(int);
    int length;
#endif

    REQUIRE("Valid size", size <= INT32_MAX);

#ifdef EIF_WINDOWS
    if (0 != setjmp(env)) {
        KillTimer (NULL, timer);        /* Stop alarm clock */
        errno = EPIPE;                          /* Signal timeout on read */
        return -1;
    }

    while (len < size) {
        timer = SetTimer(NULL, timer, TIMEOUT*1000, (TIMERPROC) timeout);   /* Give read only TIMEOUT seconds to succeed */
        fSuccess = ReadFile(readfd(cs), buf + len, (DWORD) (size - len), &length, NULL);
        KillTimer (NULL, timer);

        if (fSuccess)
            if (length == 0)        /* connection closed */
                goto closed;
            else
                ;
        else
            return -1;              /* failed */

        len += length;
    }

    if (reset) {
        /* There is a problem when there are 0 bytes t send
         * Literally 0 bytes are sent and the Semaphore is set
         * We need to release the semaphore in this case
         */
        if (size == 0) {
            /* Wait to get back in sync. */
            if (WaitForSingleObject (readev(cs), INFINITE) != WAIT_OBJECT_0) {
#ifdef USE_ADD_LOG
                add_log (8, "network:97 Bad wait");
#endif
            }
        } else {
            if (WaitForSingleObject (readev(cs), 0) != WAIT_OBJECT_0) {
#ifdef USE_ADD_LOG
                add_log (8, "network:101 Wait on %d failed", size);
#endif
            }
        }
    }

    return 0;

closed:

    /* Unlike recv(), we return an error condition with a suitable errno code
     * if possible when and end of file is detected... because we never expect
     * one. Before closing the connection, the remote application should be
     * polite enough to send a 'bye' request and wait for us to receive it.
     */

    errno = EPIPE;				/* connection is broken */
    KillTimer (NULL, timer);	/* stop alarm clock */

    return -1;

#else
    oldalrm = signal(SIGALRM, timeout);	/* Trap SIGALRM within this function */

    if (0 != setjmp(env)) {
        alarm(0);					/* Stop alarm clock */
        signal(SIGPIPE, oldalrm);
        errno = NET_TIMEOUT;		/* Signal timeout on read */
        return -1;
    }


    while (len < size) {

        alarm(TIMEOUT);			/* Give read only TIMEOUT seconds to succeed */
        length = read(readfd(cs), buf + len, size - len);
        alarm(0);

        if (length == 0)	/* connection closed */
            goto closed;

        if (length == -1) {
            if (errno != EINTR) {
                return -1;		/* failed */
            } else {
                length = 0;
            }
        }

        len += length;
    }

    signal(SIGALRM, oldalrm);	/* restore default handler */

    return 0;

closed:

    /* Unlike recv(), we return an error condition with a suitable errno code
     * if possible when and end of file is detected... because we never expect
     * one. Before closing the connection, the remote application should be
     * polite enough to send a 'bye' request and wait for us to receive it.
     */

    errno = NET_BROKEN;			/* conntection is broken */
    alarm(0);					/* stop alarm clock */
    signal(SIGALRM, oldalrm);	/* restore default handler */

    return -1;
#endif
}