Files
platform-external-webrtc/webrtc/base/socketpool.h
ivoc 3324cf751a Revert of Delete unused code httprequest, httpclient, and socketpool. (patchset #3 id:40001 of https://codereview.webrtc.org/2366333002/ )
Reason for revert:
This CL breaks some downstream dependencies (contact me for more info).

Original issue's description:
> Delete unused code httprequest, httpclient, and socketpool.
>
> BUG=webrtc:6424
>
> Committed: https://crrev.com/4a255be3790a040cae2f6182ed70b7dd38c6839e
> Cr-Commit-Position: refs/heads/master@{#14514}

TBR=perkj@webrtc.org,pthatcher@webrtc.org,nisse@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:6424

Review-Url: https://codereview.webrtc.org/2397673002
Cr-Commit-Position: refs/heads/master@{#14518}
2016-10-05 08:23:21 +00:00

144 lines
4.7 KiB
C++

/*
* Copyright 2004 The WebRTC Project Authors. All rights reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef WEBRTC_BASE_SOCKETPOOL_H_
#define WEBRTC_BASE_SOCKETPOOL_H_
#include <deque>
#include <list>
#include "webrtc/base/logging.h"
#include "webrtc/base/sigslot.h"
#include "webrtc/base/socketaddress.h"
namespace rtc {
class AsyncSocket;
class LoggingAdapter;
class SocketFactory;
class SocketStream;
class StreamInterface;
//////////////////////////////////////////////////////////////////////
// StreamPool
//////////////////////////////////////////////////////////////////////
class StreamPool {
public:
virtual ~StreamPool() { }
virtual StreamInterface* RequestConnectedStream(const SocketAddress& remote,
int* err) = 0;
virtual void ReturnConnectedStream(StreamInterface* stream) = 0;
};
///////////////////////////////////////////////////////////////////////////////
// StreamCache - Caches a set of open streams, defers creation/destruction to
// the supplied StreamPool.
///////////////////////////////////////////////////////////////////////////////
class StreamCache : public StreamPool, public sigslot::has_slots<> {
public:
StreamCache(StreamPool* pool);
~StreamCache() override;
// StreamPool Interface
StreamInterface* RequestConnectedStream(const SocketAddress& remote,
int* err) override;
void ReturnConnectedStream(StreamInterface* stream) override;
private:
typedef std::pair<SocketAddress, StreamInterface*> ConnectedStream;
typedef std::list<ConnectedStream> ConnectedList;
void OnStreamEvent(StreamInterface* stream, int events, int err);
// We delegate stream creation and deletion to this pool.
StreamPool* pool_;
// Streams that are in use (returned from RequestConnectedStream).
ConnectedList active_;
// Streams which were returned to us, but are still open.
ConnectedList cached_;
};
///////////////////////////////////////////////////////////////////////////////
// NewSocketPool
// Creates a new stream on every request
///////////////////////////////////////////////////////////////////////////////
class NewSocketPool : public StreamPool {
public:
NewSocketPool(SocketFactory* factory);
~NewSocketPool() override;
// StreamPool Interface
StreamInterface* RequestConnectedStream(const SocketAddress& remote,
int* err) override;
void ReturnConnectedStream(StreamInterface* stream) override;
private:
SocketFactory* factory_;
};
///////////////////////////////////////////////////////////////////////////////
// ReuseSocketPool
// Maintains a single socket at a time, and will reuse it without closing if
// the destination address is the same.
///////////////////////////////////////////////////////////////////////////////
class ReuseSocketPool : public StreamPool, public sigslot::has_slots<> {
public:
ReuseSocketPool(SocketFactory* factory);
~ReuseSocketPool() override;
// StreamPool Interface
StreamInterface* RequestConnectedStream(const SocketAddress& remote,
int* err) override;
void ReturnConnectedStream(StreamInterface* stream) override;
private:
void OnStreamEvent(StreamInterface* stream, int events, int err);
SocketFactory* factory_;
SocketStream* stream_;
SocketAddress remote_;
bool checked_out_; // Whether the stream is currently checked out
};
///////////////////////////////////////////////////////////////////////////////
// LoggingPoolAdapter - Adapts a StreamPool to supply streams with attached
// LoggingAdapters.
///////////////////////////////////////////////////////////////////////////////
class LoggingPoolAdapter : public StreamPool {
public:
LoggingPoolAdapter(StreamPool* pool, LoggingSeverity level,
const std::string& label, bool binary_mode);
~LoggingPoolAdapter() override;
// StreamPool Interface
StreamInterface* RequestConnectedStream(const SocketAddress& remote,
int* err) override;
void ReturnConnectedStream(StreamInterface* stream) override;
private:
StreamPool* pool_;
LoggingSeverity level_;
std::string label_;
bool binary_mode_;
typedef std::deque<LoggingAdapter*> StreamList;
StreamList recycle_bin_;
};
//////////////////////////////////////////////////////////////////////
} // namespace rtc
#endif // WEBRTC_BASE_SOCKETPOOL_H_