Skip to content

Commit

Permalink
LibCore: Rename Udp classes to UDP
Browse files Browse the repository at this point in the history
The kernel was already using the UDP prefix, and the TCP LibCore classes
are also uppercased. Let's rename for consistency.

Also order the LibCore Makefile alphabetically, because everywhere else
seems to be doing that :)
  • Loading branch information
shannonbooth authored and awesomekling committed Mar 14, 2020
1 parent 149a9ba commit 5dc5b8a
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 47 deletions.
4 changes: 2 additions & 2 deletions Libraries/LibCore/Forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class TCPServer;
class TCPSocket;
class Timer;
class TimerEvent;
class UdpServer;
class UdpSocket;
class UDPServer;
class UDPSocket;

enum class TimerShouldFireWhenNotVisible;

Expand Down
38 changes: 19 additions & 19 deletions Libraries/LibCore/Makefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
OBJS = \
ArgsParser.o \
ConfigFile.o \
DateTime.o \
IODevice.o \
File.o \
SocketAddress.o \
Socket.o \
LocalSocket.o \
LocalServer.o \
TCPSocket.o \
TCPServer.o \
UdpSocket.o \
UdpServer.o \
DirIterator.o \
ElapsedTimer.o \
MimeData.o \
Notifier.o \
Event.o \
EventLoop.o \
File.o \
Gzip.o \
HttpJob.o \
HttpRequest.o \
HttpResponse.o \
HttpJob.o \
IODevice.o \
LocalServer.o \
LocalSocket.o \
MimeData.o \
NetworkJob.o \
NetworkResponse.o \
Notifier.o \
Object.o \
Timer.o \
EventLoop.o \
ConfigFile.o \
Event.o \
ProcessStatisticsReader.o \
DirIterator.o \
Socket.o \
SocketAddress.o \
TCPServer.o \
TCPSocket.o \
Timer.o \
UDPServer.o \
UDPSocket.o \
UserInfo.o \
Gzip.o \
puff.o

LIBRARY = libcore.a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@
#include <AK/IPv4Address.h>
#include <AK/Types.h>
#include <LibCore/Notifier.h>
#include <LibCore/UdpServer.h>
#include <LibCore/UdpSocket.h>
#include <LibCore/UDPServer.h>
#include <LibCore/UDPSocket.h>
#include <stdio.h>
#include <sys/socket.h>

namespace Core {

UdpServer::UdpServer(Object* parent)
UDPServer::UDPServer(Object* parent)
: Object(parent)
{
m_fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
ASSERT(m_fd >= 0);
}

UdpServer::~UdpServer()
UDPServer::~UDPServer()
{
}

bool UdpServer::listen(const IPv4Address& address, u16 port)
bool UDPServer::listen(const IPv4Address& address, u16 port)
{
if (m_listening)
return false;
Expand All @@ -68,7 +68,7 @@ bool UdpServer::listen(const IPv4Address& address, u16 port)
return true;
}

RefPtr<UdpSocket> UdpServer::accept()
RefPtr<UDPSocket> UDPServer::accept()
{
ASSERT(m_listening);
sockaddr_in in;
Expand All @@ -79,10 +79,10 @@ RefPtr<UdpSocket> UdpServer::accept()
return nullptr;
}

return UdpSocket::construct(accepted_fd);
return UDPSocket::construct(accepted_fd);
}

Optional<IPv4Address> UdpServer::local_address() const
Optional<IPv4Address> UDPServer::local_address() const
{
if (m_fd == -1)
return {};
Expand All @@ -95,7 +95,7 @@ Optional<IPv4Address> UdpServer::local_address() const
return IPv4Address(address.sin_addr.s_addr);
}

Optional<u16> UdpServer::local_port() const
Optional<u16> UDPServer::local_port() const
{
if (m_fd == -1)
return {};
Expand Down
10 changes: 5 additions & 5 deletions Libraries/LibCore/UdpServer.h → Libraries/LibCore/UDPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@

namespace Core {

class UdpServer : public Object {
C_OBJECT(UdpServer)
class UDPServer : public Object {
C_OBJECT(UDPServer)
public:
virtual ~UdpServer() override;
virtual ~UDPServer() override;

bool is_listening() const { return m_listening; }
bool listen(const IPv4Address& address, u16 port);

RefPtr<UdpSocket> accept();
RefPtr<UDPSocket> accept();

Optional<IPv4Address> local_address() const;
Optional<u16> local_port() const;

Function<void()> on_ready_to_accept;

private:
explicit UdpServer(Object* parent = nullptr);
explicit UDPServer(Object* parent = nullptr);

int m_fd { -1 };
bool m_listening { false };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <LibCore/UdpSocket.h>
#include <LibCore/UDPSocket.h>
#include <errno.h>
#include <sys/socket.h>

namespace Core {

UdpSocket::UdpSocket(int fd, Object* parent)
UDPSocket::UDPSocket(int fd, Object* parent)
: Socket(Socket::Type::UDP, parent)
{
// NOTE: This constructor is used by UdpServer::accept(), so the socket is already connected.
// NOTE: This constructor is used by UDPServer::accept(), so the socket is already connected.
m_connected = true;
set_fd(fd);
set_mode(IODevice::ReadWrite);
set_error(0);
}

UdpSocket::UdpSocket(Object* parent)
UDPSocket::UDPSocket(Object* parent)
: Socket(Socket::Type::UDP, parent)
{
int fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, 0);
Expand All @@ -53,7 +53,7 @@ UdpSocket::UdpSocket(Object* parent)
}
}

UdpSocket::~UdpSocket()
UDPSocket::~UDPSocket()
{
}

Expand Down
10 changes: 5 additions & 5 deletions Libraries/LibCore/UdpSocket.h → Libraries/LibCore/UDPSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@

namespace Core {

class UdpSocket final : public Socket {
C_OBJECT(UdpSocket)
class UDPSocket final : public Socket {
C_OBJECT(UDPSocket)
public:
virtual ~UdpSocket() override;
virtual ~UDPSocket() override;

private:
UdpSocket(int fd, Object* parent = nullptr);
explicit UdpSocket(Object* parent = nullptr);
UDPSocket(int fd, Object* parent = nullptr);
explicit UDPSocket(Object* parent = nullptr);
};

}
4 changes: 2 additions & 2 deletions Servers/LookupServer/LookupServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <LibCore/File.h>
#include <LibCore/LocalServer.h>
#include <LibCore/LocalSocket.h>
#include <LibCore/UdpSocket.h>
#include <LibCore/UDPSocket.h>
#include <stdio.h>
#include <unistd.h>

Expand Down Expand Up @@ -176,7 +176,7 @@ Vector<String> LookupServer::lookup(const String& hostname, bool& did_timeout, u

auto buffer = request.to_byte_buffer();

auto udp_socket = Core::UdpSocket::construct();
auto udp_socket = Core::UDPSocket::construct();
udp_socket->set_blocking(true);

struct timeval timeout {
Expand Down

0 comments on commit 5dc5b8a

Please sign in to comment.