xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
send_packets_element.h
Go to the documentation of this file.
1 #pragma once
5 
6 #include <fstream>
7 #include <functional>
8 #include <vector>
9 #include "../../ustring.h"
10 #include "../ip_address.h"
11 
13 #undef unix
14 
17 namespace xtd {
19  namespace net {
21  namespace sockets {
23  class socket;
25 
34  public:
36  using ifstream_ref = std::reference_wrapper<std::ifstream>;
37 
39  send_packets_element() = default;
40 
44  send_packets_element(const std::vector<byte_t>& buffer);
45 
54 
61  send_packets_element(const std::vector<byte_t>& buffer, size_t offset, size_t count, bool end_of_packet);
62 
69  send_packets_element(const xtd::ustring& file_path, size_t offset, size_t count);
70 
77  send_packets_element(std::ifstream& file_stream, size_t offset, size_t count, bool end_of_packet);
78 
84  send_packets_element(const std::vector<byte_t>& buffer, size_t offset, size_t count);
85 
91 
95  send_packets_element(std::ifstream& file_stream);
96 
101 
105  std::vector<byte_t> buffer() const noexcept;
106 
111  size_t count() const noexcept;
112 
116  bool end_of_packet() const noexcept;
117 
122  const xtd::ustring& file_path() const noexcept;
123 
127  std::optional<ifstream_ref> file_stream() const noexcept;
128 
132  size_t offset() const noexcept;
133 
134  private:
135  std::vector<byte_t> buffer_;
136  size_t count_ = 0;
137  bool end_of_packet_ = false;
138  xtd::ustring file_path_;
139  std::ifstream* file_stream_ = nullptr;
140  size_t offset_ = 0;
141  bool delete_file_stream_when_destroy_ = false;
142  };
143  }
144  }
145 }
Implements the Berkeley sockets interface.
Definition: socket.h:63
const xtd::ustring & file_path() const noexcept
Gets the filename of the file to send if the xtd::net::sockets::send_packets_element object was initi...
size_t offset() const noexcept
Gets the offset, in bytes, from the beginning of the data buffer or file to the location in the buffe...
std::optional< ifstream_ref > file_stream() const noexcept
Gets the object representation of the file to send if the xtd::net::sockets::send_packets_element obj...
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
bool end_of_packet() const noexcept
Gets a bool value that indicates if this element should not be combined with the next element in a si...
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
Represents an element in a xtd::net::sockets::send_packets_element array.
Definition: send_packets_element.h:33
Socket options apply to all sockets.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:26
std::reference_wrapper< std::ifstream > ifstream_ref
Represent ta std::ifstream reference.
Definition: send_packets_element.h:36
size_t count() const noexcept
Gets the count of bytes to be sent.
std::vector< byte_t > buffer() const noexcept
Gets the buffer to be sent if the xtd::net::sockets::send_packets_element object was initialized with...
send_packets_element()=default
Initializes a new instance of the xtd::net::sockets::send_packets_element class.