Adds socket creation for arbitrary domain, type and protocol.

This commit is contained in:
Dominik Picheta 2014-09-18 17:01:44 +01:00
commit 867dfbfbfa
4 changed files with 31 additions and 0 deletions

View file

@ -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.