示例#1
0
HTTPConnection * HTTPConnectionManager::getConnection(const std::string &scheme,
                                                      const std::string &hostname,
                                                      uint16_t port)
{
    if((scheme != "http" && scheme != "https") || hostname.empty())
        return NULL;

    const int sockettype = (scheme == "https") ? TLSSocket::TLS : Socket::REGULAR;
    vlc_mutex_lock(&lock);
    HTTPConnection *conn = getConnection(hostname, port, sockettype);
    if(!conn)
    {
        Socket *socket = (sockettype == TLSSocket::TLS) ? new (std::nothrow) TLSSocket()
                                                        : new (std::nothrow) Socket();
        if(!socket)
        {
            vlc_mutex_unlock(&lock);
            return NULL;
        }
        /* disable pipelined tls until we have ticket/resume session support */
        conn = new (std::nothrow) HTTPConnection(stream, socket, sockettype != TLSSocket::TLS);
        if(!conn)
        {
            delete socket;
            vlc_mutex_unlock(&lock);
            return NULL;
        }

        connectionPool.push_back(conn);

        if (!conn->connect(hostname, port))
        {
            vlc_mutex_unlock(&lock);
            return NULL;
        }
    }

    conn->setUsed(true);
    vlc_mutex_unlock(&lock);
    return conn;
}
示例#2
0
HTTPConnection* HTTP::sendRequest(HTTPRequest& r,                           /* the request that we will sent */
                                  httpconnection_event_callback eventCB,    /* this function gets called when we receive data, see HTTPConnection.h */
                                  void* user,                               /* the user pointer that gets passed into `eventCB` */
                                  SSL* ssl)                                 /* pass a SSL* when you want to make a secure connection */
{

  // create request string.
  std::string request_str;
  if(!r.toString(request_str)) {
    RX_ERROR("Cannot create request string");
    return NULL;
  }

  // create connection
  HTTPConnection* c = new HTTPConnection(loop, r.getURL().getHost(), r.getURL().getPort(), ssl);
  c->cb_close = http_on_connection_event;
  c->cb_close_user = this;
  c->addToOutputBuffer(request_str);
  c->connect(eventCB, user);

  connections.push_back(c);
  return c;
}