From d342de9e03902b93f1cff552e772f98caa0ee726 Mon Sep 17 00:00:00 2001 From: Determinant Date: Sat, 8 Jun 2019 19:36:06 -0400 Subject: WIP: ... --- event.go | 28 ++++++++++++++++++++++++++++ netaddr.go | 2 ++ salticidae | 2 +- stream.go | 8 ++++---- test_msgnet/main.go | 4 +++- 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/event.go b/event.go index 93b9255..e4ed463 100644 --- a/event.go +++ b/event.go @@ -11,6 +11,34 @@ func (self EventContext) Free() { C.eventcontext_free(self) } func (self EventContext) Dispatch() { C.eventcontext_dispatch(self) } func (self EventContext) Stop() { C.eventcontext_stop(self) } +type ThreadCall = *C.struct_threadcall_t +type ThreadCallCallback = C.threadcall_callback_t + +func NewThreadCall(ec EventContext) ThreadCall { return C.threadcall_new(ec) } + +func (self ThreadCall) Free() { C.threadcall_free(self) } + +func (self ThreadCall) AsyncCall(callback ThreadCallCallback, userdata rawptr_t) { + C.threadcall_async_call(self, callback, userdata) +} + +func (self ThreadCall) GetEC() EventContext { return C.threadcall_get_ec(self) } + +type TimerEvent = *C.timerev_t +type TimerEventCallback = C.timerev_callback_t + +func NewTimerEvent(ec EventContext, cb TimerEventCallback) TimerEvent { + return C.timerev_new(ec, cb) +} + +func (self TimerEvent) Free() { C.timerev_free(self) } +func (self TimerEvent) SetCallback(callback TimerEventCallback) { + C.timerev_set_callback(self, callback) +} + +func (self TimerEvent) Add(t_sec float64) { C.timerev_add(self, C.double(t_sec)) } +func (self TimerEvent) Clear() { C.timerev_clear(self) } + type SigEvent = *C.sigev_t type SigEventCallback = C.sigev_callback_t var SIGTERM = C.SIGTERM diff --git a/netaddr.go b/netaddr.go index 37ead1e..0a8af8b 100644 --- a/netaddr.go +++ b/netaddr.go @@ -14,3 +14,5 @@ func NewAddrFromIPPortString(addr string) (res NetAddr) { } func (self NetAddr) Free() { C.netaddr_free(self) } + +func (self NetAddr) IsEq(other NetAddr) bool { return bool(C.netaddr_is_eq(self, other)) } diff --git a/salticidae b/salticidae index 1f5bffd..66c711c 160000 --- a/salticidae +++ b/salticidae @@ -1 +1 @@ -Subproject commit 1f5bffd006ef432a2fa12fe5baf03c7160c42f73 +Subproject commit 66c711cf653b082ae07e1119417dcb3461039c80 diff --git a/stream.go b/stream.go index 2727565..1e7860f 100644 --- a/stream.go +++ b/stream.go @@ -8,6 +8,10 @@ type ByteArray = *C.struct_bytearray_t func NewByteArray() ByteArray { return C.bytearray_new() } func (self ByteArray) Free() { C.bytearray_free(self) } +func NewByteArrayMovedFromDataStream(src DataStream) ByteArray { + return C.bytearray_new_moved_from_datastream(src) +} + type DataStream = *C.struct_datastream_t func NewDataStream() DataStream { return C.datastream_new() } @@ -82,7 +86,3 @@ func (self UInt256) Unserialize(s DataStream) { C.uint256_unserialize(self, s) } func (self DataStream) GetHash() UInt256 { return C.datastream_get_hash(self) } - -func (_moved_self DataStream) ToByteArray() ByteArray { - return C.datastream_to_bytearray(_moved_self) -} diff --git a/test_msgnet/main.go b/test_msgnet/main.go index f1d82dc..4158376 100644 --- a/test_msgnet/main.go +++ b/test_msgnet/main.go @@ -37,7 +37,9 @@ func msgHelloSerialize(name string, text string) salticidae.Msg { serialized.PutData(t) serialized.PutData([]byte(name)) serialized.PutData([]byte(text)) - return salticidae.NewMsg(MSG_OPCODE_HELLO, serialized.ToByteArray()) + return salticidae.NewMsg( + MSG_OPCODE_HELLO, + salticidae.NewByteArrayFromDataStreamByMove(serialized)) } func msgHelloUnserialize(msg salticidae.Msg) MsgHello { -- cgit v1.2.3-70-g09d2