- // We want dual-stack sockets. (Sorry, OpenBSD and Windows XP...)
- int zero = 0;
- if (setsockopt(server_sock, IPPROTO_IPV6, IPV6_V6ONLY, &zero, sizeof(zero)) == -1) {
- perror("setsockopt(IPV6_V6ONLY)");
- exit(1);
+ return state;
+}
+
+// Find all port statements in the configuration file, and create acceptors for htem.
+vector<Acceptor *> create_acceptors(
+ const Config &config,
+ map<sockaddr_in6, Acceptor *, Sockaddr6Compare> *deserialized_acceptors)
+{
+ vector<Acceptor *> acceptors;
+ for (unsigned i = 0; i < config.acceptors.size(); ++i) {
+ const AcceptorConfig &acceptor_config = config.acceptors[i];
+ Acceptor *acceptor = NULL;
+ map<sockaddr_in6, Acceptor *, Sockaddr6Compare>::iterator deserialized_acceptor_it =
+ deserialized_acceptors->find(acceptor_config.addr);
+ if (deserialized_acceptor_it != deserialized_acceptors->end()) {
+ acceptor = deserialized_acceptor_it->second;
+ deserialized_acceptors->erase(deserialized_acceptor_it);
+ } else {
+ int server_sock = create_server_socket(acceptor_config.addr, TCP_SOCKET);
+ acceptor = new Acceptor(server_sock, acceptor_config.addr);
+ }
+ acceptor->run();
+ acceptors.push_back(acceptor);