ladybird/Userland/Services/ProtocolServer/Protocol.cpp
Brian Gianforcaro 1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00

50 lines
1.0 KiB
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/HashMap.h>
#include <ProtocolServer/Protocol.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
namespace ProtocolServer {
static HashMap<String, Protocol*>& all_protocols()
{
static HashMap<String, Protocol*> map;
return map;
}
Protocol* Protocol::find_by_name(const String& name)
{
return all_protocols().get(name).value_or(nullptr);
}
Protocol::Protocol(const String& name)
{
all_protocols().set(name, this);
}
Protocol::~Protocol()
{
VERIFY_NOT_REACHED();
}
Result<Protocol::Pipe, String> Protocol::get_pipe_for_download()
{
int fd_pair[2] { 0 };
if (pipe(fd_pair) != 0) {
auto saved_errno = errno;
dbgln("Protocol: pipe() failed: {}", strerror(saved_errno));
return String { strerror(saved_errno) };
}
fcntl(fd_pair[1], F_SETFL, fcntl(fd_pair[1], F_GETFL) | O_NONBLOCK);
return Pipe { fd_pair[0], fd_pair[1] };
}
}