ConnectionFileDescriptor.h revision d0691fe6327b0edaadf907008b26c55e78c1ca2f
1//===-- ConnectionFileDescriptor.h ------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef liblldb_ConnectionFileDescriptor_h_
11#define liblldb_ConnectionFileDescriptor_h_
12
13// C Includes
14// C++ Includes
15// Other libraries and framework includes
16// Project includes
17#include "lldb/Core/Connection.h"
18
19namespace lldb_private {
20
21class ConnectionFileDescriptor :
22    public Connection
23{
24public:
25
26    ConnectionFileDescriptor ();
27
28    ConnectionFileDescriptor (int fd, bool owns_fd);
29
30    virtual
31    ~ConnectionFileDescriptor ();
32
33    virtual bool
34    IsConnected () const;
35
36    virtual lldb::ConnectionStatus
37    Connect (const char *s, Error *error_ptr);
38
39    virtual lldb::ConnectionStatus
40    Disconnect (Error *error_ptr);
41
42    virtual size_t
43    Read (void *dst,
44          size_t dst_len,
45          uint32_t timeout_usec,
46          lldb::ConnectionStatus &status,
47          Error *error_ptr);
48
49    virtual size_t
50    Write (const void *src,
51           size_t src_len,
52           lldb::ConnectionStatus &status,
53           Error *error_ptr);
54
55protected:
56
57    lldb::ConnectionStatus
58    BytesAvailable (uint32_t timeout_usec, Error *error_ptr);
59
60    lldb::ConnectionStatus
61    SocketListen (uint16_t listen_port_num, Error *error_ptr);
62
63    lldb::ConnectionStatus
64    SocketConnect (const char *host_and_port, Error *error_ptr);
65
66    lldb::ConnectionStatus
67    NamedSocketAccept (const char *socket_name, Error *error_ptr);
68
69    lldb::ConnectionStatus
70    NamedSocketConnect (const char *socket_name, Error *error_ptr);
71
72    lldb::ConnectionStatus
73    Close (int& fd, Error *error);
74
75    int m_fd;    // Socket we use to communicate once conn established
76    bool m_is_socket;
77    bool m_should_close_fd; // True if this class should close the file descriptor when it goes away.
78    uint32_t m_socket_timeout_usec;
79
80    static int
81    GetSocketOption(int fd, int level, int option_name, int &option_value);
82
83    static int
84    SetSocketOption(int fd, int level, int option_name, int option_value);
85
86    bool
87    SetSocketReceiveTimeout (uint32_t timeout_usec);
88
89private:
90    DISALLOW_COPY_AND_ASSIGN (ConnectionFileDescriptor);
91};
92
93} // namespace lldb_private
94
95#endif  // liblldb_ConnectionFileDescriptor_h_
96