1 // ***************************************************************************
2 // TcpSocketEngine_p.h (c) 2011 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 10 November 2011 (DB)
6 // ---------------------------------------------------------------------------
7 // Provides low-level implementation of TCP I/O
8 // ***************************************************************************
10 #ifndef TCPSOCKETENGINE_P_H
11 #define TCPSOCKETENGINE_P_H
17 // This file is not part of the BamTools API. It exists purely as an
18 // implementation detail. This header file may change from version to version
19 // without notice, or even be removed.
23 #include "api/internal/io/HostAddress_p.h"
24 #include "api/internal/io/TcpSocket_p.h"
29 struct TcpSocketEngine {
33 TcpSocketEngine(void);
34 TcpSocketEngine(const TcpSocketEngine& other);
35 ~TcpSocketEngine(void);
37 // TcpSocketEngine interface
40 // connection-related methods
42 bool Connect(const HostAddress& address, const uint16_t port);
43 bool Initialize(HostAddress::NetworkProtocol protocol);
44 bool IsValid(void) const;
47 int64_t NumBytesAvailable(void) const;
48 int64_t Read(char* dest, size_t max);
49 int64_t Write(const char* data, size_t length);
51 bool WaitForRead(int msec, bool* timedOut);
52 bool WaitForWrite(int msec, bool* timedOut);
54 // query connection state
55 // HostAddress GetLocalAddress(void) const;
56 // uint16_t GetLocalPort(void) const;
57 HostAddress GetRemoteAddress(void) const;
58 uint16_t GetRemotePort(void) const;
60 int GetSocketDescriptor(void) const;
61 TcpSocket::SocketError GetSocketError(void);
62 TcpSocket::SocketState GetSocketState(void);
64 std::string GetErrorString(void) const;
66 // platform-dependent internal methods
67 // provided in the corresponding TcpSocketEngine_<OS>_p.cpp
69 void nativeClose(void);
70 bool nativeConnect(const HostAddress& address, const uint16_t port);
71 bool nativeCreateSocket(HostAddress::NetworkProtocol protocol);
72 void nativeDisconnect(void);
73 int64_t nativeNumBytesAvailable(void) const;
74 int64_t nativeRead(char* dest, size_t max);
75 int nativeSelect(int msecs, bool isRead) const;
76 int64_t nativeWrite(const char* data, size_t length);
80 int m_socketDescriptor;
82 // HostAddress m_localAddress;
83 HostAddress m_remoteAddress;
84 // uint16_t m_localPort;
85 uint16_t m_remotePort;
87 TcpSocket::SocketError m_socketError;
88 TcpSocket::SocketState m_socketState;
89 std::string m_errorString;
92 } // namespace Internal
93 } // namespace BamTools
95 #endif // TCPSOCKETENGINE_P_H