Transition* trans_new(State *dest){ Transition *trans = NULL; if((trans = (Transition *) calloc(1, sizeof(Transition))) == NULL){ dbg_e("Error on malloc() the new transition'", NULL); goto end; } trans->dest = dest; state_ref(dest); trans->clistnext = trans; trans->clistprev = trans; trans->raction = NULL; end: return trans; }
State* state_new(struct reactor_d *reactor, const char* id){ State *ste = NULL; if ((ste = (State *) calloc(1, sizeof(State))) == NULL) { dbg_e("Error on malloc() the state '%s'", id); goto end; } ste->id = strdup(id); ste->refcount = 0; reactor_hash_table_insert(reactor->states, ste->id, ste); end: return ste; }
int memory_request(struct memory *mem, size_t address, void *n, int size, int convert, gclock_t *cycles) { if((( address) + size) > mem->len) { dbg_e("Memory request out of bounds (%ld + %d > %ld)", address, size, mem->len); return -EFAULT; } memcpy(n, PMEMORY_DATA(mem) + address, size); if(convert) { swap_bytes(n, size); } return 0; }
int memory_write(struct memory *mem, size_t address, void *n, int size, int convert, gclock_t *cycles) { if((( address) + size) > mem->len) { dbg_e("Memory request out of bounds (%ld + %d > %ld)", address, size, mem->len); return -EFAULT; } if(convert) { swap_bytes(n, size); } if((address >= 0xC00000) && (address <= 0xDFFFFF)) { static int vdp_write_count = 0; dbg_i("Write: VDP @ 0x%x (%d)\n", address, ++vdp_write_count); } memcpy(PMEMORY_DATA(mem) + address, n, size); return 0; }
static void attend_remote_events(int sfd, short ev, void *arg) { // int s, // *nsfd; // pthread_t t1; // if((nsfd = malloc(sizeof(int))) == NULL){ // dbg_e("Error on malloc() the remote socket file descriptor", NULL); // return; // } // *nsfd = sfd; // s = pthread_create(&t1, NULL, attend_remote_events_thread, (void *) nsfd); // if(s != 0) // dbg("Unable to create the thread to receive the events", strerror(s)); struct sockaddr addr; char ip[INET6_ADDRSTRLEN]; int psfd, addrlen = sizeof(struct sockaddr); RSList *eids; RSList *eidsp; ip[0] = NULL; if((psfd = accept(sfd, &addr, &addrlen)) == -1) { dbg_e("Unable to stablish connection with remote reactord", NULL); } else inet_ntop(addr.sa_family, &addr, ip, INET6_ADDRSTRLEN); if((eids = receive_remote_events(psfd)) == NULL) { goto end; } for(eidsp = eids; eidsp != NULL; eidsp = reactor_slist_next(eidsp)) { reactor_event_handler(&reactor, eidsp->data); } end: while(eids != NULL) { free(eids->data); eids = reactor_slist_delete_link(eids, eids); } close(psfd); }