static void out_complete (io_context_t ctx, struct iocb *iocb, long res, long res2) { int status; if (verbose > 2) fprintf(stderr, "%s uiocb %p status %ld %ld\n", __FUNCTION__, iocb, res, res2); /* fail on all errors we can see. (short reads MAY mask faults.) */ if (res < 0) goto fail; res = empty_out_buf (iocb->u.c.buf, res); if (res < 0) goto fail; /* resubmit */ status = io_submit (ctx, 1, &iocb); if (status == 1) return; fprintf (stderr, "aio read %p resubmit fail, %d (%s)\n", iocb, errno, strerror (errno)); goto clean; fail: errno = -res; fprintf (stderr, "aio read %p fail, %d (%s)\n", iocb, errno, strerror (errno)); clean: aio_out_pending--; return; }
void leave(){ timer_unsubscribe_int(); kb_unsubscribe_int(); mouse_unsubscribe_int(); empty_out_buf(); vg_exit(); highscore_save(); options_save(); exit(0); }
static void *simple_sink_thread (void *param) { char *name = (char *) param; int status; char buf [USB_BUFSIZE]; status = sink_open (name); if (status < 0) return 0; sink_fd = status; /* synchronous reads of endless streams of data */ pthread_cleanup_push (close_fd, &sink_fd); do { /* original LinuxThreads cancelation didn't work right * so test for it explicitly. */ pthread_testcancel (); errno = 0; status = read (sink_fd, buf, sizeof buf); if (status < 0) break; status = empty_out_buf (buf, status); } while (status > 0); if (status == 0) { if (verbose) fprintf (stderr, "done %s\n", __FUNCTION__); } else if (verbose > 2 || errno != ESHUTDOWN) /* normal disconnect */ perror ("read"); fflush (stdout); fflush (stderr); pthread_cleanup_pop (1); return 0; }