TPort is now uint16 and other small sockets fixes.
This commit is contained in:
parent
4013fc56a3
commit
0663c883e5
1 changed files with 19 additions and 12 deletions
|
|
@ -31,6 +31,7 @@ when hostos == "solaris":
|
||||||
|
|
||||||
import os, parseutils
|
import os, parseutils
|
||||||
from times import epochTime
|
from times import epochTime
|
||||||
|
import unsigned
|
||||||
|
|
||||||
when defined(ssl):
|
when defined(ssl):
|
||||||
import openssl
|
import openssl
|
||||||
|
|
@ -82,7 +83,7 @@ type
|
||||||
|
|
||||||
TSocket* = ref TSocketImpl
|
TSocket* = ref TSocketImpl
|
||||||
|
|
||||||
TPort* = distinct int16 ## port type
|
TPort* = distinct uint16 ## port type
|
||||||
|
|
||||||
TDomain* = enum ## domain, which specifies the protocol family of the
|
TDomain* = enum ## domain, which specifies the protocol family of the
|
||||||
## created socket. Other domains than those that are listed
|
## created socket. Other domains than those that are listed
|
||||||
|
|
@ -540,7 +541,7 @@ proc acceptAddr*(server: TSocket, client: var TSocket, address: var string) {.
|
||||||
SSLError("Unknown error")
|
SSLError("Unknown error")
|
||||||
|
|
||||||
proc setBlocking*(s: TSocket, blocking: bool) {.tags: [].}
|
proc setBlocking*(s: TSocket, blocking: bool) {.tags: [].}
|
||||||
## sets blocking mode on socket
|
## Sets blocking mode on socket
|
||||||
|
|
||||||
when defined(ssl):
|
when defined(ssl):
|
||||||
proc acceptAddrSSL*(server: TSocket, client: var TSocket,
|
proc acceptAddrSSL*(server: TSocket, client: var TSocket,
|
||||||
|
|
@ -634,24 +635,32 @@ proc close*(socket: TSocket) =
|
||||||
discard SSLShutdown(socket.sslHandle)
|
discard SSLShutdown(socket.sslHandle)
|
||||||
|
|
||||||
proc getServByName*(name, proto: string): TServent {.tags: [FReadIO].} =
|
proc getServByName*(name, proto: string): TServent {.tags: [FReadIO].} =
|
||||||
## well-known getservbyname proc.
|
## Searches the database from the beginning and finds the first entry for
|
||||||
|
## which the service name specified by ``name`` matches the s_name member
|
||||||
|
## and the protocol name specified by ``proto`` matches the s_proto member.
|
||||||
|
##
|
||||||
|
## On posix this will search through the ``/etc/services`` file.
|
||||||
when defined(Windows):
|
when defined(Windows):
|
||||||
var s = winlean.getservbyname(name, proto)
|
var s = winlean.getservbyname(name, proto)
|
||||||
else:
|
else:
|
||||||
var s = posix.getservbyname(name, proto)
|
var s = posix.getservbyname(name, proto)
|
||||||
if s == nil: OSError(OSLastError())
|
if s == nil: raise newException(EOS, "Service not found.")
|
||||||
result.name = $s.s_name
|
result.name = $s.s_name
|
||||||
result.aliases = cstringArrayToSeq(s.s_aliases)
|
result.aliases = cstringArrayToSeq(s.s_aliases)
|
||||||
result.port = TPort(s.s_port)
|
result.port = TPort(s.s_port)
|
||||||
result.proto = $s.s_proto
|
result.proto = $s.s_proto
|
||||||
|
|
||||||
proc getServByPort*(port: TPort, proto: string): TServent {.tags: [FReadIO].} =
|
proc getServByPort*(port: TPort, proto: string): TServent {.tags: [FReadIO].} =
|
||||||
## well-known getservbyport proc.
|
## Searches the database from the beginning and finds the first entry for
|
||||||
|
## which the port specified by ``port`` matches the s_port member and the
|
||||||
|
## protocol name specified by ``proto`` matches the s_proto member.
|
||||||
|
##
|
||||||
|
## On posix this will search through the ``/etc/services`` file.
|
||||||
when defined(Windows):
|
when defined(Windows):
|
||||||
var s = winlean.getservbyport(ze(int16(port)).cint, proto)
|
var s = winlean.getservbyport(ze(int16(port)).cint, proto)
|
||||||
else:
|
else:
|
||||||
var s = posix.getservbyport(ze(int16(port)).cint, proto)
|
var s = posix.getservbyport(ze(int16(port)).cint, proto)
|
||||||
if s == nil: OSError(OSLastError())
|
if s == nil: raise newException(EOS, "Service not found.")
|
||||||
result.name = $s.s_name
|
result.name = $s.s_name
|
||||||
result.aliases = cstringArrayToSeq(s.s_aliases)
|
result.aliases = cstringArrayToSeq(s.s_aliases)
|
||||||
result.port = TPort(s.s_port)
|
result.port = TPort(s.s_port)
|
||||||
|
|
@ -687,7 +696,7 @@ proc getHostByAddr*(ip: string): THostEnt {.tags: [FReadIO].} =
|
||||||
result.length = int(s.h_length)
|
result.length = int(s.h_length)
|
||||||
|
|
||||||
proc getHostByName*(name: string): THostEnt {.tags: [FReadIO].} =
|
proc getHostByName*(name: string): THostEnt {.tags: [FReadIO].} =
|
||||||
## well-known gethostbyname proc.
|
## This function will lookup the IP address of a hostname.
|
||||||
when defined(Windows):
|
when defined(Windows):
|
||||||
var s = winlean.gethostbyname(name)
|
var s = winlean.gethostbyname(name)
|
||||||
else:
|
else:
|
||||||
|
|
@ -877,11 +886,6 @@ proc timeValFromMilliseconds(timeout = 500): TTimeVal =
|
||||||
var seconds = timeout div 1000
|
var seconds = timeout div 1000
|
||||||
result.tv_sec = seconds.int32
|
result.tv_sec = seconds.int32
|
||||||
result.tv_usec = ((timeout - seconds * 1000) * 1000).int32
|
result.tv_usec = ((timeout - seconds * 1000) * 1000).int32
|
||||||
#proc recvfrom*(s: TWinSocket, buf: cstring, len, flags: cint,
|
|
||||||
# fromm: ptr TSockAddr, fromlen: ptr cint): cint
|
|
||||||
|
|
||||||
#proc sendto*(s: TWinSocket, buf: cstring, len, flags: cint,
|
|
||||||
# to: ptr TSockAddr, tolen: cint): cint
|
|
||||||
|
|
||||||
proc createFdSet(fd: var TFdSet, s: seq[TSocket], m: var int) =
|
proc createFdSet(fd: var TFdSet, s: seq[TSocket], m: var int) =
|
||||||
FD_ZERO(fd)
|
FD_ZERO(fd)
|
||||||
|
|
@ -1670,6 +1674,9 @@ proc isSSL*(socket: TSocket): bool = return socket.isSSL
|
||||||
proc getFD*(socket: TSocket): TSocketHandle = return socket.fd
|
proc getFD*(socket: TSocket): TSocketHandle = return socket.fd
|
||||||
## Returns the socket's file descriptor
|
## Returns the socket's file descriptor
|
||||||
|
|
||||||
|
proc isBlocking*(socket: TSocket): bool = not socket.nonblocking
|
||||||
|
## Determines whether ``socket`` is blocking.
|
||||||
|
|
||||||
when defined(Windows):
|
when defined(Windows):
|
||||||
var wsa: TWSADATA
|
var wsa: TWSADATA
|
||||||
if WSAStartup(0x0101'i16, addr wsa) != 0: OSError(OSLastError())
|
if WSAStartup(0x0101'i16, addr wsa) != 0: OSError(OSLastError())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue