mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 19:47:42 +00:00
Kernel: Add SocketRole::Listener and report the role nicely in /proc/PID/fds.
This commit is contained in:
parent
a0b55987d3
commit
df2d46d5dc
3 changed files with 17 additions and 2 deletions
|
@ -318,6 +318,20 @@ int FileDescriptor::close()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* to_string(SocketRole role)
|
||||||
|
{
|
||||||
|
switch (role) {
|
||||||
|
case SocketRole::Listener:
|
||||||
|
return "Listener";
|
||||||
|
case SocketRole::Accepted:
|
||||||
|
return "Accepted";
|
||||||
|
case SocketRole::Connected:
|
||||||
|
return "Connected";
|
||||||
|
default:
|
||||||
|
return "None";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String FileDescriptor::absolute_path()
|
String FileDescriptor::absolute_path()
|
||||||
{
|
{
|
||||||
Stopwatch sw("absolute_path");
|
Stopwatch sw("absolute_path");
|
||||||
|
@ -328,7 +342,7 @@ String FileDescriptor::absolute_path()
|
||||||
if (is_device())
|
if (is_device())
|
||||||
return String::format("device:%u,%u (%s)", m_device->major(), m_device->minor(), m_device->class_name());
|
return String::format("device:%u,%u (%s)", m_device->major(), m_device->minor(), m_device->class_name());
|
||||||
if (is_socket())
|
if (is_socket())
|
||||||
return String::format("socket:%x (role: %u)", m_socket.ptr(), m_socket_role);
|
return String::format("socket:%x (role: %s)", m_socket.ptr(), to_string(m_socket_role));
|
||||||
ASSERT(m_inode);
|
ASSERT(m_inode);
|
||||||
return VFS::the().absolute_path(*m_inode);
|
return VFS::the().absolute_path(*m_inode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2267,6 +2267,7 @@ int Process::sys$listen(int sockfd, int backlog)
|
||||||
int error;
|
int error;
|
||||||
if (!socket.listen(backlog, error))
|
if (!socket.listen(backlog, error))
|
||||||
return error;
|
return error;
|
||||||
|
descriptor->set_socket_role(SocketRole::Listener);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <Kernel/UnixTypes.h>
|
#include <Kernel/UnixTypes.h>
|
||||||
|
|
||||||
enum class SocketRole { None, Accepted, Connected };
|
enum class SocketRole { None, Listener, Accepted, Connected };
|
||||||
|
|
||||||
class Socket : public Retainable<Socket> {
|
class Socket : public Retainable<Socket> {
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue