there is only one style -- my style
This commit is contained in:
parent
73cc029fec
commit
87a2ced1ba
16 changed files with 232 additions and 213 deletions
|
|
@ -267,8 +267,8 @@ proc unregister*[T](s: Selector[T], ev: SelectEvent) =
|
|||
proc registerTimer*[T](s: Selector[T], timeout: int, oneshot: bool,
|
||||
data: T): int {.discardable.} =
|
||||
var
|
||||
new_ts: Itimerspec
|
||||
old_ts: Itimerspec
|
||||
newTs: Itimerspec
|
||||
oldTs: Itimerspec
|
||||
let fdi = timerfd_create(CLOCK_MONOTONIC, 0).int
|
||||
if fdi == -1:
|
||||
raiseIOSelectorsError(osLastError())
|
||||
|
|
@ -282,19 +282,19 @@ proc registerTimer*[T](s: Selector[T], timeout: int, oneshot: bool,
|
|||
epv.data.u64 = fdi.uint
|
||||
|
||||
if oneshot:
|
||||
new_ts.it_interval.tv_sec = posix.Time(0)
|
||||
new_ts.it_interval.tv_nsec = 0
|
||||
new_ts.it_value.tv_sec = posix.Time(timeout div 1_000)
|
||||
new_ts.it_value.tv_nsec = (timeout %% 1_000) * 1_000_000
|
||||
newTs.it_interval.tv_sec = posix.Time(0)
|
||||
newTs.it_interval.tv_nsec = 0
|
||||
newTs.it_value.tv_sec = posix.Time(timeout div 1_000)
|
||||
newTs.it_value.tv_nsec = (timeout %% 1_000) * 1_000_000
|
||||
incl(events, Event.Oneshot)
|
||||
epv.events = epv.events or EPOLLONESHOT
|
||||
else:
|
||||
new_ts.it_interval.tv_sec = posix.Time(timeout div 1000)
|
||||
new_ts.it_interval.tv_nsec = (timeout %% 1_000) * 1_000_000
|
||||
new_ts.it_value.tv_sec = new_ts.it_interval.tv_sec
|
||||
new_ts.it_value.tv_nsec = new_ts.it_interval.tv_nsec
|
||||
newTs.it_interval.tv_sec = posix.Time(timeout div 1000)
|
||||
newTs.it_interval.tv_nsec = (timeout %% 1_000) * 1_000_000
|
||||
newTs.it_value.tv_sec = newTs.it_interval.tv_sec
|
||||
newTs.it_value.tv_nsec = newTs.it_interval.tv_nsec
|
||||
|
||||
if timerfd_settime(fdi.cint, cint(0), new_ts, old_ts) != 0:
|
||||
if timerfd_settime(fdi.cint, cint(0), newTs, oldTs) != 0:
|
||||
raiseIOSelectorsError(osLastError())
|
||||
if epoll_ctl(s.epollFD, EPOLL_CTL_ADD, fdi.cint, addr epv) != 0:
|
||||
raiseIOSelectorsError(osLastError())
|
||||
|
|
|
|||
|
|
@ -253,8 +253,8 @@ proc getAddrInfo*(address: string, port: Port, domain: Domain = AF_INET,
|
|||
when not defined(freebsd) and not defined(openbsd) and not defined(netbsd) and not defined(android) and not defined(haiku):
|
||||
if domain == AF_INET6:
|
||||
hints.ai_flags = AI_V4MAPPED
|
||||
let socket_port = if sockType == SOCK_RAW: "" else: $port
|
||||
var gaiResult = getaddrinfo(address, socket_port, addr(hints), result)
|
||||
let socketPort = if sockType == SOCK_RAW: "" else: $port
|
||||
var gaiResult = getaddrinfo(address, socketPort, addr(hints), result)
|
||||
if gaiResult != 0'i32:
|
||||
when useWinVersion:
|
||||
raiseOSError(osLastError())
|
||||
|
|
@ -357,8 +357,8 @@ proc getHostByAddr*(ip: string): Hostent {.tags: [ReadIOEffect].} =
|
|||
result.addrList = @[]
|
||||
var i = 0
|
||||
while not isNil(s.h_addr_list[i]):
|
||||
var inaddr_ptr = cast[ptr InAddr](s.h_addr_list[i])
|
||||
result.addrList.add($inet_ntoa(inaddr_ptr[]))
|
||||
var inaddrPtr = cast[ptr InAddr](s.h_addr_list[i])
|
||||
result.addrList.add($inet_ntoa(inaddrPtr[]))
|
||||
inc(i)
|
||||
else:
|
||||
result.addrList = cstringArrayToSeq(s.h_addr_list)
|
||||
|
|
@ -386,8 +386,8 @@ proc getHostByName*(name: string): Hostent {.tags: [ReadIOEffect].} =
|
|||
result.addrList = @[]
|
||||
var i = 0
|
||||
while not isNil(s.h_addr_list[i]):
|
||||
var inaddr_ptr = cast[ptr InAddr](s.h_addr_list[i])
|
||||
result.addrList.add($inet_ntoa(inaddr_ptr[]))
|
||||
var inaddrPtr = cast[ptr InAddr](s.h_addr_list[i])
|
||||
result.addrList.add($inet_ntoa(inaddrPtr[]))
|
||||
inc(i)
|
||||
else:
|
||||
result.addrList = cstringArrayToSeq(s.h_addr_list)
|
||||
|
|
|
|||
|
|
@ -148,6 +148,9 @@ type
|
|||
Peek,
|
||||
SafeDisconn ## Ensures disconnection exceptions (ECONNRESET, EPIPE etc) are not thrown.
|
||||
|
||||
when defined(nimHasStyleChecks):
|
||||
{.push styleChecks: off.}
|
||||
|
||||
type
|
||||
IpAddressFamily* {.pure.} = enum ## Describes the type of an IP address
|
||||
IPv6, ## IPv6 address
|
||||
|
|
@ -161,6 +164,8 @@ type
|
|||
of IpAddressFamily.IPv4:
|
||||
address_v4*: array[0..3, uint8] ## Contains the IP address in bytes in
|
||||
## case of IPv4
|
||||
when defined(nimHasStyleChecks):
|
||||
{.pop.}
|
||||
|
||||
proc socketError*(socket: Socket, err: int = -1, async = false,
|
||||
lastError = (-1).OSErrorCode): void {.gcsafe.}
|
||||
|
|
|
|||
|
|
@ -71,14 +71,14 @@ when defined(windows):
|
|||
type
|
||||
SHORT = int16
|
||||
COORD = object
|
||||
X: SHORT
|
||||
Y: SHORT
|
||||
x: SHORT
|
||||
y: SHORT
|
||||
|
||||
SMALL_RECT = object
|
||||
Left: SHORT
|
||||
Top: SHORT
|
||||
Right: SHORT
|
||||
Bottom: SHORT
|
||||
left: SHORT
|
||||
top: SHORT
|
||||
right: SHORT
|
||||
bottom: SHORT
|
||||
|
||||
CONSOLE_SCREEN_BUFFER_INFO = object
|
||||
dwSize: COORD
|
||||
|
|
@ -114,14 +114,14 @@ when defined(windows):
|
|||
var csbi: CONSOLE_SCREEN_BUFFER_INFO
|
||||
for h in handles:
|
||||
if getConsoleScreenBufferInfo(h, addr csbi) != 0:
|
||||
return int(csbi.srWindow.Right - csbi.srWindow.Left + 1)
|
||||
return int(csbi.srWindow.right - csbi.srWindow.left + 1)
|
||||
return 0
|
||||
|
||||
proc terminalHeightIoctl*(handles: openArray[Handle]): int =
|
||||
var csbi: CONSOLE_SCREEN_BUFFER_INFO
|
||||
for h in handles:
|
||||
if getConsoleScreenBufferInfo(h, addr csbi) != 0:
|
||||
return int(csbi.srWindow.Bottom - csbi.srWindow.Top + 1)
|
||||
return int(csbi.srWindow.bottom - csbi.srWindow.top + 1)
|
||||
return 0
|
||||
|
||||
proc terminalWidth*(): int =
|
||||
|
|
@ -168,12 +168,12 @@ when defined(windows):
|
|||
var c: CONSOLE_SCREEN_BUFFER_INFO
|
||||
if getConsoleScreenBufferInfo(h, addr(c)) == 0:
|
||||
raiseOSError(osLastError())
|
||||
return (int(c.dwCursorPosition.X), int(c.dwCursorPosition.Y))
|
||||
return (int(c.dwCursorPosition.x), int(c.dwCursorPosition.y))
|
||||
|
||||
proc setCursorPos(h: Handle, x, y: int) =
|
||||
var c: COORD
|
||||
c.X = int16(x)
|
||||
c.Y = int16(y)
|
||||
c.x = int16(x)
|
||||
c.y = int16(y)
|
||||
if setConsoleCursorPosition(h, c) == 0:
|
||||
raiseOSError(osLastError())
|
||||
|
||||
|
|
@ -319,7 +319,7 @@ proc setCursorXPos*(f: File, x: int) =
|
|||
if getConsoleScreenBufferInfo(h, addr(scrbuf)) == 0:
|
||||
raiseOSError(osLastError())
|
||||
var origin = scrbuf.dwCursorPosition
|
||||
origin.X = int16(x)
|
||||
origin.x = int16(x)
|
||||
if setConsoleCursorPosition(h, origin) == 0:
|
||||
raiseOSError(osLastError())
|
||||
else:
|
||||
|
|
@ -336,7 +336,7 @@ when defined(windows):
|
|||
if getConsoleScreenBufferInfo(h, addr(scrbuf)) == 0:
|
||||
raiseOSError(osLastError())
|
||||
var origin = scrbuf.dwCursorPosition
|
||||
origin.Y = int16(y)
|
||||
origin.y = int16(y)
|
||||
if setConsoleCursorPosition(h, origin) == 0:
|
||||
raiseOSError(osLastError())
|
||||
else:
|
||||
|
|
@ -422,10 +422,10 @@ proc eraseLine*(f: File) =
|
|||
if getConsoleScreenBufferInfo(h, addr(scrbuf)) == 0:
|
||||
raiseOSError(osLastError())
|
||||
var origin = scrbuf.dwCursorPosition
|
||||
origin.X = 0'i16
|
||||
origin.x = 0'i16
|
||||
if setConsoleCursorPosition(h, origin) == 0:
|
||||
raiseOSError(osLastError())
|
||||
var wt: DWORD = scrbuf.dwSize.X - origin.X
|
||||
var wt: DWORD = scrbuf.dwSize.x - origin.x
|
||||
if fillConsoleOutputCharacter(h, ' ', wt,
|
||||
origin, addr(numwrote)) == 0:
|
||||
raiseOSError(osLastError())
|
||||
|
|
@ -446,7 +446,7 @@ proc eraseScreen*(f: File) =
|
|||
|
||||
if getConsoleScreenBufferInfo(h, addr(scrbuf)) == 0:
|
||||
raiseOSError(osLastError())
|
||||
let numChars = int32(scrbuf.dwSize.X)*int32(scrbuf.dwSize.Y)
|
||||
let numChars = int32(scrbuf.dwSize.x)*int32(scrbuf.dwSize.y)
|
||||
|
||||
if fillConsoleOutputCharacter(h, ' ', numChars,
|
||||
origin, addr(numwrote)) == 0:
|
||||
|
|
|
|||
|
|
@ -283,12 +283,20 @@ type
|
|||
dSat = "Saturday"
|
||||
dSun = "Sunday"
|
||||
|
||||
when defined(nimHasStyleChecks):
|
||||
{.push styleChecks: off.}
|
||||
|
||||
type
|
||||
DateTimeLocale* = object
|
||||
MMM*: array[mJan..mDec, string]
|
||||
MMMM*: array[mJan..mDec, string]
|
||||
ddd*: array[dMon..dSun, string]
|
||||
dddd*: array[dMon..dSun, string]
|
||||
|
||||
when defined(nimHasStyleChecks):
|
||||
{.pop.}
|
||||
|
||||
type
|
||||
MonthdayRange* = range[1..31]
|
||||
HourRange* = range[0..23]
|
||||
MinuteRange* = range[0..59]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue