mirror of
https://github.com/sbrow/zomq.git
synced 2026-08-26 10:53:32 -04:00
feat: Removed allocations from bind and connect.
This commit is contained in:
@@ -125,14 +125,12 @@ close :: proc(s: Socket) -> Error {
|
|||||||
return _close(s) == 0 ? nil : last_error()
|
return _close(s) == 0 ? nil : last_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
bind :: proc(s: Socket, addr: string, allocator := context.temp_allocator) -> Error {
|
bind :: proc(s: Socket, addr: cstring) -> Error {
|
||||||
c := strings.clone_to_cstring(addr, allocator)
|
return _bind(s, addr) == 0 ? nil : last_error()
|
||||||
return _bind(s, c) == 0 ? nil : last_error()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
connect :: proc(s: Socket, addr: string, allocator := context.temp_allocator) -> Error {
|
connect :: proc(s: Socket, addr: cstring) -> Error {
|
||||||
c := strings.clone_to_cstring(addr, allocator)
|
return _connect(s, addr) == 0 ? nil : last_error()
|
||||||
return _connect(s, c) == 0 ? nil : last_error()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
send :: proc {
|
send :: proc {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
package zmq
|
package zmq
|
||||||
|
|
||||||
|
import "base:runtime"
|
||||||
import "core:testing"
|
import "core:testing"
|
||||||
|
|
||||||
@(test)
|
@(test)
|
||||||
@@ -13,6 +14,38 @@ test_version :: proc(t: ^testing.T) {
|
|||||||
testing.expect_value(t, pa, 5)
|
testing.expect_value(t, pa, 5)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
test_connect_does_not_allocate_with_string_literals :: proc(t: ^testing.T) {
|
||||||
|
context.temp_allocator = runtime.panic_allocator()
|
||||||
|
|
||||||
|
ctx := ctx_new()
|
||||||
|
defer ctx_term(ctx)
|
||||||
|
|
||||||
|
srv, serr := socket(ctx, .REP)
|
||||||
|
testing.expect_value(t, serr, nil)
|
||||||
|
if serr != nil {
|
||||||
|
testing.fail_now(t, "Can't create server socket")
|
||||||
|
}
|
||||||
|
defer close(srv)
|
||||||
|
|
||||||
|
if err := bind(srv, "inproc://echo"); err != nil {
|
||||||
|
testing.expect_value(t, err, nil)
|
||||||
|
testing.fail_now(t, "Can't bind server socket")
|
||||||
|
}
|
||||||
|
|
||||||
|
cli, cerr := socket(ctx, .REQ)
|
||||||
|
testing.expect_value(t, cerr, nil)
|
||||||
|
if cerr != nil {
|
||||||
|
testing.fail_now(t, "Can't create client socket")
|
||||||
|
}
|
||||||
|
defer close(cli)
|
||||||
|
err := connect(cli, "inproc://echo")
|
||||||
|
testing.expect_value(t, err, nil)
|
||||||
|
if err != nil {
|
||||||
|
testing.fail_now(t, "Can't connect client to server")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@(test)
|
@(test)
|
||||||
test_simple_const_echo :: proc(t: ^testing.T) {
|
test_simple_const_echo :: proc(t: ^testing.T) {
|
||||||
ctx := ctx_new()
|
ctx := ctx_new()
|
||||||
|
|||||||
Reference in New Issue
Block a user