Example #1
0
void read_cb(ev_loop *loop, ev_io *watcher, int revents)
{
	char buf[BUF_SIZE];
	ssize_t buf_cnt;

	LDAPMessage_t *req = NULL;
	asn_dec_rval_t rdecode;

	if (EV_ERROR & revents)
		fail("got invalid event");

	bzero(buf, sizeof(buf));
	buf_cnt = recv(watcher->fd, buf, sizeof(buf), 0);

	if (buf_cnt <= 0) {
		ev_close(loop, watcher);
		if (buf_cnt < 0)
			fail("read");
		return;
	}

	/* from asn1c's FAQ: If you want data to be BER or DER encoded, just invoke der_encode(). */
	rdecode = asn_DEF_LDAPMessage.ber_decoder(0, &asn_DEF_LDAPMessage, (void **)&req, buf, buf_cnt, 0);

	if (rdecode.code != RC_OK || (ssize_t) rdecode.consumed != buf_cnt) {
		ev_close(loop, watcher);
		ldapmessage_free(req);
		fail((rdecode.code != RC_OK) ? "der_decoder" : "consumed");
	}

	LDAP_DEBUG(req);
	switch (req->protocolOp.present) {
	case LDAPMessage__protocolOp_PR_bindRequest:
		ldap_bind(req->messageID, &req->protocolOp.choice.bindRequest, loop, watcher);
		break;
	case LDAPMessage__protocolOp_PR_searchRequest:
		ldap_search(req->messageID, &req->protocolOp.choice.searchRequest, loop, watcher);
		break;
	case LDAPMessage__protocolOp_PR_unbindRequest:
		ev_close(loop, watcher);
		break;
	default:
		perror("_|_");
		ev_close(loop, watcher);
	}
	ldapmessage_free(req);
}
Example #2
0
int main(int argc, char **argv)
{
    signed int keygrabber;
    uint32_t ev;

    if (argc < 2) {
        fprintf(stderr, "usage: managerui /dev/input/eventX\n");
        return EXIT_FAILURE;
    }

    keygrabber = ev_open(argv[1]);
    if (keygrabber < 0) {
        fprintf(stderr, "Cannot open event file\n");
        return EXIT_FAILURE;
    }

    if (daemon(0, 0) != 0) {
        fprintf(stderr, "Cannot fork into background\n");
        return EXIT_FAILURE;
    }

    while (1) {
        ev = ev_read(keygrabber);
        if (EV_FAIL(ev)) {
            if (EV_GETERROR(ev) == EV_EBLOCK)
                continue;
            else
                break;
        }
        switch (EV_GETCODE(ev)) {
        case 225:
            if (EV_HASFLAG(ev, EV_UP))
                system("setbacklight %+10");
            break;
        case 224:
            if (EV_HASFLAG(ev, EV_UP))
                system("setbacklight %-10");
            break;
        default:
            break;
        }
    }

    ev_close(keygrabber);
    return EXIT_SUCCESS;
}
Example #3
0
ssize_t ldap_send(LDAPMessage_t *msg, ev_loop *loop, ev_io *watcher)
{
	char buf[BUF_SIZE];
	ssize_t buf_cnt;
	asn_enc_rval_t rencode;

	LDAP_DEBUG(msg);

	bzero(buf, sizeof(buf));
	rencode = der_encode_to_buffer(&asn_DEF_LDAPMessage, msg, &buf, sizeof(buf));
	buf_cnt = write(watcher->fd, buf, rencode.encoded);

	if (rencode.encoded != buf_cnt) {
		ev_close(loop, watcher);
		perror("ldap_send");
		return -1;
	}
	return buf_cnt;
}
Example #4
0
File: pyext.c Project: pzread/sdup
static PyObject* pyext_epoll_free(PyObject *self,PyObject *args){
    khiter_t hit;

    int epfd;
    struct pyep_data *pyep;

    if(!PyArg_ParseTuple(args,"i",&epfd)){
        PyErr_BadArgument();
        return NULL;
    }
    if((pyep = pyep_getby_epfd(epfd)) == NULL){
        PyErr_SetString(PyExc_KeyError,"epoll file descriptor not found");
        return NULL;
    }

    if(ev_close(&pyep->evdata)){
        PyErr_SetString(PyExc_SystemError,"epoll free failed");
        return NULL;
    }

    for(hit = kh_begin(pyep->evhdr_ht);hit != kh_end(pyep->evhdr_ht);hit++){
        if(kh_exist(pyep->evhdr_ht,hit)){
            free((struct ev_header*)kh_value(pyep->evhdr_ht,hit));
        }
    }
    
    kh_destroy(ptr,pyep->evhdr_ht);

    hit = kh_get(ptr,pyep_ht,epfd);
    kh_del(ptr,pyep_ht,hit);
    
    free(pyep);

    Py_INCREF(Py_None);
    return Py_None;
}
Example #5
0
/*!

Destroy event loop.

*/
void core_destroy() {
    ev_close(core_evdata);

    INFO("Destroyed.\n");
}