Ejemplo n.º 1
0
int
io_readline(int fd, char *buffer, size_t size)
{
	int nr = 0;
	char c;

	while (nr < size && read_nonblock(fd, &c, 1) > 0 && c != '\n')
		buffer[nr++] = c;

	return nr;
}
Ejemplo n.º 2
0
static void monitor_replies(struct sched_ent *alarm)
{
  if (config.debug.dnahelper) {
    DEBUGF("sched_replies.poll.fd=%d .revents=%s",
	sched_replies.poll.fd,
	strbuf_str(strbuf_append_poll_events(strbuf_alloca(40), sched_replies.poll.revents))
      );
  }
  assert(alarm == &sched_replies);
  if (sched_replies.poll.revents & POLLIN) {
    size_t remaining = reply_buffer + sizeof reply_buffer - reply_bufend;
    ssize_t nread = read_nonblock(sched_replies.poll.fd, reply_bufend, remaining);
    if (nread > 0) {
      char *bufp = reply_buffer;
      char *readp = reply_bufend;
      reply_bufend += nread;
      char *nl;
      while (nread > 0 && (nl = srv_strnstr(readp, nread, "\n"))) {
	size_t len = nl - bufp + 1;
	if (discarding_until_nl) {
	  if (config.debug.dnahelper)
	    DEBUGF("Discarding %s", alloca_toprint(-1, bufp, len));
	  discarding_until_nl = 0;
	} else {
	  handle_reply_line(bufp, len);
	}
	readp = bufp = nl + 1;
	nread = reply_bufend - readp;
      }
      if (bufp != reply_buffer) {
	size_t len = reply_bufend - bufp;
	memmove(reply_buffer, bufp, len);
	reply_bufend = reply_buffer + len;
      } else if (reply_bufend >= reply_buffer + sizeof reply_buffer) {
	WHY("DNAHELPER reply buffer overrun");
	if (config.debug.dnahelper)
	  DEBUGF("Discarding %s", alloca_toprint(-1, reply_buffer, sizeof reply_buffer));
	reply_bufend = reply_buffer;
	discarding_until_nl = 1;
      }
    }
  }
  if (sched_replies.poll.revents & (POLLHUP | POLLERR | POLLNVAL)) {
    if (config.debug.dnahelper)
      DEBUGF("DNAHELPER closing stdout fd=%d", dna_helper_stdout);
    close(dna_helper_stdout);
    dna_helper_stdout = -1;
    unwatch(&sched_replies);
    sched_replies.poll.fd = -1;
    dna_helper_kill();
  }
}
Ejemplo n.º 3
0
void rhizome_client_poll(struct sched_ent *alarm)
{
  rhizome_http_request *r = (rhizome_http_request *)alarm;
  if (alarm->poll.revents == 0){
    rhizome_server_free_http_request(r);
    return;
  }
  switch(r->request_type)
    {
    case RHIZOME_HTTP_REQUEST_RECEIVING:
      /* Keep reading until we have two CR/LFs in a row */
      r->request[r->request_length] = '\0';
      sigPipeFlag=0;
      int bytes = read_nonblock(r->alarm.poll.fd, &r->request[r->request_length], RHIZOME_HTTP_REQUEST_MAXLEN - r->request_length);
      /* If we got some data, see if we have found the end of the HTTP request */
      if (bytes > 0) {
	// reset inactivity timer
	r->alarm.alarm = gettime_ms() + RHIZOME_IDLE_TIMEOUT;
	r->alarm.deadline = r->alarm.alarm + RHIZOME_IDLE_TIMEOUT;
	unschedule(&r->alarm);
	schedule(&r->alarm);
	r->request_length += bytes;
	if (http_header_complete(r->request, r->request_length, bytes + 4)) {
	  /* We have the request. Now parse it to see if we can respond to it */
	  rhizome_server_parse_http_request(r);
	}
      } else {
	if (debug & DEBUG_RHIZOME_TX)
	  DEBUG("Empty read, closing connection");
	rhizome_server_free_http_request(r);
	return;
      }
      if (sigPipeFlag) {
	if (debug & DEBUG_RHIZOME_TX)
	  DEBUG("Received SIGPIPE, closing connection");
	rhizome_server_free_http_request(r);
	return;
      }
      break;
    default:
      /* Socket already has request -- so just try to send some data. */
      rhizome_server_http_send_bytes(r);
      break;
  }
  return;
}
Ejemplo n.º 4
0
static void monitor_errors(struct sched_ent *alarm)
{
  if (debug & DEBUG_DNAHELPER) {
    DEBUGF("sched_errors.poll.fd=%d .revents=%s",
	sched_errors.poll.fd,
	strbuf_str(strbuf_append_poll_events(strbuf_alloca(40), sched_errors.poll.revents))
      );
  }
  if (sched_errors.poll.revents & POLLIN) {
    char buffer[1024];
    ssize_t nread = read_nonblock(sched_errors.poll.fd, buffer, sizeof buffer);
    if (nread > 0)
      WHYF("DNAHELPER stderr %s", alloca_toprint(-1, buffer, nread));
  }
  if (sched_errors.poll.revents & (POLLHUP | POLLERR | POLLNVAL)) {
    if (debug & DEBUG_DNAHELPER)
      DEBUGF("DNAHELPER closing stderr fd=%d", dna_helper_stderr);
    close(dna_helper_stderr);
    dna_helper_stderr = -1;
    unwatch(&sched_errors);
    sched_errors.poll.fd = -1;
  }
}
Ejemplo n.º 5
0
int read( int fd, void *buffer, size_t nbytes )
{
    if( (stdin_flags&O_NONBLOCK)==O_NONBLOCK )  return read_nonblock(fd, buffer, nbytes);
    else                                        return read_block(fd, buffer, nbytes );
}
Ejemplo n.º 6
0
void process_keys()
{
    int tst;
    char inp;

    tst = read_nonblock( 0, &inp, 1 );
    if( tst == 0 || inp == 0 ) return;

    switch( inp )
    {
    case 'l':   laplace3_run = !laplace3_run; break;
    case 'd':   dct_run = !dct_run; break;
    case 'x':   idct_run = !idct_run; break;
    case 'r':   rotate_run = !rotate_run; break;
    case '5':   laplace5_run = !laplace5_run; break;
    case 'z':   sharpen_run = !sharpen_run; break;
    case 's':   sobel_run = !sobel_run; break;
    case 'b':   blur_run = !blur_run; break;
    case 'p':   pixelate_run = !pixelate_run; break;
    case 'e':   emboss_run = !emboss_run; break;
    case 'h':   histogram_run = !histogram_run; break;
    case 'q':   histogram_eq_run = !histogram_eq_run; break;
    case '!':   hw_not_sw = !hw_not_sw; break;
    case 'n':   invert_run = !invert_run; break;
    case 'i':   intensity_waveform_run = !intensity_waveform_run; break;
    case 'u':   uv_mapping_run = !uv_mapping_run; break;
    case 'o':   hough_run = !hough_run; break;
    case 'f':   frame_limit_run = !frame_limit_run; break;
    case 'm':   median_run = !median_run; break;
    case 't':   thresh_run = !thresh_run; break;
    case 'g':   gray_run = !gray_run; break;
    case 'c':   contrast_run = !contrast_run; break;
    case '[':   median_win -= 2; if( median_win < 3 ) median_win = 3; break;
    case ']':   median_win += 2; if( median_win > 9 ) median_win = 9; break;
    case ',':   low_line++; high_line--; break;
    case '.':   low_line--; high_line++; break;
    case '-':   low_line--; high_line--; break;
    case '=':   low_line++; high_line++; break;
    case '0':   thresh_val++; if( thresh_val > 255 ) thresh_val = 255; break;
    case '9':   thresh_val--; if( thresh_val < 0 ) thresh_val = 0; break;
    case '1':   sharpen_val--; if( sharpen_val < 1 ) sharpen_val = 1; break;
    case '2':   sharpen_val++; if( sharpen_val > 255 ) sharpen_val = 255; break;
    case ')':   angle--;  if (angle < 0) angle = 0; /*sang = sin( M_PI/180.0 * angle ); cang = cos( M_PI/180.0 * angle );*/ break;
    case '(':   angle++;  if (angle > 360) angle = 0;/* sang = sin( M_PI/180.0 * angle ); cang = cos( M_PI/180.0 * angle );*/ break;
    case ';':   fps--; break;
    case '\'':  fps++; break;

    case 27:   
        rotate_run = 0;
        histogram_run = 0;
        intensity_waveform_run = 0;
        laplace3_run = 0;
        laplace5_run = 0;
        frame_limit_run = 0;
        sharpen_run = 0;
        sobel_run = 0;
        blur_run = 0;
        pixelate_run = 0;
        gray_run = 0;
        median_run = 0;
        contrast_run = 0;
        invert_run = 0;
        dct_run = 0;
        idct_run = 0;
        histogram_eq_run = 0;
        uv_mapping_run = 0;
        hough_run = 0;
        emboss_run = 0;
        low_line = 20;
        high_line = 40;
        thresh_val = 128;
        thresh_run = 0;
        fps = 30;
        angle = 45;
        hw_not_sw = 0;
        break;

    case '\\':
        stream_show( streams );
        break;

    case 8:     
    case 127:
        printf("Filter                  Key      Enabled \n");
        printf("-------------------------------------------------------\n");
        printf("laplace 3x3             l        %d\n",laplace3_run);
        printf("laplace 5x5             5        %d\n",laplace5_run);
        printf("sharpen                 z        %d\n",sharpen_run);
        printf("invert                  n        %d\n",invert_run);
        printf("sobel                   s        %d\n",sobel_run);
        printf("blur                    b        %d\n",blur_run);
        printf("pixelate                p        %d\n",pixelate_run);
        printf("emboss                  e        %d\n",emboss_run);
        printf("gray scale              g        %d\n",gray_run);
        printf("median                  m        %d\n",median_run);
        printf("contrast                c        %d\n",contrast_run);
        printf("histogram               h        %d\n",histogram_run);
        printf("histogram_eq            q        %d\n",histogram_eq_run);
        printf("rotate                  r        %d\n",rotate_run);
        printf("DCT                     d        %d\n",dct_run);
        printf("IDCT                    x        %d\n",idct_run);
        printf("threshold               t        %d\n",thresh_run);
        printf("intensity waveform      i        %d\n",intensity_waveform_run);
        printf("uv mapping              u        %d\n",uv_mapping_run);
        printf("hough                   o        %d\n",hough_run);
        printf("frame rate limit        f        %d\n",frame_limit_run);
        printf("frame rate decrease     ;        %d\n",fps);
        printf("frame rate increase     '        %d\n",fps);
        printf("median window decrease  [        %d\n",median_win);
        printf("median window increase  ]        %d\n",median_win);
        printf("threshold decrease      9        %d\n",thresh_val);
        printf("threshold increase      0        %d\n",thresh_val);
        printf("sharpen decrease        1        %d\n",sharpen_val);
        printf("sharpen increase        2        %d\n",sharpen_val);
        printf("angle decrease          )        %d\n",angle);
        printf("angle increase          (        %d\n",angle);
        printf("HW(1) or SW(0)          !        %d\n",hw_not_sw);
        break;

    //default:    printf( "Unknown Key: %d (%c)\n", inp, inp );
    }
}