Get the Stream socket client.

Connect to the APNS server and open a client socket to it.

@return resource Socket to the APNS server.

@throws PushException if connection to APNS server failed.
517902
private function getStreamSocketClient()
    {
        $stream_socket_client = stream_socket_client(
            $this->params['endpoint'],
            $errno,
            $errstr,
            30,
            STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT,
            $this->getStreamContext()
        );

        if ($stream_socket_client === false) {
            throw new PushException('An error occurred while trying to contact APNS server.');
        }

        return $stream_socket_client;
    }
1155788
@Override
    public boolean isPushSupported() {

        // Find the existing H2 connection and stream so we can use them to send the
        // push_promise frame to the client.
        HttpInboundServiceContext isc = (HttpInboundServiceContext) getServiceContext();
        HttpInboundLink link = ((HttpInboundServiceContextImpl) isc).getLink();

        if (!(link instanceof H2HttpInboundLinkWrap)) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "HTTPRequestMessageImpl.isPushSupported(): Error: This is not an HTTP2 connection, push() was ignored.");
            }
            return false;
        }

        if ((((H2HttpInboundLinkWrap) link).muxLink == null) ||
            (((H2HttpInboundLinkWrap) link).muxLink.getRemoteConnectionSettings() == null)) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "HTTPRequestMessageImpl.isPushSupported(): The H2HttpInboundLinkWrap muxlink is null, push() was ignored.");
            }
            return false;
        }

        // If the link is closing, don't bother
        //if (((H2InboundLink) link).linkStatus == LINK_STATUS.CLOSING) {
        //    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
        //        Tr.debug(tc, "HTTPRequestMessageImpl.pushNewRequest(): Link is closing, push() was ignored.");
        //    }
        //    return false;
        // }

        // Don't send the push_promise frame if the client doesn't want it
        if (((H2HttpInboundLinkWrap) link).muxLink.getRemoteConnectionSettings().getEnablePush() != 1) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "HTTPRequestMessageImpl.isPushSupported(): The client does not accept push_promise frames, push() was ignored.");
            }
            return false;
        }

        return true;
    }
351422
static OutputStream connectToOneServer(String server, int port) throws IOException {
        try {
            Socket pushSocket = new Socket(server, port);
            OutputStream out = pushSocket.getOutputStream();
            m_logger.info("Connected to export endpoint node at: " + server + ":" + port);
            return out;
        } catch (UnknownHostException e) {
            m_logger.rateLimitedLog(120, Level.ERROR, e, "Don't know about host: " + server);
            throw e;
        } catch (IOException e) {
            m_logger.rateLimitedLog(120, Level.ERROR, e, "Couldn't get I/O for the connection to: " + server);
            throw e;
        }
    }
842113
public InputStream asInputStream() {
        InputStream is = fromStreamOrBufferOrUrl();
        if (is != null) return is;
        String s = fromStringOrReader();
        if (s != null) return streamFrom(s);
        throw resourceUnaccessible();
    }
529421
public ClientSocket openIfHeartbeatActive()
  {
    if (_state.isClosed()) {
      return null;
    }
    
    if (! _isHeartbeatActive && _isHeartbeatServer) {
      return null;
    }

    ClientSocket stream = openRecycle();

    if (stream != null)
      return stream;

    return connect();
  }
1151858
public function push(PushInterface $push)
    {
        $client = $this->getOpenedServiceClient();

        $pushedDevices = new DeviceCollection();

        foreach ($push->getDevices() as $device) {
            /** @var \ZendService\Apple\Apns\Message $message */
            $message = $this->getServiceMessageFromOrigin($device, $push->getMessage());

            try {
                /** @var \ZendService\Apple\Apns\Response\Message $response */
                $response = $client->send($message);

                $responseArr = [
                    'id'    => $response->getId(),
                    'token' => $response->getCode(),
                ];
                $push->addResponse($device, $responseArr);

                if (ServiceResponse::RESULT_OK === $response->getCode()) {
                    $pushedDevices->add($device);
                } else {
                    $client->close();
                    unset($this->openedClient, $client);
                    // Assign returned new client to the in-scope/in-use $client variable
                    $client = $this->getOpenedServiceClient();
                }

                $this->response->addOriginalResponse($device, $response);
                $this->response->addParsedResponse($device, $responseArr);
            } catch (\RuntimeException $e) {
                throw new PushException($e->getMessage());
            }
        }

        return $pushedDevices;
    }
689513
public InputStream getInputStream()
    throws IOException
  {
    if (_indirectSource != null)
      return _indirectSource.getInputStream();
    else if (_out != null)
      return _out.openInputStream();
    else
      throw new IllegalStateException(L.l("{0}: no input stream is available",
                                          this));
  }
848040
public function connect()
    {
        $connectTimeout = 1;
        $errstr = '';
        $errno = 0;
        $stream = @stream_socket_client($this->nodeUrl, $errno, $errstr, $connectTimeout);

        if (!$stream) {
            $this->log->warning('unable to connect to '.$this->nodeUrl.': '.$errstr);
            throw new ConnectException('Unable to connect to resource '.$this->nodeUrl.'. '.$errstr, $errno);
        }

        $this->log->info('connected to '.$this->nodeUrl);
        $this->stream = $stream;

        return true;
    }
680619
@Override
   public InputStream getInputStream() throws IOException
   {
      if (!connected)
         connect();

      try
      {
         return nodeRepresentation.getInputStream();
      }
      catch (IOException e)
      {
         //e.printStackTrace();
         throw new IOException("can't get input stream", e);
      }
      catch (RepositoryException e)
      {
         //e.printStackTrace();
         throw new IOException("can't get input stream", e);
      }
   }
851847
public SocketAddress receive(ByteBuffer dst) throws IOException {
        if (dst.isReadOnly())
            throw new IllegalArgumentException("Read-only buffer");
        if (dst == null)
            throw new NullPointerException();
        // Android-changed : Do not attempt to bind to 0 (or 0.0.0.0) if there hasn't been
        // an explicit call to bind() yet. Fail fast and return null.
        if (localAddress == null)
            return null;
        synchronized (readLock) {
            ensureOpen();
            // Socket was not bound before attempting receive
            // if (localAddress() == null)
            //     bind(null);
            int n = 0;
            ByteBuffer bb = null;
            try {
                begin();
                if (!isOpen())
                    return null;
                SecurityManager security = System.getSecurityManager();
                readerThread = NativeThread.current();
                if (isConnected() || (security == null)) {
                    do {
                        n = receive(fd, dst);
                    } while ((n == IOStatus.INTERRUPTED) && isOpen());
                    if (n == IOStatus.UNAVAILABLE)
                        return null;
                } else {
                    bb = Util.getTemporaryDirectBuffer(dst.remaining());
                    for (;;) {
                        do {
                            n = receive(fd, bb);
                        } while ((n == IOStatus.INTERRUPTED) && isOpen());
                        if (n == IOStatus.UNAVAILABLE)
                            return null;
                        InetSocketAddress isa = (InetSocketAddress)sender;
                        try {
                            security.checkAccept(
                                isa.getAddress().getHostAddress(),
                                isa.getPort());
                        } catch (SecurityException se) {
                            // Ignore packet
                            bb.clear();
                            n = 0;
                            continue;
                        }
                        bb.flip();
                        dst.put(bb);
                        break;
                    }
                }
                return sender;
            } finally {
                if (bb != null)
                    Util.releaseTemporaryDirectBuffer(bb);
                readerThread = 0;
                end((n > 0) || (n == IOStatus.UNAVAILABLE));
                assert IOStatus.check(n);
            }
        }
    }
128066
@Override
    public InputStream getInputStream() {
        try {
            LOGGER.debug("getInputStream getExternalIdentifier: {} {} ", property().getName(), getExternalIdentifier());
            return URI.create(getExternalIdentifier()).toURL().openStream();
        } catch (final MalformedURLException e) {
            throw new RepositoryRuntimeException("Malformed URL: " + getExternalIdentifier(), e);
        } catch (final Exception e) {
            throw new RepositoryRuntimeException(e);
        }
    }
