Skip to content

Commit

Permalink
Made the fix apply to all unices and added a unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrempus committed Aug 19, 2013
1 parent 7006ac9 commit c3b1ac1
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions std/socket.d
Expand Up @@ -73,14 +73,10 @@ version(Windows)
else version(Posix)
{
version(linux)
{
import std.c.linux.socket : AF_IPX, AF_APPLETALK, SOCK_RDM,
IPPROTO_IGMP, IPPROTO_GGP, IPPROTO_PUP, IPPROTO_IDP,
SD_RECEIVE, SD_SEND, SD_BOTH, MSG_NOSIGNAL, INADDR_NONE,
TCP_KEEPIDLE, TCP_KEEPINTVL;

import core.sys.posix.sys.un : sockaddr_un;
}
else version(OSX)
import std.c.osx.socket : AF_IPX, AF_APPLETALK, SOCK_RDM,
IPPROTO_IGMP, IPPROTO_GGP, IPPROTO_PUP, IPPROTO_IDP,
Expand All @@ -98,6 +94,7 @@ else version(Posix)
static assert(false);

import core.sys.posix.netdb;
import core.sys.posix.sys.un : sockaddr_un;
private import core.sys.posix.fcntl;
private import core.sys.posix.unistd;
private import core.sys.posix.arpa.inet;
Expand Down Expand Up @@ -1914,6 +1911,40 @@ static if (is(sockaddr_un))
return path;
}
}

unittest
{
import core.stdc.stdio : remove;

immutable ubyte[] data = [1, 2, 3, 4];
Socket[2] pair;

auto name = "unix-address-family-unittest-socket-name";
auto address = new UnixAddress(name);

auto listener = new Socket(AddressFamily.UNIX, SocketType.STREAM);
scope(exit) listener.close();

listener.bind(address);
scope(exit) remove(toStringz(name));

listener.listen(1);

pair[0] = new Socket(AddressFamily.UNIX, SocketType.STREAM);
scope(exit) listener.close();

pair[0].connect(address);
scope(exit) pair[0].close();

pair[1] = listener.accept();
scope(exit) pair[1].close();

pair[0].send(data);

auto buf = new ubyte[data.length];
pair[1].receive(buf);
assert(buf == data);
}
}


Expand Down

0 comments on commit c3b1ac1

Please sign in to comment.