Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update connections.nim #48

Merged
merged 7 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,27 @@ on:
- master

jobs:
default:
runs-on: ubuntu-latest
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
nim:
- '2.0.x'
- 'stable'
- devel
os:
- ubuntu-latest

name: '${{ matrix.nim }} (${{ matrix.os }})'
steps:
- uses: actions/checkout@v4
- uses: iffy/install-nim@v5
- name: Setup nim
uses: jiro4989/setup-nim-action@v2
with:
use-nightlies: true
nim-version: ${{ matrix.nim }}
repo-token: ${{ secrets.GITHUB_TOKEN }}

- run: nimble install -y
- run: nimble test
- run: nimble test --gc:arc
Expand Down
2 changes: 1 addition & 1 deletion zmq.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "1.5.2"
version = "1.5.3"
author = "Andreas Rumpf"
description = "ZeroMQ wrapper"
license = "MIT"
Expand Down
42 changes: 20 additions & 22 deletions zmq/connections.nim
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,29 @@ proc terminate*(ctx: ZContext) =
get/set socket options
Declare socket options first because it's used in =destroy hooks
]#
# Some option take cint, int64 or uint64
proc setsockopt_impl[T: SomeOrdinal](s: ZSocket, option: ZSockOptions, optval: T) =
var val: T = optval
if setsockopt(s, option, addr(val), sizeof(val)) != 0:
zmqError()

# Some option take cstring
proc setsockopt_impl(s: ZSocket, option: ZSockOptions, optval: string) =
var val: string = optval
if setsockopt(s, option, cstring(val), val.len) != 0:
zmqError()
# Some option take cint, int64 or uint64
Clonkk marked this conversation as resolved.
Show resolved Hide resolved
proc setsockopt_impl[T: string|SomeOrdinal](s: ZSocket, option: ZSockOptions, optval: T) =
when T is string:
var val: string = optval
if setsockopt(s, option, cstring(val), val.len) != 0:
zmqError()
elif T is SomeOrdinal:
var val: T = optval
if setsockopt(s, option, addr(val), sizeof(val)) != 0:
zmqError()

# some sockopt returns integer values
proc getsockopt_impl[T: SomeOrdinal](s: ZSocket, option: ZSockOptions, optval: var T) =
var optval_len: int = sizeof(optval)

if bindings.getsockopt(s, option, addr(optval), addr(optval_len)) != 0:
zmqError()

# Some sockopt returns a string
proc getsockopt_impl(s: ZSocket, option: ZSockOptions, optval: var string) =
var optval_len: int = optval.len

if bindings.getsockopt(s, option, cstring(optval), addr(optval_len)) != 0:
zmqError()
proc getsockopt_impl[T: SomeOrdinal|string](s: ZSocket, option: ZSockOptions, optval: var T) =
when T is string:
var optval_len: int = optval.len
if bindings.getsockopt(s, option, cstring(optval), addr(optval_len)) != 0:
zmqError()
elif T is SomeOrdinal:
var optval_len: int = sizeof(optval)
if bindings.getsockopt(s, option, addr(optval), addr(optval_len)) != 0:
zmqError()

#[
Public set/get sockopt function on ZSocket / ZConnection
Expand Down Expand Up @@ -323,7 +321,7 @@ proc close(c: var ZConnectionImpl, linger: int = 500) =
c.context.terminate()

proc close*(c: ZConnection, linger: int = 500) =
c[].close()
close(c[], linger)

# Send / Receive
# Send with ZSocket type
Expand Down