Created
September 12, 2011 17:20
-
-
Save dnadlinger/1211819 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import std.datetime : AutoStart, Duration, StopWatch; | |
| import std.socket; | |
| import std.stdio; | |
| void main() { | |
| foreach (factory; [ | |
| cast(Socket delegate()){ return new TcpSocket(new InternetAddress("google.com", 80)); }, // Cast due to a DMD @@BUG@@. | |
| { auto pair = socketPair(); return pair[0]; } // Temporary due to a DMD @@BUG@@. | |
| ]) { | |
| foreach (msecs; [1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000]) { | |
| auto sock = factory(); | |
| sock.setOption(SocketOptionLevel.SOCKET, | |
| SocketOption.RCVTIMEO, dur!"msecs"(msecs)); | |
| auto sw = StopWatch(AutoStart.yes); | |
| ubyte[1] buf; | |
| sock.receive(buf); | |
| sw.stop(); | |
| Duration readBack = void; | |
| sock.getOption(SocketOptionLevel.SOCKET, SocketOption.RCVTIMEO, readBack); | |
| writefln("Set: %s ms (%s ms). Actual: %s ms.", msecs, | |
| readBack.total!"msecs", sw.peek().msecs); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment