Example #1
0
File: sm.c Project: 119120119/node
/*
 * Called when the dirty side of the SSL has lost its connection. This is
 * pretty terminal as all that can be left to do is send any buffered output
 * on the clean side - after that, we're done.
 */
int state_machine_close_dirty(state_machine_t * machine)
{
    buffer_close(&machine->dirty_in);
    buffer_close(&machine->dirty_out);
    buffer_close(&machine->clean_in);
    if (machine->ssl)
        SSL_free(machine->ssl);
    machine->ssl = NULL;
    machine->bio_intossl = machine->bio_fromssl = NULL;
    if (buffer_empty(&machine->clean_out))
        return 0;
    return 1;
}
Example #2
0
File: sm.c Project: 119120119/node
/* Called when the clean side of the SSL has lost its connection */
int state_machine_close_clean(state_machine_t * machine)
{
    /*
     * Well, first thing to do is null out the clean-side buffers - they're
     * no use any more.
     */
    buffer_close(&machine->clean_in);
    buffer_close(&machine->clean_out);
    /* And start an SSL shutdown */
    if (machine->ssl)
        SSL_shutdown(machine->ssl);
    /* This is an "event", so flush the SSL of any generated traffic */
    state_machine_churn(machine);
    if (buffer_empty(&machine->dirty_in) && buffer_empty(&machine->dirty_out))
        return 0;
    return 1;
}
Example #3
0
/*-------------------------------------------------------------------------*\
* Closes socket used by object 
\*-------------------------------------------------------------------------*/
static int meth_close(lua_State *L)
{
    p_tcp tcp = (p_tcp) auxiliar_checkgroup(L, "tcp{any}", 1);
	buffer_close(L, &tcp->buf);
    socket_destroy(&tcp->sock);
    lua_pushnumber(L, 1);
    return 1;
}
Example #4
0
/* load the history
 * ----------------------------------------------------------------------- */
