1 // ***************************************************************************
2 // TcpSocketEngine_p.h (c) 2011 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 8 December 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"
27 # include "api/internal/io/NetWin_p.h"
33 struct TcpSocketEngine {
37 TcpSocketEngine(void);
38 TcpSocketEngine(const TcpSocketEngine& other);
39 ~TcpSocketEngine(void);
41 // TcpSocketEngine interface
44 // connection-related methods
46 bool Connect(const HostAddress& address, const uint16_t port);
47 bool Initialize(HostAddress::NetworkProtocol protocol);
48 bool IsValid(void) const;
51 int64_t NumBytesAvailable(void) const;
52 int64_t Read(char* dest, size_t max);
53 int64_t Write(const char* data, size_t length);
55 bool WaitForRead(int msec, bool* timedOut);
56 bool WaitForWrite(int msec, bool* timedOut);
58 // query connection state
59 // HostAddress GetLocalAddress(void) const;
60 // uint16_t GetLocalPort(void) const;
61 HostAddress GetRemoteAddress(void) const;
62 uint16_t GetRemotePort(void) const;
64 int GetSocketDescriptor(void) const;
65 TcpSocket::SocketError GetSocketError(void);
66 TcpSocket::SocketState GetSocketState(void);
68 std::string GetErrorString(void) const;
70 // platform-dependent internal methods
71 // provided in the corresponding TcpSocketEngine_<OS>_p.cpp
73 void nativeClose(void);
74 bool nativeConnect(const HostAddress& address, const uint16_t port);
75 bool nativeCreateSocket(HostAddress::NetworkProtocol protocol);
76 void nativeDisconnect(void);
77 int64_t nativeNumBytesAvailable(void) const;
78 int64_t nativeRead(char* dest, size_t max);
79 int nativeSelect(int msecs, bool isRead) const;
80 int64_t nativeWrite(const char* data, size_t length);
84 int m_socketDescriptor;
86 // HostAddress m_localAddress;
87 HostAddress m_remoteAddress;
88 // uint16_t m_localPort;
89 uint16_t m_remotePort;
91 TcpSocket::SocketError m_socketError;
92 TcpSocket::SocketState m_socketState;
93 std::string m_errorString;
96 WindowsSockInit m_win;
100 } // namespace Internal
101 } // namespace BamTools
103 #endif // TCPSOCKETENGINE_P_H