Ejemplo n.º 1
0
int
main(int argc, char *argv[]) {

  int s;
  long val;

  if (argc != 2) {
    usage(argv[0],"socketname");
  }

  s = mksocketcliente();

  if (s < 0) {
    fprintf(stderr, "No se pudo crear un socket %d %s\n", 
	    errno, strerror(errno));
    exit(1);
  }

  if (mkconnect(s, argv[1]) < 0) {
    fprintf(stderr, "No se pudo conectar al socket %d %s\n", 
	    errno, strerror(errno));
    exit(1);
  }

  if (establecerDescriptorNoBloqueante(0) < 0) { 
    fprintf(stderr, "Error estableciendo descriptor no bloqueante %d %s\n",
	    errno, strerror(errno));
    exit(1);
  }

  if (establecerDescriptorNoBloqueante(s) < 0) { 
    fprintf(stderr, "Error estableciendo descriptor no bloqueante %d %s\n",
	    errno, strerror(errno));
    exit(1);
  }

  while (1) {

    if (leerEscribirNoBloqueante(0, s) < 0) { 
      fprintf(stderr, "Error en la lectura: %d %s\n",
	      errno, strerror(errno));
      exit(1);
    }

    if (leerEscribirNoBloqueante(s, 1) < 0) { 
      fprintf(stderr, "Error en la lectura: %d %s\n",
	      errno, strerror(errno));
      exit(1);
    }
  }
  
  exit(0);
  return 0;
}
Ejemplo n.º 2
0
static void
listenproc(void *vaddress)
{
	HConnect *c;
	char *address, ndir[NETPATHLEN], dir[NETPATHLEN];
	int ctl, nctl, data;

	address = vaddress;
	ctl = announce(address, dir);
	if(ctl < 0){
		fprint(2, "venti: httpd can't announce on %s: %r\n", address);
		return;
	}

	if(0) print("announce ctl %d dir %s\n", ctl, dir);
	for(;;){
		/*
		 *  wait for a call (or an error)
		 */
		nctl = listen(dir, ndir);
		if(0) print("httpd listen %d %s...\n", nctl, ndir);
		if(nctl < 0){
			fprint(2, "venti: httpd can't listen on %s: %r\n", address);
			return;
		}

		data = accept(ctl, ndir);
		if(0) print("httpd accept %d...\n", data);
		if(data < 0){
			fprint(2, "venti: httpd accept: %r\n");
			close(nctl);
			continue;
		}
		if(0) print("httpd close nctl %d\n", nctl);
		close(nctl);
		c = mkconnect();
		hinit(&c->hin, data, Hread);
		hinit(&c->hout, data, Hwrite);
		vtproc(httpproc, c);
	}
}