2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2016-09-02 21:12:59 -07:00
|
|
|
|
2018-04-29 23:33:19 -07:00
|
|
|
#include "wpi/raw_socket_ostream.h"
|
2017-10-21 20:31:20 -07:00
|
|
|
|
2018-04-29 23:33:19 -07:00
|
|
|
#include "wpi/NetworkStream.h"
|
2016-09-02 21:12:59 -07:00
|
|
|
|
|
|
|
|
using namespace wpi;
|
|
|
|
|
|
|
|
|
|
raw_socket_ostream::~raw_socket_ostream() {
|
|
|
|
|
flush();
|
2020-12-28 12:58:06 -08:00
|
|
|
if (m_shouldClose) {
|
|
|
|
|
close();
|
|
|
|
|
}
|
2016-09-02 21:12:59 -07:00
|
|
|
}
|
|
|
|
|
|
2017-10-21 20:31:20 -07:00
|
|
|
void raw_socket_ostream::write_impl(const char* data, size_t len) {
|
|
|
|
|
size_t pos = 0;
|
2016-09-02 21:12:59 -07:00
|
|
|
|
|
|
|
|
while (pos < len) {
|
|
|
|
|
NetworkStream::Error err;
|
2017-10-21 20:31:20 -07:00
|
|
|
size_t count = m_stream.send(&data[pos], len - pos, &err);
|
2016-09-02 21:12:59 -07:00
|
|
|
if (count == 0) {
|
|
|
|
|
error_detected();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
pos += count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 12:58:06 -08:00
|
|
|
uint64_t raw_socket_ostream::current_pos() const {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2016-09-02 21:12:59 -07:00
|
|
|
|
|
|
|
|
void raw_socket_ostream::close() {
|
2020-12-28 12:58:06 -08:00
|
|
|
if (!m_shouldClose) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-09-02 21:12:59 -07:00
|
|
|
flush();
|
|
|
|
|
m_stream.close();
|
|
|
|
|
}
|