Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement DSCP on udp connection #1868

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion core/vibe/core/drivers/libasync.d
Original file line number Diff line number Diff line change
Expand Up @@ -1706,7 +1706,12 @@ final class LibasyncUDPConnection : UDPConnection {
}
}

void addMembership(ref NetworkAddress multiaddr)
override void setDSCP(uint codePoint)
{
assert(false, "TODO!");
}

override void addMembership(ref NetworkAddress multiaddr)
{
assert(false, "TODO!");
}
Expand Down
16 changes: 15 additions & 1 deletion core/vibe/core/drivers/libevent2.d
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,18 @@ version(Windows)
version(OSX)
{
import std.c.osx.socket : IP_ADD_MEMBERSHIP, IP_MULTICAST_LOOP;
static const IP_TOS = 3;
} else version(linux)
{
import std.c.linux.socket : IP_ADD_MEMBERSHIP, IP_MULTICAST_LOOP;
static const IP_TOS = 1;
} else version(Posix)
{
import std.c.linux.socket : IP_ADD_MEMBERSHIP, IP_MULTICAST_LOOP;
static const IP_TOS = 3;
} else version(Windows)
{
// IP_ADD_MEMBERSHIP and IP_MULTICAST_LOOP are included in winsock(2) import above
// IP_ADD_MEMBERSHIP, IP_MULTICAST_LOOP and IP_TOS are included in winsock(2) import above
}

final class Libevent2Driver : EventDriver {
Expand Down Expand Up @@ -1093,6 +1099,14 @@ final class Libevent2UDPConnection : UDPConnection {
}
}

override void setDSCP(ubyte codePoint)
{
int tmp_cp = codePoint;
enforce(codePoint < 64, "Differentiated Services Code Point is only 6 bits");
enforce(() @trusted { return setsockopt(m_ctx.socketfd, IPPROTO_IP, IP_TOS, &tmp_cp, tmp_cp.sizeof); } () == 0,
"Failed to set Differentiated Services Code Point");
}

override void addMembership(ref NetworkAddress multiaddr)
{
if (multiaddr.family == AF_INET)
Expand Down
7 changes: 6 additions & 1 deletion core/vibe/core/drivers/win32.d
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,12 @@ final class Win32UDPConnection : UDPConnection, SocketEventHandler {
assert(false);
}

void addMembership(ref NetworkAddress multiaddr)
override void setDSCP(uint codePoint)
{
assert(false, "TODO!");
}

override void addMembership(ref NetworkAddress multiaddr)
{
assert(false, "TODO!");
}
Expand Down
9 changes: 8 additions & 1 deletion core/vibe/core/net.d
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,14 @@ interface UDPConnection {
/// ditto
ubyte[] recv(Duration timeout, ubyte[] buf = null, NetworkAddress* peer_address = null);

/** Become member of IP multicast group
/** Set Differentiated Services Code Point

Used for Quality of Service. 6bit number, higher is more priority.
see https://www.iana.org/assignments/dscp-registry/dscp-registry.xhtml
*/
void setDSCP(ubyte codePoint);

/** Become member of IP multicast group
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A trailing space slipped in here.


The multiaddr parameter should be in the range 239.0.0.0-239.255.255.255.
See https://www.iana.org/assignments/multicast-addresses/multicast-addresses.xml#multicast-addresses-12
Expand Down