diff options
Diffstat (limited to 'net/websockets/websocket_throttle.h')
-rw-r--r-- | net/websockets/websocket_throttle.h | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/net/websockets/websocket_throttle.h b/net/websockets/websocket_throttle.h index 279aea2..d05b246 100644 --- a/net/websockets/websocket_throttle.h +++ b/net/websockets/websocket_throttle.h @@ -5,12 +5,17 @@ #ifndef NET_WEBSOCKETS_WEBSOCKET_THROTTLE_H_ #define NET_WEBSOCKETS_WEBSOCKET_THROTTLE_H_ +#include <deque> +#include <string> + #include "base/hash_tables.h" #include "base/singleton.h" -#include "net/socket_stream/socket_stream_throttle.h" namespace net { +class SocketStream; +class WebSocketJob; + // SocketStreamThrottle for WebSocket protocol. // Implements the client-side requirements in the spec. // http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol @@ -19,42 +24,31 @@ namespace net { // remote host (IP address) identified by /host/, even if known by // another name, wait until that connection has been established or // for that connection to have failed. -class WebSocketThrottle : public SocketStreamThrottle { +class WebSocketThrottle { public: - virtual int OnStartOpenConnection(SocketStream* socket, - CompletionCallback* callback); - virtual int OnRead(SocketStream* socket, const char* data, int len, - CompletionCallback* callback); - virtual int OnWrite(SocketStream* socket, const char* data, int len, - CompletionCallback* callback); - virtual void OnClose(SocketStream* socket); + // Puts |job| in |queue_| and queues for the destination addresses + // of |job|. + // If other job is using the same destination address, set |job| waiting. + void PutInQueue(WebSocketJob* job); - static void Init(); + // Removes |job| from |queue_| and queues for the destination addresses + // of |job|. + void RemoveFromQueue(WebSocketJob* job); + + // Checks sockets waiting in |queue_| and check the socket is the front of + // every queue for the destination addresses of |socket|. + // If so, the socket can resume estabilshing connection, so wake up + // the socket. + void WakeupSocketIfNecessary(); private: - class WebSocketState; - typedef std::deque<WebSocketState*> ConnectingQueue; + typedef std::deque<WebSocketJob*> ConnectingQueue; typedef base::hash_map<std::string, ConnectingQueue*> ConnectingAddressMap; WebSocketThrottle(); virtual ~WebSocketThrottle(); friend struct DefaultSingletonTraits<WebSocketThrottle>; - // Puts |socket| in |queue_| and queues for the destination addresses - // of |socket|. Also sets |state| as UserData of |socket|. - // If other socket is using the same destination address, set |state| waiting. - void PutInQueue(SocketStream* socket, WebSocketState* state); - - // Removes |socket| from |queue_| and queues for the destination addresses - // of |socket|. Also releases |state| from UserData of |socket|. - void RemoveFromQueue(SocketStream* socket, WebSocketState* state); - - // Checks sockets waiting in |queue_| and check the socket is the front of - // every queue for the destination addresses of |socket|. - // If so, the socket can resume estabilshing connection, so wake up - // the socket. - void WakeupSocketIfNecessary(); - // Key: string of host's address. Value: queue of sockets for the address. ConnectingAddressMap addr_map_; |