检查 gateway 的通信端口是否都已经连
如果有未连接的端口，则尝试连接

@param array $addresses_list
979084
public function checkGatewayConnections($addresses_list)
    {
        if (empty($addresses_list)) {
            return;
        }
        foreach ($addresses_list as $addr) {
            if (!isset($this->_waitingConnectGatewayAddresses[$addr])) {
                $this->tryToConnectGateway($addr);
            }
        }
    }
1352863
public function ip($return_type = null, $ip_addresses = [])
  {
    $ip_elements = array(
      'HTTP_X_FORWARDED_FOR', 'HTTP_FORWARDED_FOR',
      'HTTP_X_FORWARDED', 'HTTP_FORWARDED',
      'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_CLUSTER_CLIENT_IP',
      'HTTP_X_CLIENT_IP', 'HTTP_CLIENT_IP',
      'REMOTE_ADDR'
    );

    foreach ( $ip_elements as $element ) {
      if(isset($_SERVER[$element])) {
        if ( !is_string($_SERVER[$element]) ) {
          // Log the value somehow, to improve the script!
          continue;
        }
        $address_list = explode(',', $_SERVER[$element]);
        $address_list = array_map('trim', $address_list);
        // Not using array_merge in order to preserve order
        foreach ( $address_list as $x ) {
          $ip_addresses[] = $x;
        }
      }
    }
    if (count($ip_addresses) == 0) {
      return false;
    } elseif ($return_type === 'array') {
      return $ip_addresses;
    } elseif ($return_type === 'single' || $return_type === null) {
      return $ip_addresses[0];
    }
  }
373245
public ServiceCall<GatewayList> listGateways(ListGatewaysOptions listGatewaysOptions) {
    Validator.notNull(listGatewaysOptions, "listGatewaysOptions cannot be null");
    String[] pathSegments = { "v1/environments", "gateways" };
    String[] pathParameters = { listGatewaysOptions.environmentId() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments,
        pathParameters));
    builder.query("version", versionDate);
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "listGateways");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
      builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(GatewayList.class));
  }
808213
protected function actionListAddress()
    {
        list($selected, $action) = $this->getPostedAction();

        $deleted = 0;

        foreach ($selected as $id) {
            if ($action === 'delete' && $this->access('address_delete')) {
                $deleted += (int) $this->address->delete($id);
            }
        }

        if ($deleted > 0) {
            $message = $this->text('Deleted %num item(s)', array('%num' => $deleted));
            $this->setMessage($message, 'success');
        }
    }
893626
public ClientNetworkConfig setAddresses(List<String> addresses) {
        isNotNull(addresses, "addresses");
        addressList.clear();
        addressList.addAll(addresses);
        return this;
    }
905713
private function createAddresses($addresses) {
        if (array_key_exists('email', $addresses)) {
            $this->mailer->addAddress($addresses['email'], $addresses['name']);
        } else {
            foreach ($addresses as $address) {
                $this->mailer->addAddress($address['email'], $address['name']);
            }
        }
    }
299361
public void setAddresses(java.util.Collection<Address> addresses) {
        if (addresses == null) {
            this.addresses = null;
            return;
        }

        this.addresses = new com.amazonaws.internal.SdkInternalList<Address>(addresses);
    }
909001
protected function setPagerlListAddress()
    {
        $conditions = $this->query_filter;
        $conditions['count'] = true;

        $pager = array(
            'query' => $this->query_filter,
            'total' => (int) $this->address->getList($conditions)
        );

        return $this->data_limit = $this->setPager($pager);
    }
1326719
public function addMailboxListHeader(string $name, array $addresses)
    {
        return $this->add(new MailboxListHeader($name, Address::createArray($addresses)));
    }
462851
protected static function kickAddress($address, $connection_id, $message)
    {
        $gateway_data                  = GatewayProtocol::$empty;
        $gateway_data['cmd']           = GatewayProtocol::CMD_KICK;
        $gateway_data['connection_id'] = $connection_id;
        $gateway_data['body'] = $message;
        return static::sendToGateway($address, $gateway_data);
    }
1353855
public static InetSocketAddress[] parseAddressList(String[] addresses) {
        InetSocketAddress[] isa = new InetSocketAddress[addresses.length];
        for (int x = 0; x < addresses.length; x++) {
            isa[x] = createInetSocketAddress(addresses[x]);
        }
        return isa;
    }
1284350
private void setUrlParserFromEndpoints(List<String> endpoints, int port) {
    List<HostAddress> addresses = new ArrayList<>();
    for (String endpoint : endpoints) {
      HostAddress newHostAddress = new HostAddress(endpoint, port, null);
      addresses.add(newHostAddress);
    }

    synchronized (urlParser) {
      urlParser.setHostAddresses(addresses);
    }
  }
1007543
public function getAddresses($type = ShopgateAddress::BOTH)
    {
        if (empty($this->addresses)) {
            return array();
        }

        $addresses = array();

        foreach ($this->addresses as $address) {
            if (($address->getAddressType() & $type) == $address->getAddressType()) {
                $addresses[] = $address;
            }
        }

        return $addresses;
    }
1352719
protected function filterList(array &$list, array $allowed_fields, array $query)
    {
        $filter = array_intersect_key($query, array_flip($allowed_fields));

        if (!empty($filter)) {
            $list = array_filter($list, function ($item) use ($filter) {
                return $this->callbackFilterList($item, $filter);
            });
        }
    }
988287
protected static function getAllGatewayAddressesFromRegister()
    {
        static $addresses_cache, $last_update;
        $time_now = time();
        $expiration_time = 1;
        if(empty($addresses_cache) || $time_now - $last_update > $expiration_time) {
            $client = stream_socket_client('tcp://' . self::$registerAddress, $errno, $errmsg, self::$connectTimeout);
            if (!$client) {
                throw new Exception('Can not connect to tcp://' . self::$registerAddress . ' ' . $errmsg);
            }
            fwrite($client, '{"event":"worker_connect","secret_key":"' . self::$secretKey . '"}' . "\n");
            stream_set_timeout($client, 5);
            $ret = fgets($client, 655350);
            if (!$ret || !$data = json_decode(trim($ret), true)) {
                throw new Exception('getAllGatewayAddressesFromRegister fail. tcp://' .
                    self::$registerAddress . ' return ' . var_export($ret, true));
            }
            $last_update = $time_now;
            $addresses_cache = $data['addresses'];
        }
        return $addresses_cache;
    }
79541
protected static function getAllGatewayAddressesFromRegister()
    {
        static $addresses_cache, $last_update;
        $time_now = time();
        $expiration_time = 1;
        $register_addresses = (array)static::$registerAddress;
        if(empty($addresses_cache) || $time_now - $last_update > $expiration_time) {
            foreach ($register_addresses as $register_address) {
                $client = stream_socket_client('tcp://' . $register_address, $errno, $errmsg, static::$connectTimeout);
                if (!$client) {
                    continue;
                }
            }
            if (!$client) {
                throw new Exception('Can not connect to tcp://' . $register_address . ' ' . $errmsg);
            }

            fwrite($client, '{"event":"worker_connect","secret_key":"' . static::$secretKey . '"}' . "\n");
            stream_set_timeout($client, 5);
            $ret = fgets($client, 655350);
            if (!$ret || !$data = json_decode(trim($ret), true)) {
                throw new Exception('getAllGatewayAddressesFromRegister fail. tcp://' .
                    $register_address . ' return ' . var_export($ret, true));
            }
            $last_update = $time_now;
            $addresses_cache = $data['addresses'];
        }
        if (!$addresses_cache) {
            throw new Exception('Gateway::getAllGatewayAddressesFromRegister() with registerAddress:' .
                json_encode(static::$registerAddress) . '  return ' . var_export($addresses_cache, true));
        }
        return $addresses_cache;
    }
642765
public function getListGateway($listId = null)
    {
        $gateway = new ListsGateway($this->httpClient);
        $this->injectListGatewayDependencies($gateway, $listId);
        return $gateway;
    }