libtasks Documentation  1.6
http_base.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 ADTECH GmbH
3  * Licensed under MIT (https://github.com/adtechlabs/libtasks/blob/master/COPYING)
4  *
5  * Author: Andreas Pohl
6  */
7 
8 #include <sys/socket.h>
9 #include <tasks/logging.h>
10 
11 #include <tasks/net/http_base.h>
12 #include <tasks/net/socket.h>
13 
14 namespace tasks {
15 namespace net {
16 
17 const std::string http_base::NO_VAL;
18 
20  // Fill the data buffer in ready state
21  if (io_state::READY == m_state) {
24  }
25  // Write data buffer
27  write_headers(sock);
28  if (!m_data_buffer.to_read()) {
29  if (m_content_buffer.size()) {
31  } else {
33  }
34  }
35  }
36  // Write content buffer
38  write_content(sock);
39  if (!m_content_buffer.to_read()) {
41  }
42  }
43 }
44 
46  std::streamsize bytes = sock.write(m_data_buffer.ptr_read(), m_data_buffer.to_read());
47  if (bytes > 0) {
48  tdbg("http_base: wrote data successfully, " << bytes << "/" << m_data_buffer.size() << " bytes" << std::endl);
50  }
51 }
52 
54  std::streamsize bytes = sock.write(m_content_buffer.ptr_read(), m_content_buffer.to_read());
55  if (bytes > 0) {
56  tdbg("http_base: wrote content successfully, " << bytes << "/" << m_content_buffer.size() << " bytes"
57  << std::endl);
59  }
60 }
61 
62 } // net
63 } // tasks
void write_content(socket &sock)
Definition: http_base.cpp:53
tasks::tools::buffer m_data_buffer
Definition: http_base.h:130
void write_data(socket &sock)
Write a HTTP object to a socket.
Definition: http_base.cpp:19
std::size_t size() const
Definition: buffer.h:70
char * ptr_read()
Definition: buffer.h:32
virtual void prepare_data_buffer()=0
Prepare a HTTP request/response to be sent.
std::streamsize write(const char *data, std::size_t len, int port=-1, std::string ip="")
Definition: socket.cpp:225
void write_headers(socket &sock)
Definition: http_base.cpp:45
void move_ptr_read(std::size_t s)
Definition: buffer.h:60
#define tdbg(m)
Definition: logging.h:54
The socket class.
Definition: socket.h:35
tasks::tools::buffer m_content_buffer
Definition: http_base.h:131
std::streamsize to_read() const
Definition: buffer.h:68
static const std::string NO_VAL
Definition: http_base.h:32