X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fapi%2Finternal%2Fio%2FBamHttp_p.h;h=cbbc95c602ccaf174ba119850abbcc74816392f2;hb=153d8f44a0ae6aebd0323289d961e5c00ea2b212;hp=38e94b7dcdd4e12ff7a8da8e7cb0bd70878bf514;hpb=90432a3736392f98803a5e8787f3db0dc5bb44ad;p=bamtools.git diff --git a/src/api/internal/io/BamHttp_p.h b/src/api/internal/io/BamHttp_p.h index 38e94b7..cbbc95c 100644 --- a/src/api/internal/io/BamHttp_p.h +++ b/src/api/internal/io/BamHttp_p.h @@ -2,7 +2,7 @@ // BamHttp_p.h (c) 2011 Derek Barnett // Marth Lab, Department of Biology, Boston College // --------------------------------------------------------------------------- -// Last modified: 10 October 2011 (DB) +// Last modified: 10 November 2011 (DB) // --------------------------------------------------------------------------- // Provides reading/writing of BAM files on HTTP server // *************************************************************************** @@ -26,6 +26,10 @@ namespace BamTools { namespace Internal { +class HttpRequestHeader; +class HttpResponseHeader; +class TcpSocket; + class BamHttp : public IBamIODevice { // ctor & dtor @@ -36,18 +40,49 @@ class BamHttp : public IBamIODevice { // IBamIODevice implementation public: void Close(void); + bool IsOpen(void) const; bool IsRandomAccess(void) const; bool Open(const IBamIODevice::OpenMode mode); - size_t Read(char* data, const unsigned int numBytes); - bool Seek(const int64_t& position); + int64_t Read(char* data, const unsigned int numBytes); + bool Seek(const int64_t& position, const int origin = SEEK_SET); int64_t Tell(void) const; - size_t Write(const char* data, const unsigned int numBytes); + int64_t Write(const char* data, const unsigned int numBytes); // internal methods private: + void ClearResponse(void); + bool ConnectSocket(void); + void DisconnectSocket(void); + bool EnsureSocketConnection(void); + void ParseUrl(const std::string& url); + int64_t ReadFromSocket(char* data, const unsigned int numBytes); + bool ReceiveResponse(void); + bool SendGetRequest(const size_t numBytes = 0x10000); + bool SendHeadRequest(void); + int64_t WriteToSocket(const char* data, const unsigned int numBytes); // data members private: + + // our main socket + TcpSocket* m_socket; + + // our connection data + std::string m_hostname; + std::string m_port; + std::string m_filename; + + // our last (active) request & response info + HttpRequestHeader* m_request; + HttpResponseHeader* m_response; + + // internal state flags + bool m_isUrlParsed; + + // file position + int64_t m_filePosition; + int64_t m_fileEndPosition; + int64_t m_rangeEndPosition; }; } // namespace Internal