Merge branch 'bigbreak' of https://github.com/Araq/Nimrod into bigbreak
This commit is contained in:
commit
32b582bb00
6 changed files with 19 additions and 17 deletions
|
|
@ -116,7 +116,7 @@ proc sendStatus(client: PAsyncSocket, status: string): Future[void] =
|
||||||
proc processClient(client: PAsyncSocket, address: string,
|
proc processClient(client: PAsyncSocket, address: string,
|
||||||
callback: proc (request: TRequest):
|
callback: proc (request: TRequest):
|
||||||
Future[void] {.closure, gcsafe.}) {.async.} =
|
Future[void] {.closure, gcsafe.}) {.async.} =
|
||||||
while true:
|
while not client.closed:
|
||||||
# GET /path HTTP/1.1
|
# GET /path HTTP/1.1
|
||||||
# Header: val
|
# Header: val
|
||||||
# \n
|
# \n
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,8 @@ type
|
||||||
# PAsyncSocket* {.borrow: `.`.} = distinct PSocket. But that doesn't work.
|
# PAsyncSocket* {.borrow: `.`.} = distinct PSocket. But that doesn't work.
|
||||||
AsyncSocketDesc = object
|
AsyncSocketDesc = object
|
||||||
fd*: SocketHandle
|
fd*: SocketHandle
|
||||||
case isBuffered*: bool # determines whether this socket is buffered.
|
closed*: bool ## determines whether this socket has been closed
|
||||||
|
case isBuffered*: bool ## determines whether this socket is buffered.
|
||||||
of true:
|
of true:
|
||||||
buffer*: array[0..BufferSize, char]
|
buffer*: array[0..BufferSize, char]
|
||||||
currPos*: int # current index in buffer
|
currPos*: int # current index in buffer
|
||||||
|
|
@ -400,6 +401,7 @@ proc close*(socket: PAsyncSocket) =
|
||||||
raiseSslError()
|
raiseSslError()
|
||||||
elif res != 1:
|
elif res != 1:
|
||||||
raiseSslError()
|
raiseSslError()
|
||||||
|
socket.closed = true # TODO: Add extra debugging checks for this.
|
||||||
|
|
||||||
when defined(ssl):
|
when defined(ssl):
|
||||||
proc wrapSocket*(ctx: SslContext, socket: AsyncSocket) =
|
proc wrapSocket*(ctx: SslContext, socket: AsyncSocket) =
|
||||||
|
|
|
||||||
|
|
@ -287,11 +287,11 @@ proc bindAddr*(socket: Socket, port = Port(0), address = "") {.
|
||||||
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(socket.fd, cast[ptr SockAddr](addr(name)),
|
if bindAddr(socket.fd, cast[ptr SockAddr](addr(name)),
|
||||||
sizeof(name).Socklen) < 0'i32:
|
sizeof(name).SockLen) < 0'i32:
|
||||||
raiseOSError(osLastError())
|
raiseOSError(osLastError())
|
||||||
else:
|
else:
|
||||||
var aiList = getAddrInfo(address, port, AF_INET)
|
var aiList = getAddrInfo(address, port, AF_INET)
|
||||||
if bindAddr(socket.fd, aiList.ai_addr, aiList.ai_addrlen.Socklen) < 0'i32:
|
if bindAddr(socket.fd, aiList.ai_addr, aiList.ai_addrlen.SockLen) < 0'i32:
|
||||||
dealloc(aiList)
|
dealloc(aiList)
|
||||||
raiseOSError(osLastError())
|
raiseOSError(osLastError())
|
||||||
dealloc(aiList)
|
dealloc(aiList)
|
||||||
|
|
@ -315,7 +315,7 @@ proc acceptAddr*(server: Socket, client: var Socket, address: var string,
|
||||||
## accept will be called again.
|
## accept will be called again.
|
||||||
assert(client != nil)
|
assert(client != nil)
|
||||||
var sockAddress: Sockaddr_in
|
var sockAddress: Sockaddr_in
|
||||||
var addrLen = sizeof(sockAddress).Socklen
|
var addrLen = sizeof(sockAddress).SockLen
|
||||||
var sock = accept(server.fd, cast[ptr SockAddr](addr(sockAddress)),
|
var sock = accept(server.fd, cast[ptr SockAddr](addr(sockAddress)),
|
||||||
addr(addrLen))
|
addr(addrLen))
|
||||||
|
|
||||||
|
|
@ -754,7 +754,7 @@ proc recvFrom*(socket: Socket, data: var string, length: int,
|
||||||
|
|
||||||
# TODO: Buffered sockets
|
# TODO: Buffered sockets
|
||||||
data.setLen(length)
|
data.setLen(length)
|
||||||
var sockAddress: SockAddrIn
|
var sockAddress: Sockaddr_in
|
||||||
var addrLen = sizeof(sockAddress).SockLen
|
var addrLen = sizeof(sockAddress).SockLen
|
||||||
result = recvfrom(socket.fd, cstring(data), length.cint, flags.cint,
|
result = recvfrom(socket.fd, cstring(data), length.cint, flags.cint,
|
||||||
cast[ptr SockAddr](addr(sockAddress)), addr(addrLen))
|
cast[ptr SockAddr](addr(sockAddress)), addr(addrLen))
|
||||||
|
|
|
||||||
|
|
@ -162,7 +162,7 @@ proc close*(socket: SocketHandle) =
|
||||||
# TODO: These values should not be discarded. An EOS should be raised.
|
# TODO: These values should not be discarded. An EOS should be raised.
|
||||||
# http://stackoverflow.com/questions/12463473/what-happens-if-you-call-close-on-a-bsd-socket-multiple-times
|
# http://stackoverflow.com/questions/12463473/what-happens-if-you-call-close-on-a-bsd-socket-multiple-times
|
||||||
|
|
||||||
proc bindAddr*(socket: SocketHandle, name: ptr SockAddr, namelen: Socklen): cint =
|
proc bindAddr*(socket: SocketHandle, name: ptr SockAddr, namelen: SockLen): cint =
|
||||||
result = bindSocket(socket, name, namelen)
|
result = bindSocket(socket, name, namelen)
|
||||||
|
|
||||||
proc listen*(socket: SocketHandle, backlog = SOMAXCONN): cint {.tags: [ReadIOEffect].} =
|
proc listen*(socket: SocketHandle, backlog = SOMAXCONN): cint {.tags: [ReadIOEffect].} =
|
||||||
|
|
@ -314,7 +314,7 @@ proc getSockName*(socket: SocketHandle): Port =
|
||||||
name.sin_family = posix.AF_INET
|
name.sin_family = posix.AF_INET
|
||||||
#name.sin_port = htons(cint16(port))
|
#name.sin_port = htons(cint16(port))
|
||||||
#name.sin_addr.s_addr = htonl(INADDR_ANY)
|
#name.sin_addr.s_addr = htonl(INADDR_ANY)
|
||||||
var namelen = sizeof(name).Socklen
|
var namelen = sizeof(name).SockLen
|
||||||
if getsockname(socket, cast[ptr SockAddr](addr(name)),
|
if getsockname(socket, cast[ptr SockAddr](addr(name)),
|
||||||
addr(namelen)) == -1'i32:
|
addr(namelen)) == -1'i32:
|
||||||
raiseOSError(osLastError())
|
raiseOSError(osLastError())
|
||||||
|
|
@ -324,7 +324,7 @@ proc getSockOptInt*(socket: SocketHandle, level, optname: int): int {.
|
||||||
tags: [ReadIOEffect].} =
|
tags: [ReadIOEffect].} =
|
||||||
## getsockopt for integer options.
|
## getsockopt for integer options.
|
||||||
var res: cint
|
var res: cint
|
||||||
var size = sizeof(res).Socklen
|
var size = sizeof(res).SockLen
|
||||||
if getsockopt(socket, cint(level), cint(optname),
|
if getsockopt(socket, cint(level), cint(optname),
|
||||||
addr(res), addr(size)) < 0'i32:
|
addr(res), addr(size)) < 0'i32:
|
||||||
raiseOSError(osLastError())
|
raiseOSError(osLastError())
|
||||||
|
|
@ -335,7 +335,7 @@ proc setSockOptInt*(socket: SocketHandle, level, optname, optval: int) {.
|
||||||
## setsockopt for integer options.
|
## setsockopt for integer options.
|
||||||
var value = cint(optval)
|
var value = cint(optval)
|
||||||
if setsockopt(socket, cint(level), cint(optname), addr(value),
|
if setsockopt(socket, cint(level), cint(optname), addr(value),
|
||||||
sizeof(value).Socklen) < 0'i32:
|
sizeof(value).SockLen) < 0'i32:
|
||||||
raiseOSError(osLastError())
|
raiseOSError(osLastError())
|
||||||
|
|
||||||
proc setBlocking*(s: SocketHandle, blocking: bool) =
|
proc setBlocking*(s: SocketHandle, blocking: bool) =
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,9 @@ To build from source you will need:
|
||||||
If you are on a fairly modern *nix system, the following steps should work:
|
If you are on a fairly modern *nix system, the following steps should work:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ git clone git://github.com/Araq/Nim.git
|
$ git clone git://github.com/Araq/Nimrod.git
|
||||||
$ cd Nim
|
$ cd Nimrod
|
||||||
$ git clone --depth 1 git://github.com/nim-code/csources
|
$ git clone --depth 1 git://github.com/nimrod-code/csources
|
||||||
$ cd csources && sh build.sh
|
$ cd csources && sh build.sh
|
||||||
$ cd ..
|
$ cd ..
|
||||||
$ bin/nim c koch
|
$ bin/nim c koch
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,10 @@ To build from source you will need:
|
||||||
If you are on a fairly modern *nix system, the following steps should work:
|
If you are on a fairly modern *nix system, the following steps should work:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ git clone git://github.com/Araq/Nim.git
|
$ git clone git://github.com/Araq/Nimrod.git
|
||||||
$ cd Nim
|
$ cd Nimrod
|
||||||
$ git clone --depth 1 git://github.com/nim-code/csources
|
$ git clone --depth 1 git://github.com/nimrod-code/csources
|
||||||
$ cd csources && ./build.sh
|
$ cd csources && sh build.sh
|
||||||
$ cd ..
|
$ cd ..
|
||||||
$ bin/nim c koch
|
$ bin/nim c koch
|
||||||
$ ./koch boot -d:release
|
$ ./koch boot -d:release
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue