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.
|
2018-07-17 01:06:24 -07:00
|
|
|
|
|
|
|
|
#include "wpi/uv/NetworkStream.h"
|
|
|
|
|
|
|
|
|
|
namespace wpi {
|
|
|
|
|
namespace uv {
|
|
|
|
|
|
|
|
|
|
ConnectReq::ConnectReq() {
|
|
|
|
|
error = [this](Error err) { GetStream().error(err); };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NetworkStream::Listen(int backlog) {
|
|
|
|
|
Invoke(&uv_listen, GetRawStream(), backlog,
|
|
|
|
|
[](uv_stream_t* handle, int status) {
|
|
|
|
|
auto& h = *static_cast<NetworkStream*>(handle->data);
|
2020-12-28 12:58:06 -08:00
|
|
|
if (status < 0) {
|
2018-07-17 01:06:24 -07:00
|
|
|
h.ReportError(status);
|
2020-12-28 12:58:06 -08:00
|
|
|
} else {
|
2018-07-17 01:06:24 -07:00
|
|
|
h.connection();
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2018-07-17 01:06:24 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NetworkStream::Listen(std::function<void()> callback, int backlog) {
|
|
|
|
|
connection.connect(callback);
|
|
|
|
|
Listen(backlog);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace uv
|
|
|
|
|
} // namespace wpi
|