mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-09 20:52:54 +00:00
We have a new, improved string type coming up in AK (OOM aware, no null state), and while it's going to use UTF-8, the name UTF8String is a mouthful - so let's free up the String name by renaming the existing class. Making the old one have an annoying name will hopefully also help with quick adoption :^)
50 lines
1.1 KiB
C++
50 lines
1.1 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/HashMap.h>
|
|
#include <RequestServer/Protocol.h>
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
namespace RequestServer {
|
|
|
|
static HashMap<DeprecatedString, Protocol*>& all_protocols()
|
|
{
|
|
static HashMap<DeprecatedString, Protocol*> map;
|
|
return map;
|
|
}
|
|
|
|
Protocol* Protocol::find_by_name(DeprecatedString const& name)
|
|
{
|
|
return all_protocols().get(name).value_or(nullptr);
|
|
}
|
|
|
|
Protocol::Protocol(DeprecatedString const& name)
|
|
{
|
|
all_protocols().set(name, this);
|
|
}
|
|
|
|
Protocol::~Protocol()
|
|
{
|
|
// FIXME: Do proper de-registration.
|
|
VERIFY_NOT_REACHED();
|
|
}
|
|
|
|
ErrorOr<Protocol::Pipe> Protocol::get_pipe_for_request()
|
|
{
|
|
int fd_pair[2] { 0 };
|
|
if (pipe(fd_pair) != 0) {
|
|
auto saved_errno = errno;
|
|
dbgln("Protocol: pipe() failed: {}", strerror(saved_errno));
|
|
return Error::from_errno(saved_errno);
|
|
}
|
|
fcntl(fd_pair[1], F_SETFL, fcntl(fd_pair[1], F_GETFL) | O_NONBLOCK);
|
|
return Pipe { fd_pair[0], fd_pair[1] };
|
|
}
|
|
|
|
}
|