ladybird/Libraries/LibCore/CSocketAddress.h
Robin Burchell ffa8cb668f AudioServer: Assorted infrastructure work
* Add a LibAudio, and move WAV file parsing there (via AWavFile and AWavLoader)
* Add CLocalSocket, and CSocket::connect() variant for local address types.
  We make some small use of this in WindowServer (as that's where we
  modelled it from), but don't get too invasive as this PR is already
  quite large, and the WS I/O is a bit carefully done
* Add an AClientConnection which will eventually be used to talk to
  AudioServer (and make use of it in Piano, though right now it really
  doesn't do anything except connect, using our new CLocalSocket...)
2019-07-13 22:57:24 +02:00

48 lines
1 KiB
C++

#pragma once
#include <AK/IPv4Address.h>
class CSocketAddress {
public:
enum class Type {
Invalid,
IPv4,
Local
};
CSocketAddress() {}
CSocketAddress(const IPv4Address& address)
: m_type(Type::IPv4)
, m_ipv4_address(address)
{
}
static CSocketAddress local(const String& address)
{
CSocketAddress addr;
addr.m_type = Type::Local;
addr.m_local_address = address;
return addr;
}
Type type() const { return m_type; }
bool is_valid() const { return m_type != Type::Invalid; }
IPv4Address ipv4_address() const { return m_ipv4_address; }
String to_string() const
{
switch (m_type) {
case Type::IPv4:
return m_ipv4_address.to_string();
case Type::Local:
return m_local_address;
default:
return "[CSocketAddress]";
}
}
private:
Type m_type { Type::Invalid };
IPv4Address m_ipv4_address;
String m_local_address;
};