aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile9
-rw-r--r--network.go5
m---------salticidae0
-rw-r--r--test_msgnet/main.go10
-rw-r--r--test_p2p_stress/main.go10
5 files changed, 31 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index f82603c..a7a5d47 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,10 @@
-.PHONY: all clean
+.PHONY: all clean run_make
all: build/test_msgnet build/test_p2p_stress
+run_make:
+ make -C salticidae/
+
salticidae/libsalticidae.so:
cd salticidae/; cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED=ON -DSALTICIDAE_DEBUG_LOG=OFF -DSALTICIDAE_CBINDINGS=ON -DBUILD_TEST=OFF ./
make -C salticidae/
@@ -9,9 +12,9 @@ salticidae/libsalticidae.so:
build:
mkdir -p build
-build/test_msgnet: salticidae/libsalticidae.so test_msgnet/main.go
+build/test_msgnet: salticidae/libsalticidae.so test_msgnet/main.go run_make
go build -o $@ github.com/Determinant/salticidae-go/test_msgnet
-build/test_p2p_stress: salticidae/libsalticidae.so test_p2p_stress/main.go
+build/test_p2p_stress: salticidae/libsalticidae.so test_p2p_stress/main.go run_make
go build -o $@ github.com/Determinant/salticidae-go/test_p2p_stress
clean:
diff --git a/network.go b/network.go
index 5f42fb0..d4d85cd 100644
--- a/network.go
+++ b/network.go
@@ -75,6 +75,7 @@ func (self MsgNetworkConn) Free() { C.msgnetwork_conn_free(self) }
type MsgNetworkMsgCallback = C.msgnetwork_msg_callback_t
type MsgNetworkConnCallback = C.msgnetwork_conn_callback_t
+type MsgNetworkErrorCallback = C.msgnetwork_error_callback_t
func (self MsgNetwork) RegHandler(opcode Opcode, callback MsgNetworkMsgCallback, userdata rawptr_t) {
C.msgnetwork_reg_handler(self, C._opcode_t(opcode), callback, userdata)
@@ -84,6 +85,10 @@ func (self MsgNetwork) RegConnHandler(callback MsgNetworkConnCallback, userdata
C.msgnetwork_reg_conn_handler(self, callback, userdata)
}
+func (self MsgNetwork) RegErrorHandler(callback MsgNetworkErrorCallback, userdata rawptr_t) {
+ C.msgnetwork_reg_error_handler(self, callback, userdata)
+}
+
type PeerNetwork = *C.struct_peernetwork_t
type PeerNetworkConn = *C.struct_peernetwork_conn_t
diff --git a/salticidae b/salticidae
-Subproject deb478812b259cdf586ab5105284ae227fe4268
+Subproject d66b85289a1552e02e4c2c7cf62aa11ed240d5e
diff --git a/test_msgnet/main.go b/test_msgnet/main.go
index ee262b7..4c885d3 100644
--- a/test_msgnet/main.go
+++ b/test_msgnet/main.go
@@ -6,6 +6,7 @@ package main
// void onReceiveHello(msg_t *, msgnetwork_conn_t *, void *);
// void onReceiveAck(msg_t *, msgnetwork_conn_t *, void *);
// void connHandler(msgnetwork_conn_t *, bool, void *);
+// void errorHandler(SalticidaeCError *, bool, void *);
import "C"
import (
@@ -120,6 +121,14 @@ func connHandler(_conn *C.struct_msgnetwork_conn_t, connected C.bool, _ unsafe.P
}
}
+//export errorHandler
+func errorHandler(_err *C.struct_SalticidaeCError, fatal C.bool, _ unsafe.Pointer) {
+ err := (*salticidae.Error)(unsafe.Pointer(_err))
+ s := "recoverable"
+ if fatal { s = "fatal" }
+ fmt.Printf("Captured %s error during an async call: %s\n", s, salticidae.StrError(err.GetCode()))
+}
+
func genMyNet(ec salticidae.EventContext, name string) MyNet {
netconfig := salticidae.NewMsgNetworkConfig()
n := MyNet {
@@ -129,6 +138,7 @@ func genMyNet(ec salticidae.EventContext, name string) MyNet {
n.net.RegHandler(MSG_OPCODE_HELLO, salticidae.MsgNetworkMsgCallback(C.onReceiveHello), nil)
n.net.RegHandler(MSG_OPCODE_ACK, salticidae.MsgNetworkMsgCallback(C.onReceiveAck), nil)
n.net.RegConnHandler(salticidae.MsgNetworkConnCallback(C.connHandler), nil)
+ n.net.RegErrorHandler(salticidae.MsgNetworkErrorCallback(C.errorHandler), nil)
netconfig.Free()
return n
}
diff --git a/test_p2p_stress/main.go b/test_p2p_stress/main.go
index 6670f03..7cda52d 100644
--- a/test_p2p_stress/main.go
+++ b/test_p2p_stress/main.go
@@ -9,6 +9,7 @@ package main
// void onReceiveAck(msg_t *, msgnetwork_conn_t *, void *);
// void onStopLoop(threadcall_handle_t *, void *);
// void connHandler(msgnetwork_conn_t *, bool, void *);
+// void errorHandler(SalticidaeCError *, bool, void *);
// void onTimeout(timerev_t *, void *);
// typedef struct timeout_callback_context_t {
// int app_id;
@@ -235,6 +236,14 @@ func connHandler(_conn *C.struct_msgnetwork_conn_t, connected C.bool, userdata u
}
}
+//export errorHandler
+func errorHandler(_err *C.struct_SalticidaeCError, fatal C.bool, _ unsafe.Pointer) {
+ err := (*salticidae.Error)(unsafe.Pointer(_err))
+ s := "recoverable"
+ if fatal { s = "fatal" }
+ fmt.Printf("Captured %s error during an async call: %s\n", s, salticidae.StrError(err.GetCode()))
+}
+
//export onStopLoop
func onStopLoop(_ *C.threadcall_handle_t, userdata unsafe.Pointer) {
ec := salticidae.EventContext(userdata)
@@ -285,6 +294,7 @@ func main() {
net.RegHandler(MSG_OPCODE_RAND, salticidae.MsgNetworkMsgCallback(C.onReceiveRand), _i)
net.RegHandler(MSG_OPCODE_ACK, salticidae.MsgNetworkMsgCallback(C.onReceiveAck), _i)
net.RegConnHandler(salticidae.MsgNetworkConnCallback(C.connHandler), _i)
+ net.RegErrorHandler(salticidae.MsgNetworkErrorCallback(C.errorHandler), _i)
net.Start()
}
netconfig.Free()