summary refs log tree commit diff stats
path: root/lib/pure/net.nim
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@googlemail.com>2014-09-18 17:01:44 +0100
committerDominik Picheta <dominikpicheta@googlemail.com>2014-09-18 17:03:23 +0100
commit867dfbfbfa68c61a2b65d46af7c22aa47857fa21 (patch)
tree76daec4dd69b31783e73ebf5d9cd7ca17cff15e5 /lib/pure/net.nim
parent47d755b4188c6988c3dc16ff707912239d90d319 (diff)
downloadNim-867dfbfbfa68c61a2b65d46af7c22aa47857fa21.tar.gz
Adds socket creation for arbitrary domain, type and protocol.
Diffstat (limited to 'lib/pure/net.nim')
-rw-r--r--lib/pure/net.nim9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/pure/net.nim b/lib/pure/net.nim
index 886ed792f..60298ec88 100644
--- a/lib/pure/net.nim
+++ b/lib/pure/net.nim
@@ -108,6 +108,15 @@ proc createSocket(fd: SocketHandle, isBuff: bool): Socket =
   if isBuff:
     result.currPos = 0
 
+proc newSocket*(domain, typ, protocol: cint, buffered = true): Socket =
+  ## Creates a new socket.
+  ##
+  ## If an error occurs EOS will be raised.
+  let fd = newRawSocket(domain, typ, protocol)
+  if fd == osInvalidSocket:
+    raiseOSError(osLastError())
+  result = createSocket(fd, buffered)
+
 proc newSocket*(domain: Domain = AF_INET, typ: SockType = SOCK_STREAM,
              protocol: Protocol = IPPROTO_TCP, buffered = true): Socket =
   ## Creates a new socket.