]> git.donarmstrong.com Git - bamtools.git/blobdiff - src/api/internal/io/TcpSocket_p.cpp
Stablized HTTP access on all platforms. (issue #54, issue #11)
[bamtools.git] / src / api / internal / io / TcpSocket_p.cpp
index 619571051b2eb2707d591d63c0b2f83fc7f522c4..d3909326dbd238823cb4bcaa9bf699cbbbc104c2 100644 (file)
@@ -2,7 +2,7 @@
 // TcpSocket_p.cpp (c) 2011 Derek Barnett
 // Marth Lab, Department of Biology, Boston College
 // ---------------------------------------------------------------------------
-// Last modified: 8 December 2011 (DB)
+// Last modified: 5 January 2012 (DB)
 // ---------------------------------------------------------------------------
 // Provides basic TCP I/O interface
 // ***************************************************************************
@@ -14,6 +14,7 @@ using namespace BamTools;
 using namespace BamTools::Internal;
 
 #include <algorithm>
+#include <climits>
 #include <sstream>
 #include <vector>
 using namespace std;
@@ -26,7 +27,7 @@ namespace BamTools {
 namespace Internal {
 
 // constants
-static const size_t DEFAULT_BUFFER_SIZE = 0x4000;
+static const size_t DEFAULT_BUFFER_SIZE = 0x10000;
 
 } // namespace Internal
 } // namespace BamTools
@@ -42,7 +43,7 @@ TcpSocket::TcpSocket(void)
     , m_engine(0)
     , m_cachedSocketDescriptor(-1)
     , m_readBuffer(DEFAULT_BUFFER_SIZE)
-    , m_error(TcpSocket::UnknownSocketError)
+    , m_error(TcpSocket::NoError)
     , m_state(TcpSocket::UnconnectedState)
 { }
 
@@ -78,7 +79,7 @@ bool TcpSocket::ConnectImpl(const HostInfo& hostInfo,
     m_hostName   = hostInfo.HostName();
     m_mode       = mode;
     m_state      = TcpSocket::UnconnectedState;
-    m_error      = TcpSocket::UnknownSocketError;
+    m_error      = TcpSocket::NoError;
 //    m_localPort  = 0;
     m_remotePort = 0;
 //    m_localAddress.Clear();
@@ -313,8 +314,8 @@ string TcpSocket::ReadLine(int64_t max) {
 
     // prep result byte buffer
     ByteArray result;
-
-    size_t bufferMax = ((max > static_cast<int64_t>(string::npos)) ? string::npos : static_cast<size_t>(max));
+    size_t bufferMax = ((max > static_cast<int64_t>(UINT_MAX))
+                        ? UINT_MAX : static_cast<size_t>(max));
     result.Resize(bufferMax);
 
     // read data
@@ -322,7 +323,7 @@ string TcpSocket::ReadLine(int64_t max) {
     if ( result.Size() == 0 ) {
 
         if ( bufferMax == 0 )
-            bufferMax = string::npos;
+            bufferMax = UINT_MAX;
 
         result.Resize(1);