Fixes async tests.

This commit is contained in:
Dominik Picheta 2014-09-09 01:17:07 +01:00
commit 56f11e2c95
3 changed files with 10 additions and 10 deletions

View file

@ -47,18 +47,18 @@ proc readMessages(client: TAsyncFD) {.async.} =
proc createServer(port: TPort) {.async.} = proc createServer(port: TPort) {.async.} =
var server = newAsyncRawSocket() var server = newAsyncRawSocket()
block: block:
var name: TSockaddr_in var name: Sockaddr_in
when defined(windows): when defined(windows):
name.sin_family = toInt(AF_INET).int16 name.sin_family = toInt(AF_INET).int16
else: else:
name.sin_family = toInt(AF_INET) name.sin_family = toInt(AF_INET)
name.sin_port = htons(int16(port)) name.sin_port = htons(int16(port))
name.sin_addr.s_addr = htonl(INADDR_ANY) name.sin_addr.s_addr = htonl(INADDR_ANY)
if bindAddr(server.TSocketHandle, cast[ptr TSockAddr](addr(name)), if bindAddr(server.SocketHandle, cast[ptr SockAddr](addr(name)),
sizeof(name).TSocklen) < 0'i32: sizeof(name).Socklen) < 0'i32:
osError(osLastError()) raiseOSError(osLastError())
discard server.TSocketHandle.listen() discard server.SocketHandle.listen()
while true: while true:
var client = await accept(server) var client = await accept(server)
asyncCheck readMessages(client) asyncCheck readMessages(client)

View file

@ -1,15 +1,15 @@
discard """ discard """
file: "tasyncexceptions.nim" file: "tasyncexceptions.nim"
exitcode: 1 exitcode: 1
outputsub: "Error: unhandled exception: foobar [E_Base]" outputsub: "Error: unhandled exception: foobar [Exception]"
""" """
import asyncdispatch import asyncdispatch
proc accept(): PFuture[int] {.async.} = proc accept(): Future[int] {.async.} =
await sleepAsync(100) await sleepAsync(100)
result = 4 result = 4
proc recvLine(fd: int): PFuture[string] {.async.} = proc recvLine(fd: int): Future[string] {.async.} =
await sleepAsync(100) await sleepAsync(100)
return "get" return "get"

View file

@ -1,8 +1,8 @@
import asyncdispatch, asyncnet import asyncdispatch, asyncnet
proc main {.async.} = proc main {.async.} =
proc f: PFuture[seq[int]] {.async.} = proc f: Future[seq[int]] {.async.} =
await newAsyncSocket().connect("www.google.com", TPort(80)) await newAsyncSocket().connect("www.google.com", Port(80))
let x = await f() let x = await f()
asyncCheck main() asyncCheck main()