func sp_send(eid int, msg Msg) (rc int) { var ( ubuf *C.char cur *C.char ) ubuf = C.ubuf_alloc(C.int(len(msg.data))) C.memcpy(unsafe.Pointer(ubuf), unsafe.Pointer(&msg.data[0]), C.size_t(len(msg.data))) for _, s := range msg.hdr { cur = C.ubuf_alloc(C.int(len(s))) C.memcpy(unsafe.Pointer(cur), unsafe.Pointer(&s[0]), C.size_t(len(s))) C.ubufctl_add(ubuf, cur) } if rc = int(C.sp_send(C.int(eid), ubuf)); rc != 0 { C.ubuf_free(ubuf) } return rc }
func sp_recv(eid int) (rc int, msg Msg) { var ( ubuf *C.char cur *C.char leng int ) if rc = int(C.sp_recv(C.int(eid), &ubuf)); rc == 0 { msg.data = C.GoBytes(unsafe.Pointer(ubuf), C.ubuf_len(ubuf)) cur = C.ubufctl_first(ubuf) msg.hdr = append(msg.hdr, C.GoBytes(unsafe.Pointer(cur), C.ubuf_len(cur))) for leng = int(C.ubufctl_num(ubuf)); leng > 0; leng-- { cur = C.ubufctl_next(ubuf, cur) msg.hdr = append(msg.hdr, C.GoBytes(unsafe.Pointer(cur), C.ubuf_len(cur))) } C.ubuf_free(ubuf) } return rc, msg }