1017394
@Override
    public InputStream getInputStream() throws IOException {
	if (barr == null) {
	    barr = IOUtil.toBytes(url.openStream());
	}
	return new ByteArrayInputStream(barr);
    }
502375
function onConnection() {
  var endpoint = new http2.Endpoint(log, 'CLIENT', {});
  endpoint.pipe(socket).pipe(endpoint);

  // Sending request
  var stream = endpoint.createStream();
  stream.headers({
    ':method': 'GET',
    ':scheme': url.protocol.slice(0, url.protocol.length - 1),
    ':authority': url.hostname,
    ':path': url.path + (url.hash || '')
  });

  // Receiving push streams
  stream.on('promise', function(push_stream, req_headers) {
    var filename = path.join(__dirname, '/push-' + push_count);
    push_count += 1;
    console.error('Receiving pushed resource: ' + req_headers[':path'] + ' -> ' + filename);
    push_stream.pipe(fs.createWriteStream(filename)).on('finish', finish);
  });

  // Receiving the response body
  stream.pipe(process.stdout);
  stream.on('end', finish);
}
561738
public InputStream getInputStream() {
        try
        {
            int responseCode = this.urlConnection.getResponseCode();

            try
            {
                // HACK: manually follow redirects, for the login to work
                // HTTPUrlConnection auto redirect doesn't respect the provided headers
                if(responseCode ==302)
                {
                    HttpClient redirectClient =
                            new HttpClient(proxyHost,proxyPort, urlConnection.getHeaderField("Location"),
                                    headers, urlConnection.getRequestMethod(), callback, authHeader);
                    redirectClient.getInputStream().close();
                }
            }
            catch (Throwable e)
            {
                System.out.println("Following redirect failed");
            }

            setCookieHeader = this.urlConnection.getHeaderField("Set-Cookie");


            InputStream in = responseCode != HttpURLConnection.HTTP_OK ?
                    this.urlConnection.getErrorStream() : this.urlConnection.getInputStream();

            return in;
        } catch (Exception e) {
            return null;
        }
    }
389056
@FFDCIgnore({IOException.class})
    public static InputStream getResourceAsStream(String resourceName, Class<?> callingClass) {
        URL url = getResource(resourceName, callingClass);

        try {
            return (url != null) ? url.openStream() : null;
        } catch (IOException e) {
            return null;
        }
    }
1054091
protected HttpURLConnection getConnection() {
        try {
            HttpURLConnection connection;
            if (proxy != null) {
                connection = (HttpURLConnection) sentryUrl.openConnection(proxy);
            } else {
                connection = (HttpURLConnection) sentryUrl.openConnection();
            }

            if (bypassSecurity && connection instanceof HttpsURLConnection) {
                ((HttpsURLConnection) connection).setHostnameVerifier(NAIVE_VERIFIER);
            }
            connection.setRequestMethod("POST");
            connection.setDoOutput(true);
            connection.setConnectTimeout(connectionTimeout);
            connection.setReadTimeout(readTimeout);
            connection.setRequestProperty(USER_AGENT, SentryEnvironment.getSentryName());
            connection.setRequestProperty(SENTRY_AUTH, getAuthHeader());

            if (marshaller.getContentType() != null) {
                connection.setRequestProperty("Content-Type", marshaller.getContentType());
            }

            if (marshaller.getContentEncoding() != null) {
                connection.setRequestProperty("Content-Encoding", marshaller.getContentEncoding());
            }

            return connection;
        } catch (IOException e) {
            throw new IllegalStateException("Couldn't set up a connection to the Sentry server.", e);
        }
    }
802376
protected InputStream getStream(HttpClient httpClient, String url) {
        try {
            HttpEntity entity = get(httpClient, url);
            if (entity == null) return null;
            return entity.getContent();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }