| | |
| | | return int(r) |
| | | } |
| | | |
| | | // SendToTimeout port |
| | | func (d *DgramSocket) SendToTimeout(data []byte, port int, sec, usec int) int { |
| | | if libsoftbus == nil { |
| | | return RETVAL |
| | | } |
| | | |
| | | r := C.wrap_fn_dgram_socket_sendto_timeout(libsoftbus, d.dgram, unsafe.Pointer(&data[0]), C.int(len(data)), C.int(port), C.int(sec), C.int(usec)) |
| | | return int(r) |
| | | } |
| | | |
| | | // SendToNoWait port |
| | | func (d *DgramSocket) SendToNoWait(data []byte, port int) int { |
| | | if libsoftbus == nil { |
| | | return RETVAL |
| | | } |
| | | |
| | | r := C.wrap_fn_dgram_socket_sendto_nowait(libsoftbus, d.dgram, unsafe.Pointer(&data[0]), C.int(len(data)), C.int(port)) |
| | | return int(r) |
| | | } |
| | | |
| | | // RecvFrom data and port |
| | | func (d *DgramSocket) RecvFrom() ([]byte, int, error) { |
| | | if libsoftbus == nil { |
| | |
| | | return data, int(rp), nil |
| | | } |
| | | |
| | | // RecvFromTimeout data and port |
| | | func (d *DgramSocket) RecvFromTimeout(sec, usec int) ([]byte, int, error) { |
| | | if libsoftbus == nil { |
| | | return nil, -1, fmt.Errorf("RecvFromTimeout Func Test libsoftbus Is Nil") |
| | | } |
| | | |
| | | var rb unsafe.Pointer |
| | | var rs C.int |
| | | var rp C.int |
| | | |
| | | r := C.wrap_fn_dgram_socket_recvfrom_timeout(libsoftbus, d.dgram, &rb, &rs, &rp, C.int(sec), C.int(usec)) |
| | | if r != 0 { |
| | | return nil, int(rp), fmt.Errorf("RecvFromTimeout Func Failed %d", int(r)) |
| | | } |
| | | |
| | | data := C.GoBytes(rb, rs) |
| | | C.wrap_fn_dgram_socket_free(libsoftbus, rb) |
| | | |
| | | return data, int(rp), nil |
| | | } |
| | | |
| | | // RecvFromNoWait data and port |
| | | func (d *DgramSocket) RecvFromNoWait() ([]byte, int, error) { |
| | | if libsoftbus == nil { |
| | | return nil, -1, fmt.Errorf("RecvFromNoWait Func Test libsoftbus Is Nil") |
| | | } |
| | | |
| | | var rb unsafe.Pointer |
| | | var rs C.int |
| | | var rp C.int |
| | | |
| | | r := C.wrap_fn_dgram_socket_recvfrom_nowait(libsoftbus, d.dgram, &rb, &rs, &rp) |
| | | if r != 0 { |
| | | return nil, int(rp), fmt.Errorf("RecvFromNoWait Func Failed %d", int(r)) |
| | | } |
| | | |
| | | data := C.GoBytes(rb, rs) |
| | | C.wrap_fn_dgram_socket_free(libsoftbus, rb) |
| | | |
| | | return data, int(rp), nil |
| | | } |
| | | |
| | | // SendAndRecv sync |
| | | func (d *DgramSocket) SendAndRecv(sdata []byte, port int) ([]byte, error) { |
| | | if libsoftbus == nil { |
| | |
| | | r := C.wrap_fn_dgram_socket_sendandrecv(libsoftbus, d.dgram, unsafe.Pointer(&sdata[0]), C.int(len(sdata)), C.int(port), &rb, &rs) |
| | | if r != 0 { |
| | | return nil, fmt.Errorf("SendAndRecv Send To %d And Recv From It Failed", port) |
| | | } |
| | | |
| | | data := C.GoBytes(rb, rs) |
| | | C.wrap_fn_dgram_socket_free(libsoftbus, rb) |
| | | |
| | | return data, nil |
| | | } |
| | | |
| | | // SendAndRecvTimeout sync |
| | | func (d *DgramSocket) SendAndRecvTimeout(sdata []byte, port int, sec, usec int) ([]byte, error) { |
| | | if libsoftbus == nil { |
| | | return nil, fmt.Errorf("SendAndRecvTimeout Func Test libsoftbus Is Nil") |
| | | } |
| | | |
| | | var rb unsafe.Pointer |
| | | var rs C.int |
| | | |
| | | r := C.wrap_fn_dgram_socket_sendandrecv_timeout(libsoftbus, d.dgram, unsafe.Pointer(&sdata[0]), C.int(len(sdata)), C.int(port), &rb, &rs, C.int(sec), C.int(usec)) |
| | | if r != 0 { |
| | | return nil, fmt.Errorf("SendAndRecvTimeout Send To %d And Recv From It Failed", port) |
| | | } |
| | | |
| | | data := C.GoBytes(rb, rs) |
| | | C.wrap_fn_dgram_socket_free(libsoftbus, rb) |
| | | |
| | | return data, nil |
| | | } |
| | | |
| | | // SendAndRecvNoWait sync |
| | | func (d *DgramSocket) SendAndRecvNoWait(sdata []byte, port int) ([]byte, error) { |
| | | if libsoftbus == nil { |
| | | return nil, fmt.Errorf("SendAndRecvNoWait Func Test libsoftbus Is Nil") |
| | | } |
| | | |
| | | var rb unsafe.Pointer |
| | | var rs C.int |
| | | |
| | | r := C.wrap_fn_dgram_socket_sendandrecv_nowait(libsoftbus, d.dgram, unsafe.Pointer(&sdata[0]), C.int(len(sdata)), C.int(port), &rb, &rs) |
| | | if r != 0 { |
| | | return nil, fmt.Errorf("SendAndRecvNoWait Send To %d And Recv From It Failed", port) |
| | | } |
| | | |
| | | data := C.GoBytes(rb, rs) |
| | |
| | | return int(r) |
| | | } |
| | | |
| | | // SubTimeout sub bus |
| | | func (d *DgramSocket) SubTimeout(topic string, port int, sec, usec int) int { |
| | | if libsoftbus == nil { |
| | | return RETVAL |
| | | } |
| | | |
| | | ct := C.CString(topic) |
| | | defer C.free(unsafe.Pointer(ct)) |
| | | |
| | | r := C.wrap_fn_dgram_socket_sub_timeout(libsoftbus, d.dgram, unsafe.Pointer(ct), C.int(len(topic)), C.int(port), C.int(sec), C.int(usec)) |
| | | return int(r) |
| | | } |
| | | |
| | | // SubNoWait sub bus |
| | | func (d *DgramSocket) SubNoWait(topic string, port int) int { |
| | | if libsoftbus == nil { |
| | | return RETVAL |
| | | } |
| | | |
| | | ct := C.CString(topic) |
| | | defer C.free(unsafe.Pointer(ct)) |
| | | |
| | | r := C.wrap_fn_dgram_socket_sub_nowait(libsoftbus, d.dgram, unsafe.Pointer(ct), C.int(len(topic)), C.int(port)) |
| | | return int(r) |
| | | } |
| | | |
| | | // Pub bus |
| | | func (d *DgramSocket) Pub(topic, msg string, port int) int { |
| | | if libsoftbus == nil { |
| | |
| | | return int(r) |
| | | } |
| | | |
| | | // PubTimeout bus |
| | | func (d *DgramSocket) PubTimeout(topic, msg string, port int, sec, usec int) int { |
| | | if libsoftbus == nil { |
| | | return RETVAL |
| | | } |
| | | |
| | | ct := C.CString(topic) |
| | | defer C.free(unsafe.Pointer(ct)) |
| | | cm := C.CString(msg) |
| | | defer C.free(unsafe.Pointer(cm)) |
| | | |
| | | r := C.wrap_fn_dgram_socket_pub_timeout(libsoftbus, d.dgram, unsafe.Pointer(ct), C.int(len(topic)), unsafe.Pointer(cm), C.int(len(msg)), C.int(port), C.int(sec), C.int(usec)) |
| | | return int(r) |
| | | } |
| | | |
| | | // PubNoWait bus |
| | | func (d *DgramSocket) PubNoWait(topic, msg string, port int) int { |
| | | if libsoftbus == nil { |
| | | return RETVAL |
| | | } |
| | | |
| | | ct := C.CString(topic) |
| | | defer C.free(unsafe.Pointer(ct)) |
| | | cm := C.CString(msg) |
| | | defer C.free(unsafe.Pointer(cm)) |
| | | |
| | | r := C.wrap_fn_dgram_socket_pub_nowait(libsoftbus, d.dgram, unsafe.Pointer(ct), C.int(len(topic)), unsafe.Pointer(cm), C.int(len(msg)), C.int(port)) |
| | | return int(r) |
| | | } |
| | | |
| | | // Port socket |
| | | func (d *DgramSocket) Port() int { |
| | | if libsoftbus == nil { |