| 1576 | }; |
| 1577 | |
| 1578 | CurlIo::CurlImpl::CurlImpl(const std::string& url, size_t blockSize) : Impl(url, blockSize), curl_(curl_easy_init()) { |
| 1579 | if (!curl_) { |
| 1580 | throw Error(ErrorCode::kerErrorMessage, "Unable to init libcurl."); |
| 1581 | } |
| 1582 | |
| 1583 | // The default block size for FTP is much larger than other protocols |
| 1584 | // the reason is that getDataByRange() in FTP always creates the new connection, |
| 1585 | // so we need the large block size to reduce the overhead of creating the connection. |
| 1586 | if (blockSize_ == 0) { |
| 1587 | blockSize_ = protocol_ == pFtp ? 102400 : 1024; |
| 1588 | } |
| 1589 | |
| 1590 | std::string timeout = getEnv(envTIMEOUT); |
| 1591 | timeout_ = atol(timeout.c_str()); |
| 1592 | if (timeout_ == 0) { |
| 1593 | throw Error(ErrorCode::kerErrorMessage, "Timeout Environmental Variable must be a positive integer."); |
| 1594 | } |
| 1595 | } |
| 1596 | |
| 1597 | int64_t CurlIo::CurlImpl::getFileLength() { |
| 1598 | curl_easy_reset(curl_); // reset all options |