示例#1
0
void Connection::setLocalAddress(const IPAddress &addr) {
  if (addr.getIP()) {
    string ip(IPAddress(addr.getIP()).getHost());
    evhttp_connection_set_local_address(con, ip.c_str());
  }

  if (addr.getPort()) evhttp_connection_set_local_port(con, addr.getPort());
}
示例#2
0
void SocketServer::service() {
  // Add listeners
  SocketSet sockSet;
  for (unsigned i = 0; i < ports.size(); i++)
    sockSet.add(ports[i]->socket, SocketSet::READ);

  // Add others
  addConnectionSockets(sockSet);

  if (sockSet.select(0.1) || connectionsReady()) {
    // Process connections
    processConnections(sockSet);

    // Accept new connections
    for (unsigned i = 0; i < ports.size() && !shouldShutdown(); i++) {
      try {
        Socket &socket = ports[i]->socket;

        if (!sockSet.isSet(socket, SocketSet::READ)) continue;

        IPAddress clientIP;
        while (true) {
          SmartPointer<Socket> client = socket.accept(&clientIP);
          if (client.isNull()) break;

          // Check access
          if (!allow(clientIP.getIP())) {
            LOG_INFO(3, "Server access denied for " << clientIP);
            continue;
          }

          SocketConnectionPtr con = createConnection(client, clientIP);
          client = 0; // Release socket pointer

          if (con.isNull())
            LOG_INFO(3, "Dropped server connection on "
                     << ports[i]->ip << " from " << clientIP);

          else {
            connections.push_back(con);

            LOG_INFO(3, "Server connection id=" << con->getID() << " on "
                     << ports[i]->ip << " from "
                     << IPAddress(clientIP.getIP()));
          }
        }
      } CBANG_CATCH_ERROR;
    }
  }
示例#3
0
void DNSBase::addNameserver(const IPAddress &ns) {
  evdns_base_nameserver_add(dns, ns.getIP());
}