Ejemplo n.º 1
0
    virtual size_t read(void* ptr, size_t bytes) override {
        assert(0 <= m_send_data_progress);
        assert(m_send_data_progress <= static_cast<int64_t>(m_send_data.size()));

        if(m_cancel) { return 0; }

        auto send_bytes = std::min(static_cast<int64_t>(bytes), static_cast<int64_t>(m_send_data.size()) - m_send_data_progress);
        std::memcpy(ptr, m_send_data.data() + m_send_data_progress, send_bytes);
        m_send_data_progress += send_bytes;

        return send_bytes;
    }
Ejemplo n.º 2
0
void connection::write(http::buffer const& message, completion_handler&& handler)
{
    LOG_COMP_TRACE_FUNCTION(connection);

    connection_->write_buffer(message, std::forward<completion_handler>(handler));

    context_.get_statistics_manager().add_output_message(message.size());
}
Ejemplo n.º 3
0
 virtual bool seek(int64_t offset, int origin) override {
     if(m_send_file) {
         switch(origin) {
             case SEEK_SET:
             case SEEK_CUR:
             case SEEK_END:  return (std::fseek(m_send_file.get(), static_cast<long>(offset), origin) != 0);
             default:        assert(false); return false;
         }
     } else {
         switch(origin) {
             case SEEK_SET:  m_send_data_progress  = offset;                         return true;
             case SEEK_CUR:  m_send_data_progress += offset;                         return true;
             case SEEK_END:  m_send_data_progress  = offset + m_send_data.size();    return true;
             default:        assert(false);                                          return false;
         }
     }
 }
Ejemplo n.º 4
0
    void prepare_send_data() {
        assert(m_post_form.empty());

        if(!m_send_data.empty()) {
            assert(!m_send_file);
            curl_easy_setopt(handle, CURLOPT_INFILESIZE_LARGE,  static_cast<curl_off_t>(m_send_data.size()));
            curl_easy_setopt(handle, CURLOPT_UPLOAD,            1);
        }

        if(m_send_file) {
            assert(m_send_data.empty());

            // set the FILE pointer as read data in CURL
            curl_easy_setopt(handle, CURLOPT_READFUNCTION,      nullptr);
            curl_easy_setopt(handle, CURLOPT_READDATA,          m_send_file.get());
            curl_easy_setopt(handle, CURLOPT_INFILESIZE_LARGE,  static_cast<curl_off_t>(m_send_file_size));
            curl_easy_setopt(handle, CURLOPT_UPLOAD,            1);
        }
    }