Infer appropriate GNU_STACK alignment for a shared library.
[chromium-blink-merge.git] / remoting / host / gnubby_socket.h
blobd1197629b80fdcd38c080ed123642070fdc7c2e5
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_
8 #include <string>
9 #include <vector>
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/threading/non_thread_safe.h"
15 namespace base {
16 class Timer;
17 } // namespace base
19 namespace net {
20 class StreamListenSocket;
21 } // namespace net
23 namespace remoting {
25 // Class that manages a socket used for gnubby requests.
26 class GnubbySocket : public base::NonThreadSafe {
27 public:
28 GnubbySocket(scoped_ptr<net::StreamListenSocket> socket,
29 const base::Closure& timeout_callback);
30 ~GnubbySocket();
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.
48 void SendSshError();
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);
56 private:
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.
64 void ResetTimer();
66 // The socket.
67 scoped_ptr<net::StreamListenSocket> socket_;
69 // Request data.
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_