rem: if (ok && !pos) {  no_ipv6 = 1; freeaddrinfo(tcp_listen_addr); goto retry;
add: if (ok) { if (!pos) {  no_ipv6 = 1; freeaddrinfo(tcp_listen_addr); goto retry; } else { errid = errno; closesocket(s); errno = errid; s = INVALID_SOCKET; }
context: tcp_listen(int argc, Scheme_Object *argv[]){  unsigned short id, origid;  int backlog, errid;  int reuse = 0;#ifdef MZ_TCP_LISTEN_IPV6_ONLY_SOCKOPT  int no_ipv6 = 0;#endif  const char *address;    if (!CHECK_PORT_ID(argv[0]))    scheme_wrong_type("tcp-listen", PORT_ID_TYPE, 0, argc, argv);  if (argc > 1) {    if (!SCHEME_INTP(argv[1]) || (SCHEME_INT_VAL(argv[1]) < 1))      scheme_wrong_type("tcp-listen", "small positive integer", 1, argc, argv);  }  if (argc > 2)    reuse = SCHEME_TRUEP(argv[2]);  if (argc > 3) {    if (!SCHEME_CHAR_STRINGP(argv[3]) && !SCHEME_FALSEP(argv[3]))      scheme_wrong_type("tcp-listen", "string or #f", 3, argc, argv);  }    #ifdef USE_TCP  TCP_INIT("tcp-listen");#endif  origid = (unsigned short)SCHEME_INT_VAL(argv[0]);  if (argc > 1)    backlog = SCHEME_INT_VAL(argv[1]);  else    backlog = 4;  if ((argc > 3) && SCHEME_TRUEP(argv[3])) {    Scheme_Object *bs;    bs = scheme_char_string_to_byte_string(argv[3]);    address = SCHEME_BYTE_STR_VAL(bs);  } else    address = NULL;  scheme_security_check_network("tcp-listen", address, origid, 0);  scheme_custodian_check_available(NULL, "tcp-listen", "network");#ifdef USE_TCP  id = origid;#endif#ifdef MZ_TCP_LISTEN_IPV6_ONLY_SOCKOPT retry:#endif  {    GC_CAN_IGNORE struct addrinfo *tcp_listen_addr, *addr;    int err, count = 0, pos = 0, i;    listener_t *l = NULL;#ifdef MZ_TCP_LISTEN_IPV6_ONLY_SOCKOPT    int any_v4 = 0, any_v6 = 0;#endif    tcp_listen_addr = scheme_get_host_address(address, id, &err, #ifdef MZ_TCP_LISTEN_IPV6_ONLY_SOCKOPT					      no_ipv6 ? MZ_PF_INET : -1,#else					      -1, #endif					      1, 1);    for (addr = tcp_listen_addr; addr; addr = addr->ai_next) {#ifdef MZ_TCP_LISTEN_IPV6_ONLY_SOCKOPT      if (addr->ai_family == MZ_PF_INET)	any_v4 = 1;      else if (addr->ai_family == PF_INET6)	any_v6 = 1;#endif      count++;    }		    if (tcp_listen_addr) {      tcp_t s;#ifdef MZ_TCP_LISTEN_IPV6_ONLY_SOCKOPT      /* Try IPv6 listeners first, so we can retry and use just IPv4 if	 IPv6 doesn't work right. */      int v6_loop = (any_v6 && any_v4), skip_v6 = 0;#endif      errid = 0;      for (addr = tcp_listen_addr; addr; ) {#ifdef MZ_TCP_LISTEN_IPV6_ONLY_SOCKOPT	if ((v6_loop && (addr->ai_family != PF_INET6))	    || (skip_v6 && (addr->ai_family == PF_INET6))) {	  addr = addr->ai_next;	  continue;	}#endif	s = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);#ifdef MZ_TCP_LISTEN_IPV6_ONLY_SOCKOPT	if (s == INVALID_SOCKET) {	  /* Maybe it failed because IPv6 is not available: */	  if ((addr->ai_family == PF_INET6) && (errno == EAFNOSUPPORT)) {	    if (any_v4 && !pos) {	      /* Maybe we can make it work with just IPv4. Try again. */	      no_ipv6 = 1;	      freeaddrinfo(tcp_listen_addr);	      goto retry;	    }	  }	}	if (s != INVALID_SOCKET) {	  if (any_v4 && (addr->ai_family == PF_INET6)) {	    int ok;# ifdef IPV6_V6ONLY	    int on = 1;	    ok = setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on));# else	    ok = -1;# endif	    if (ok && !pos) {	      /* IPV6_V6ONLY doesn't work */	      no_ipv6 = 1;	      freeaddrinfo(tcp_listen_addr);	      goto retry;	    }	  }	}#endif	if (s != INVALID_SOCKET) {#ifdef USE_WINSOCK_TCP	  unsigned long ioarg = 1;	  ioctlsocket(s, FIONBIO, &ioarg);#else	  fcntl(s, F_SETFL, MZ_NONBLOCKING);#endif	  if (reuse) {	    setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)(&reuse), sizeof(int));	  }      	  if (!bind(s, addr->ai_addr, addr->ai_addrlen)) {	    if (!listen(s, backlog)) {	      if (!pos) {		l = scheme_malloc_tagged(sizeof(listener_t) + ((count - 1) * sizeof(tcp_t)));		l->so.type = scheme_listener_type;		l->count = count;		{		  Scheme_Custodian_Reference *mref;		  mref = scheme_add_managed(NULL,					    (Scheme_Object *)l,					    (Scheme_Close_Custodian_Client *)stop_listener,					    NULL,					    1);		  l->mref = mref;		}	      }	      l->s[pos++] = s;	    	      scheme_file_open_count++;	      REGISTER_SOCKET(s);	      if (pos == count) {		freeaddrinfo(tcp_listen_addr);		return (Scheme_Object *)l;	      }	    } else {	      errid = SOCK_ERRNO();	      closesocket(s);	      break;	    }	  } else {	    errid = SOCK_ERRNO();	    closesocket(s);	    break;	  }	} else {	  errid = SOCK_ERRNO();	  break;	}	addr = addr->ai_next;#ifdef MZ_TCP_LISTEN_IPV6_ONLY_SOCKOPT	if (!addr && v6_loop) {	  v6_loop = 0;	  skip_v6 = 1;	  addr = tcp_listen_addr;	}#endif      }      for (i = 0; i < pos; i++) {	s = l->s[i];	UNREGISTER_SOCKET(s);	closesocket(s);	--scheme_file_open_count;      }            freeaddrinfo(tcp_listen_addr);    } else {      scheme_raise_exn(MZEXN_FAIL_NETWORK,		       "tcp-listen: host not found: %s (%N)",		       address, 1, err);      return NULL;    }  }#ifdef USE_TCP  scheme_raise_exn(MZEXN_FAIL_NETWORK,		   "tcp-listen: listen on %d failed (%E)",		   origid, errid);#else  scheme_raise_exn(MZEXN_FAIL_UNSUPPORTED,		   "tcp-listen: not supported on this platform");#endif  return NULL;}