void history_load(void) {
  unsigned int i;
  unsigned int hlen;
  char fname[PATH_MAX + 1];

  hlen = str_copyn(fname, sh_home, PATH_MAX);
  if(hlen >= PATH_MAX - 3)
    return;
  
  /* append a trailing slash if not already there */
  if(hlen && fname[hlen - 1] != '/')
    fname[hlen++] = '/';
  
  fname[hlen++] = '.';
  
  /* mapped history entries */
  history_mapped = 0;
  
  for(i = 0; history_files[i]; i++) {
    /* append history file name */
    str_copyn(&fname[hlen], history_files[i], PATH_MAX - hlen);

    /* then try to open the history file */
    if(buffer_mmapread(&history_buffer, fname) == 0)
      break;
  }
  
  /* we tried all files: nothing to load */
  if(history_files[i] == NULL)
    return;

  /* loop through the mapped history file and separate
   * history entries using nul-string-termination 
   *
   * note that quote-balancing is applied because there 
   * may be quoted multiline words in the history 
   */
  while(history_buffer.p < history_buffer.n) {
    unsigned long len;
    
    /* next entry will begin after the termination */
    if(!(len = history_cmdlen(&history_buffer.x[history_buffer.p])))
      break;
    
    while(parse_isspace(history_buffer.x[history_buffer.p]))
      history_buffer.p++;
    
    history_set(&history_buffer.x[history_buffer.p]);
    history_advance();
    history_mapped++;
    
    history_buffer.p += len;
  }
  
  /* unmap the file if it didn't contain any entries */
  if(history_buffer.n && history_mapped == 0)
    buffer_close(&history_buffer);
}
Example #5
0
int su_load(su_state *s, su_reader reader, void *data) {
	prototype_t *prot = su_allocate(s, NULL, sizeof(prototype_t));
	reader_buffer_t *buffer = buffer_open(s, reader, data);

	if (verify_header(s, buffer)) {
		buffer_close(s, buffer);
		return -1;
	}

	if (read_prototype(s, buffer, prot)) {
		buffer_close(s, buffer);
		return -1;
	}

	buffer_close(s, buffer);
	gc_insert_object(s, &prot->gc, PROTOTYPE);
	lambda(s, prot, -1);
	return 0;
}
Example #6
0
File: sm.c Project: 119120119/node
void state_machine_close(state_machine_t * machine)
{
    if (machine->ssl)
        SSL_free(machine->ssl);
    /*
     * SSL_free seems to decrement the reference counts already so doing this
     * goes kaboom.
     */
# if 0
    if (machine->bio_intossl)
        BIO_free(machine->bio_intossl);
    if (machine->bio_fromssl)
        BIO_free(machine->bio_fromssl);
# endif
    buffer_close(&machine->clean_in);
    buffer_close(&machine->clean_out);
    buffer_close(&machine->dirty_in);
    buffer_close(&machine->dirty_out);
    state_machine_init(machine);
}
Example #7
0
int
main(int argc, char* argv[]) {
  xmlreader r;
  int ret;
  int c;
  int index = 0;
  struct longopt opts[] = {
      {"help", 0, NULL, 'h'},
      {"single-quote", 0, &quote_char, '\''},
      {"double-quote", 0, &quote_char, '"'},
      {"one-line", 0, NULL, 'o'},
      {"compact", 0, NULL, 'c'},
      {"indent", 0, NULL, 'l'},
      {0},
  };

  errmsg_iam(argv[0]);

  for(;;) {
    c = getopt_long(argc, argv, "hsdol:c", opts, &index);
    if(c == -1)
      break;
    if(c == 0)
      continue;

    switch(c) {
      case 'h': usage(argv[0]); return 0;
      case 's': quote_char = '\''; break;
      case 'd': quote_char = '"'; break;
      case 'o': one_line = 1; break;
      case 'c': compact = 1; break;
      case 'l': scan_int(optarg, &indent); break;
      default: usage(argv[0]); return 1;
    }
  }

  if(argc > 1)
    ret = buffer_mmapprivate(&infile, argv[1]);
  else
    ret = buffer_read_fd(&infile, 0);

  if(ret) {
    errmsg_infosys("input");
    return errno == ENOENT ? 127 : 1;
  }

  xml_reader_init(&r, &infile);
  xml_read_callback(&r, xml_read_function);
  buffer_putnlflush(buffer_1);
  buffer_close(&b);

  return 0;
}
Example #8
0
static void save_button_clicked(GtkButton *btn, gpointer data)
{
	if (dev_opened) {
		g_source_remove(fill_buffer_function);
		buffer_close();
		dev_opened = false;
	}

	if (gtk_toggle_button_get_active((GtkToggleButton *)radio_single_val)){
		iio_save_widgets(tx_widgets, num_tx);
		iio_save_widgets(rx_widgets, num_rx);
		rx_update_device_sampling_freq("ad7303",
			USE_INTERN_SAMPLING_FREQ);
	} else if (gtk_toggle_button_get_active((GtkToggleButton *)radio_waveform)){
		generateWavePeriod();
		dev_opened = !buffer_open(buffer_size);
		startWaveGeneration();
	}
}
Example #9
0
int main (int argc, char *argv[]) {
  struct buffer_info buf;
  struct lc_point data[3], newdata[3];
  char errstr[ERRSTR_LEN];
  int i, j, k;

  /* Create disk buffer */
  if(buffer_init(&buf, errstr))
    fatal(1, "buffer_init: %s", errstr);

  /* Get disk buffer */
  if(buffer_alloc(&buf, 6, 3, errstr))
    fatal(1, "buffer_alloc: %s", errstr);

  for(i = 0; i < 3; i++) {
    data[i].aper[0].flux = i;
    data[i].aper[0].fluxvar = i*2;
    data[i].satur = i % 2;
  }

  /* Write out */
  if(buffer_put_object(&buf, data, 0, 3, 2, errstr))
    fatal(1, "buffer_put_object: %s", errstr);

  /* Read back */
  for(k = 0; k < 6; k++) {
    if(buffer_fetch_object(&buf, newdata, 0, 3, k, errstr))
      fatal(1, "buffer_fetch_object: %s", errstr);

    for(j = 0; j < NFLUX; j++) {
      for(i = 0; i < 3; i++)
	printf("%d %d %f %f %d\n", k, j,
	       newdata[i].aper[j].flux, newdata[i].aper[j].fluxvar, newdata[i].satur);
    }
  }

  /* Release disk buffer */
  buffer_close(&buf);

  return(0);
}
Example #10
0
File: sln.c Project: rsenn/dirlist
int
main(int argc, char* argv[]) {
  int index = 0, c;
  static const struct longopt opts[] = {{"help", 0, NULL, 'h'}, {"verbose", 0, 0, 'v'}, {0}};

  errmsg_iam(argv[0]);

  for(;;) {
    c = getopt_long(argc, argv, "hv", opts, &index);
    if(c == -1)
      break;
    if(c == '\0')
      continue;

    switch(c) {
      case 'h': usage(argv[0]); return 0;
      case 'v': verbose = 1; break;
      default: {
        usage(argv[0]);
        return 1;
      }
    }
  }

  while(optind < argc) {
    const char* a = argv[optind++];
    int i = str_rchr(a, '.');

    if(str_equal(&a[i], ".list")) {
      buffer in;
      if(!buffer_mmapread(&in, a)) {
        stralloc target, link;
        ssize_t ret;
        stralloc_init(&target);
        stralloc_init(&link);

        for(;;) {
          if((ret = buffer_get_new_token_sa(&in, &target, " \t\v", 2)) < 0)
            break;

          if(ret == 0 || target.s[0] == '\0')
            break;
          if(target.len > 0)
            --target.len;

          if((ret = buffer_get_new_token_sa(&in, &link, "\r\n", 2)) < 0)
            break;

          if(ret == 0 || link.s[0] == '\0')
            break;
          stralloc_chomp(&link);

          mklink_sa(&target, &link);

          if(!stralloc_endb(&link, ".so", 3)) {
            if(sln(link.s))
              return 1;
          }
        }

        buffer_close(&in);
      }
    } else {
      if(sln(argv[i]))
        return 1;
    }
  }
}
Example #11
0
void webhdfs_req_close (webhdfs_req_t *req) {
    buffer_close(&(req->buffer));
}
Example #12
0
int
mmap_filename(void* map, stralloc* sa) {
#if WINDOWS_NATIVE
  typedef DWORD(WINAPI get_mmaped_filename_fn)(HANDLE, LPVOID, LPSTR, DWORD);
  static get_mmaped_filename_fn* get_mmaped_filename;

  if(get_mmaped_filename == 0) {
    HINSTANCE psapi = LoadLibraryA("psapi.dll");
    if((get_mmaped_filename = (get_mmaped_filename_fn*)GetProcAddress(psapi, "GetMappedFileNameA")) == 0)
      return 0;
  }

  stralloc_ready(sa, MAX_PATH + 1);
  if((sa->len = (size_t) (*get_mmaped_filename)(GetCurrentProcess(), map, sa->s, sa->a))) {

    /* Translate path with device name to drive letters. */
    char szTemp[BUFSIZE];
    szTemp[0] = '\0';

    if(GetLogicalDriveStringsA(BUFSIZE - 1, szTemp)) {
      char szName[MAX_PATH];
      char szDrive[3] = " :";
      BOOL bFound = FALSE;
      char* p = szTemp;

      do {
        /* Copy the drive letter to the template string */
        *szDrive = *p;

        /* Look up each device name */
        if(QueryDosDevice(szDrive, szName, MAX_PATH)) {
          size_t uNameLen = str_len(szName);

          if(uNameLen < MAX_PATH) {
            bFound = strnicmp(sa->s, szName, uNameLen) == 0 && *(sa->s + uNameLen) == '\\';

            if(bFound) {
              /* Reconstruct sa->s using szTempFile
                 Replace device path with DOS path */
              stralloc_remove(sa, 0, uNameLen);
              stralloc_prepends(sa, szDrive);
              break;
            }
          }
        }

        /* Go to the next NULL character. */
        while(*p++)
          ;
      } while(!bFound && *p); /* end of string */
    }
  }
  return sa->len > 0;
#else
  char buf[1024];
  buffer b = BUFFER_INIT(read, open("/proc/self/maps", O_RDONLY), buf, sizeof(buf));
  char line[73 + PATH_MAX + 1];
  ssize_t n;
  int ret = 0;

  while((n = buffer_getline(&b, line, sizeof(line))) > 0) {
    char* p = line;
    uint64 start, end;

    p += scan_xlonglong(p, &start);
    if(*p == '-') {
      char* e = line + n - 1;
      int i = 4;

      ++p;
      p += scan_xlonglong(p, &end);

      while(i--) {
        p += scan_whitenskip(p, e - p);
        p += scan_nonwhitenskip(p, e - p);
      }
      p += scan_whitenskip(p, e - p);

      if((uint64)map >= start && (uint64)map < end) {
        stralloc_copyb(sa, p, e - p);
        ret = 1;
        break;
      }
    }
  }

  buffer_close(&b);
  return ret;
#endif
}