mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-30 18:02:05 +00:00
Merge branch 'bigbreak' of https://github.com/Araq/Nimrod into bigbreak
Conflicts: lib/pure/asynchttpserver.nim
This commit is contained in:
@@ -58,7 +58,7 @@ proc addHeaders(msg: var string, headers: PStringTable) =
|
||||
for k, v in headers:
|
||||
msg.add(k & ": " & v & "\c\L")
|
||||
|
||||
proc sendHeaders*(req: TRequest, headers: PStringTable): PFuture[void] =
|
||||
proc sendHeaders*(req: TRequest, headers: PStringTable): Future[void] =
|
||||
## Sends the specified headers to the requesting client.
|
||||
var msg = ""
|
||||
addHeaders(msg, headers)
|
||||
@@ -96,12 +96,12 @@ proc parseProtocol(protocol: string): tuple[orig: string, major, minor: int] =
|
||||
i.inc # Skip .
|
||||
i.inc protocol.parseInt(result.minor, i)
|
||||
|
||||
proc sendStatus(client: PAsyncSocket, status: string): PFuture[void] =
|
||||
proc sendStatus(client: PAsyncSocket, status: string): Future[void] =
|
||||
client.send("HTTP/1.1 " & status & "\c\L")
|
||||
|
||||
proc processClient(client: PAsyncSocket, address: string,
|
||||
callback: proc (request: TRequest):
|
||||
PFuture[void] {.closure, gcsafe.}) {.async.} =
|
||||
Future[void] {.closure, gcsafe.}) {.async.} =
|
||||
while true:
|
||||
# GET /path HTTP/1.1
|
||||
# Header: val
|
||||
@@ -188,7 +188,7 @@ proc processClient(client: PAsyncSocket, address: string,
|
||||
break
|
||||
|
||||
proc serve*(server: PAsyncHttpServer, port: Port,
|
||||
callback: proc (request: TRequest): PFuture[void] {.closure,gcsafe.},
|
||||
callback: proc (request: TRequest): Future[void] {.closure,gcsafe.},
|
||||
address = "") {.async.} =
|
||||
## Starts the process of listening for incoming HTTP connections on the
|
||||
## specified address and port.
|
||||
@@ -220,6 +220,6 @@ when isMainModule:
|
||||
"Content-type": "text/plain; charset=utf-8"}
|
||||
await req.respond(Http200, "Hello World", headers.newStringTable())
|
||||
|
||||
asyncCheck server.serve(TPort(5555), cb)
|
||||
asyncCheck server.serve(Port(5555), cb)
|
||||
runForever()
|
||||
main()
|
||||
|
||||
@@ -335,7 +335,7 @@ proc recvLine*(socket: PAsyncSocket,
|
||||
return
|
||||
add(result.string, c)
|
||||
|
||||
proc listen*(socket: Socket, backlog = SOMAXCONN) {.tags: [ReadIOEffect].} =
|
||||
proc listen*(socket: PAsyncSocket, backlog = SOMAXCONN) {.tags: [ReadIOEffect].} =
|
||||
## Marks ``socket`` as accepting connections.
|
||||
## ``Backlog`` specifies the maximum length of the
|
||||
## queue of pending connections.
|
||||
@@ -343,7 +343,7 @@ proc listen*(socket: Socket, backlog = SOMAXCONN) {.tags: [ReadIOEffect].} =
|
||||
## Raises an EOS error upon failure.
|
||||
if listen(socket.fd, backlog) < 0'i32: raiseOSError(osLastError())
|
||||
|
||||
proc bindAddr*(socket: Socket, port = Port(0), address = "") {.
|
||||
proc bindAddr*(socket: PAsyncSocket, port = Port(0), address = "") {.
|
||||
tags: [ReadIOEffect].} =
|
||||
## Binds ``address``:``port`` to the socket.
|
||||
##
|
||||
|
||||
Reference in New Issue
Block a user