Skip to content

Commit

Permalink
Merge pull request #296 from kubo39/fd-in-net
Browse files Browse the repository at this point in the history
Add fd() method for TCPConnection/UDPConnection
  • Loading branch information
s-ludwig authored Sep 25, 2021
2 parents 49643ec + 384f625 commit 12f7ddc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions source/vibe/core/net.d
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ struct TCPConnection {
releaseHandle!"sockets"(m_socket, m_context.driver);
}

@property int fd() const nothrow { return cast(int)m_socket; }

bool opCast(T)() const nothrow if (is(T == bool)) { return m_socket != StreamSocketFD.invalid; }

@property void tcpNoDelay(bool enabled) nothrow { eventDriver.sockets.setTCPNoDelay(m_socket, enabled); m_context.tcpNoDelay = enabled; }
Expand Down Expand Up @@ -971,6 +973,8 @@ struct UDPConnection {
releaseHandle!"sockets"(m_socket, m_context.driver);
}

@property int fd() const nothrow { return cast(int)m_socket; }

bool opCast(T)() const nothrow if (is(T == bool)) { return m_socket != DatagramSocketFD.invalid; }

/** Returns the address to which the UDP socket is bound.
Expand Down
2 changes: 2 additions & 0 deletions tests/0-tcp.d
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
+/
module tests;

import eventcore.core;
import vibe.core.core;
import vibe.core.log;
import vibe.core.net;
Expand All @@ -29,6 +30,7 @@ void test1()
lt = Task.getThis();
try {
while (!conn.empty) {
assert(conn.fd() != StreamSocketFD.invalid);
assert(conn.readLine() == "next");
auto curtest = test;
conn.write("continue\n");
Expand Down

0 comments on commit 12f7ddc

Please sign in to comment.