Merge branch 'master' of git@github.com:Araq/Nimrod
This commit is contained in:
commit
c9aac521a0
4 changed files with 53 additions and 16 deletions
|
|
@ -606,6 +606,35 @@ proc `[]=`*(obj: PJsonNode, key: String, val: PJsonNode) =
|
||||||
return
|
return
|
||||||
obj.fields.add((key, val))
|
obj.fields.add((key, val))
|
||||||
|
|
||||||
|
proc delete*(obj: PJsonNode, key: string) =
|
||||||
|
assert(obj.kind == JObject)
|
||||||
|
for i in 0..obj.fields.len-1:
|
||||||
|
if obj.fields[i].key == key:
|
||||||
|
obj.fields.delete(i)
|
||||||
|
return
|
||||||
|
raise newException(EInvalidIndex, "key not in object")
|
||||||
|
|
||||||
|
proc copy*(p: PJsonNode): PJsonNode =
|
||||||
|
case p.kind
|
||||||
|
of JString:
|
||||||
|
result = newJString(p.str)
|
||||||
|
of JInt:
|
||||||
|
result = newJInt(p.num)
|
||||||
|
of JFloat:
|
||||||
|
result = newJFloat(p.fnum)
|
||||||
|
of JBool:
|
||||||
|
result = newJBool(p.bval)
|
||||||
|
of JNull:
|
||||||
|
result = newJNull()
|
||||||
|
of JObject:
|
||||||
|
result = newJObject()
|
||||||
|
for key, field in items(p.fields):
|
||||||
|
result.fields.add((key, copy(field)))
|
||||||
|
of JArray:
|
||||||
|
result = newJArray()
|
||||||
|
for i in items(p.elems):
|
||||||
|
result.elems.add(copy(i))
|
||||||
|
|
||||||
# ------------- pretty printing ----------------------------------------------
|
# ------------- pretty printing ----------------------------------------------
|
||||||
|
|
||||||
proc indent(s: var string, i: int) =
|
proc indent(s: var string, i: int) =
|
||||||
|
|
|
||||||
|
|
@ -338,15 +338,15 @@ proc hMSet*(r: TRedis, key: string,
|
||||||
r.sendCommand("HMSET", args)
|
r.sendCommand("HMSET", args)
|
||||||
raiseNoOK(r.parseStatus())
|
raiseNoOK(r.parseStatus())
|
||||||
|
|
||||||
proc hSet*(r: TRedis, key, field, value: string) =
|
proc hSet*(r: TRedis, key, field, value: string): TRedisInteger =
|
||||||
## Set the string value of a hash field
|
## Set the string value of a hash field
|
||||||
r.sendCommand("HSET", key, field, value)
|
r.sendCommand("HSET", key, field, value)
|
||||||
raiseNoOK(r.parseStatus())
|
return r.parseInteger()
|
||||||
|
|
||||||
proc hSetNX*(r: TRedis, key, field, value: string) =
|
proc hSetNX*(r: TRedis, key, field, value: string): TRedisInteger =
|
||||||
## Set the value of a hash field, only if the field does **not** exist
|
## Set the value of a hash field, only if the field does **not** exist
|
||||||
r.sendCommand("HSETNX", key, field, value)
|
r.sendCommand("HSETNX", key, field, value)
|
||||||
raiseNoOK(r.parseStatus())
|
return r.parseInteger()
|
||||||
|
|
||||||
proc hVals*(r: TRedis, key: string): TRedisList =
|
proc hVals*(r: TRedis, key: string): TRedisList =
|
||||||
## Get all the values in a hash
|
## Get all the values in a hash
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ proc recvBuffer(s: var TScgiState, L: int) =
|
||||||
scgiError("could not read all data")
|
scgiError("could not read all data")
|
||||||
setLen(s.input, L)
|
setLen(s.input, L)
|
||||||
|
|
||||||
proc open*(s: var TScgiState, port = TPort(4000)) =
|
proc open*(s: var TScgiState, port = TPort(4000), address = "127.0.0.1") =
|
||||||
## opens a connection.
|
## opens a connection.
|
||||||
s.bufLen = 4000
|
s.bufLen = 4000
|
||||||
s.input = newString(s.buflen) # will be reused
|
s.input = newString(s.buflen) # will be reused
|
||||||
|
|
@ -81,7 +81,7 @@ proc open*(s: var TScgiState, port = TPort(4000)) =
|
||||||
s.server = socket()
|
s.server = socket()
|
||||||
if s.server == InvalidSocket: scgiError("could not open socket")
|
if s.server == InvalidSocket: scgiError("could not open socket")
|
||||||
#s.server.connect(connectionName, port)
|
#s.server.connect(connectionName, port)
|
||||||
bindAddr(s.server, port)
|
bindAddr(s.server, port, address)
|
||||||
listen(s.server)
|
listen(s.server)
|
||||||
|
|
||||||
proc close*(s: var TScgiState) =
|
proc close*(s: var TScgiState) =
|
||||||
|
|
|
||||||
|
|
@ -179,19 +179,27 @@ proc bindAddr*(socket: TSocket, port = TPort(0), address = "") =
|
||||||
## binds an address/port number to a socket.
|
## binds an address/port number to a socket.
|
||||||
## Use address string in dotted decimal form like "a.b.c.d"
|
## Use address string in dotted decimal form like "a.b.c.d"
|
||||||
## or leave "" for any address.
|
## or leave "" for any address.
|
||||||
var name: Tsockaddr_in
|
|
||||||
when defined(Windows):
|
|
||||||
name.sin_family = int16(ord(AF_INET))
|
|
||||||
else:
|
|
||||||
name.sin_family = posix.AF_INET
|
|
||||||
name.sin_port = sockets.htons(int16(port))
|
|
||||||
if address == "":
|
if address == "":
|
||||||
|
var name: Tsockaddr_in
|
||||||
|
when defined(Windows):
|
||||||
|
name.sin_family = int16(ord(AF_INET))
|
||||||
|
else:
|
||||||
|
name.sin_family = posix.AF_INET
|
||||||
|
name.sin_port = sockets.htons(int16(port))
|
||||||
name.sin_addr.s_addr = sockets.htonl(INADDR_ANY)
|
name.sin_addr.s_addr = sockets.htonl(INADDR_ANY)
|
||||||
|
if bindSocket(cint(socket), cast[ptr TSockAddr](addr(name)),
|
||||||
|
sizeof(name)) < 0'i32:
|
||||||
|
OSError()
|
||||||
else:
|
else:
|
||||||
name.sin_addr.s_addr = parseIp4(address)
|
var hints: TAddrInfo
|
||||||
if bindSocket(cint(socket), cast[ptr TSockAddr](addr(name)),
|
var aiList: ptr TAddrInfo = nil
|
||||||
sizeof(name)) < 0'i32:
|
hints.ai_family = toInt(AF_INET)
|
||||||
OSError()
|
hints.ai_socktype = toInt(SOCK_STREAM)
|
||||||
|
hints.ai_protocol = toInt(IPPROTO_TCP)
|
||||||
|
if getAddrInfo(address, $port, addr(hints), aiList) != 0'i32: OSError()
|
||||||
|
if bindSocket(cint(socket), aiList.ai_addr, aiList.ai_addrLen) < 0'i32:
|
||||||
|
OSError()
|
||||||
|
|
||||||
when false:
|
when false:
|
||||||
proc bindAddr*(socket: TSocket, port = TPort(0)) =
|
proc bindAddr*(socket: TSocket, port = TPort(0)) =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue