1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef REMOTING_HOST_GNUBBY_SOCKET_H_
6 #define REMOTING_HOST_GNUBBY_SOCKET_H_
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/threading/non_thread_safe.h"
20 class StreamListenSocket
;
25 // Class that manages a socket used for gnubby requests.
26 class GnubbySocket
: public base::NonThreadSafe
{
28 GnubbySocket(scoped_ptr
<net::StreamListenSocket
> socket
,
29 const base::Closure
& timeout_callback
);
32 // Adds data to the current request.
33 void AddRequestData(const char* data
, int data_len
);
35 // Gets the current request data and clears it.
36 void GetAndClearRequestData(std::string
* data_out
);
38 // Returns true if the current request is complete.
39 bool IsRequestComplete() const;
41 // Returns true if the stated request size is larger than the allowed maximum.
42 bool IsRequestTooLarge() const;
44 // Sends response data to the socket.
45 void SendResponse(const std::string
& data
);
47 // Sends an SSH error code to the socket.
50 // Returns true if |socket| is the same one owned by this object.
51 bool IsSocket(net::StreamListenSocket
* socket
) const;
53 // Sets a timer for testing.
54 void SetTimerForTesting(scoped_ptr
<base::Timer
> timer
);
57 // Returns the stated request length.
58 size_t GetRequestLength() const;
60 // Returns the response length bytes.
61 std::string
GetResponseLengthAsBytes(const std::string
& response
) const;
63 // Resets the socket activity timer.
67 scoped_ptr
<net::StreamListenSocket
> socket_
;
70 std::vector
<char> request_data_
;
72 // The activity timer.
73 scoped_ptr
<base::Timer
> timer_
;
75 DISALLOW_COPY_AND_ASSIGN(GnubbySocket
);
78 } // namespace remoting
80 #endif // REMOTING_HOST_GNUBBY_SOCKET_H_